프로젝트를 진행하다보면 톰켓 shutdown을 실행시켜서 당연히 종료되었다고 생각했지만 제대로 종료되지않고 톰캣 프로세스가 남아있는 현상이 있습니다.

이는 배치 스케쥴링과, JDBC Driver가 종료되지 않을때 나오는 현상인데, shutdown을 시킬때는 배치 스케쥴링과, JDBC Driver를 별도로 강제종료를 시켜줘야 합니다.

 

방법은 다음과 같습니다.

 

 
1. ShutdownHook을 생성
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
 
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
 
 
public class ShutdownHook implements ServletContextListener {
    @Override
    public void contextDestroyed(ServletContextEvent arg0)
    {
        try
        {
       
            // 스케쥴러 Bean name을 모를때 주석을 풀어 Bean Name을 찾을 수 있다.
//            String[] temp = getBzRConfigHelper().getFactory().getBeanDefinitionNames();
//            if(temp!=null) {
//                for (int i = 0; i < temp.length; i++) {
//                    this.logHandler("beans : " + temp[i], null);
//                }
//            }    
            // Get a reference to the Scheduler and shut it down
            try {
                Scheduler scheduler = (Scheduler) getBzRConfigHelper().getFactory().getBean("org.springframework.scheduling.quartz.SchedulerFactoryBean");
                scheduler.shutdown(true);        
            }catch(NoSuchBeanDefinitionException e) {
                this.logHandler(e.getMessage(), e);
            }
    
            Enumeration<Driver> drivers = DriverManager.getDrivers();
            while (drivers.hasMoreElements()) {
                Driver driver = drivers.nextElement();
                try {
                    DriverManager.deregisterDriver(driver);
                    this.logHandler(String.format("deregistering jdbc driver: %s", driver), null);
                } catch (SQLException e) {
                    this.logHandler(String.format("deregistering jdbc driver: %s", driver), e);
                }
            }
            Thread.sleep(1000);
            try {
                ThreadGroup threadGroup = Thread.currentThread().getThreadGroup(); 
                threadGroup.interrupt();    
            }catch(Exception e) {
                this.logHandler(e.getMessage(), e);
            }
            this.logHandler("--End contextDestroyed --" + new Date(), null);
            // Sleep for a bit so that we don't get any errors
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
 
    @Override
    public void contextInitialized(ServletContextEvent arg0)
    {
    }
        
    public boolean isNullOrEmpty(String str) {
        return str == null || StringUtils.isEmpty(str);
    }
 
    public boolean isNullOrEmptyOrWhite(String str) {
        return str == null || StringUtils.isEmpty(str.trim());
    }
    
}
http://colorscripter.com/info#e" target="_blank" style="color: rgb(229, 229, 229);">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="color: white;">cs
 
2. Web.xml 리스너를 생성한 ShutdownHook로 변경
1
2
3
4
5
....
    <listener>
        <listener-class>~.ShutdownHook</listener-class>
    </listener>
http://colorscripter.com/info#e" target="_blank" style="color: rgb(229, 229, 229);">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="color: white;">cs
 
3. 제대로 톰캣 Process가 종료되는지 확인.
==============================================================================================
주의할점은 각 프로젝트마다 Batch Bean 클래스가 다를 수 있으므로 알맞게 수정해서 사용해야합니다.
by 아카마메 2019. 3. 29. 16:57

Many text editors have advanced find (and replace) features. When I’m programming, I like to use an editor with regular expression search and replace. This feature is allows one to find text based on complex patterns rather than based just on literals. Upon occasion I want to examine each of the comments in my source code and either edit them or remove them. I found that it was difficult to write a regular expression that would find C style comments (the comments that start with /* and end with */) because my text editor does not implement the “non-greedy matching” feature of regular expressions.

First Try

When first attempting this problem, most people consider the regular expression:

/\*.*\*/

This seems the natural way to do it. /\* finds the start of the comment (note that the literal * needs to be escaped because * has a special meaning in regular expressions), .* finds any number of any character, and \*/ finds the end of the expression.

The first problem with this approach is that .* does not match new lines.

/* First comment 
 first comment—line two*/
/* Second comment */

Second Try

This can be overcome easily by replacing the . with [^] (in some regular expression packages) or more generally with (.|[\r\n]):

/\*(.|[\r\n])*\*/

This reveals a second, more serious, problem—the expression matches too much. Regular expressions are greedy, they take in as much as they can. Consider the case in which your file has two comments. This regular expression will match them both along with anything in between:

start_code();
/* First comment */
more_code(); 
/* Second comment */
end_code();

Third Try

To fix this, the regular expression must accept less. We cannot accept just any character with a ., we need to limit the types of characters that can be in our expressions:

/\*([^*]|[\r\n])*\*/

This simplistic approach doesn’t accept any comments with a * in them.

/*
 * Common multi-line comment style.
 */
/* Second comment */

Fourth Try

This is where it gets tricky. How do we accept a * without accepting the * that is part of the end comment? The solution is to still accept any character that is not *, but also accept a * and anything that follows it provided that it isn’t followed by a /:

/\*([^*]|[\r\n]|(\*([^/]|[\r\n])))*\*/

This works better but again accepts too much in some cases. It will accept any even number of *. It might even accept the * that is supposed to end the comment.

start_code();
/****
 * Common multi-line comment style.
 ****/
more_code(); 
/*
 * Another common multi-line comment style.
 */
end_code();

Fifth Try

What we tried before will work if we accept any number of * followed by anything other than a * or a /:

/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*/

Now the regular expression does not accept enough again. Its working better than ever, but it still leaves one case. It does not accept comments that end in multiple *.

/****
 * Common multi-line comment style.
 ****/
/****
 * Another common multi-line comment style.
 */

Solution

Now we just need to modify the comment end to allow any number of *:

/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/

We now have a regular expression that we can paste into text editors that support regular expressions. Finding our comments is a matter of pressing the find button. You might be able to simplify this expression somewhat for your particular editor. For example, in some regular expression implementations, [^] assumes the [\r\n] and all the [\r\n]can be removed from the expression.

This is easy to augment so that it will also find // style comments:

(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)|(//.*)

ToolExpression and UsageNotes
nedit(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)|(//.*)
Ctrl+F to find, put in expression, check the Regular Expression check box.
[^] does not include new line
grep(/\*([^*]|(\*+[^*/]))*\*+/)|(//.*)
grep -E “(/\*([^*]|(\*+[^*/]))*\*+/)|(//.*)” <files>
Does not support multi-line comments, will print out each line that completely contains a comment.
perl/((?:\/\*(?:[^*]|(?:\*+[^*\/]))*\*+\/)|(?:\/\/.*))/
perl -e “$/=undef;print<>=~/((?:\/\*(?:[^*]|(?:\*+[^*\/]))*\*+\/)|(?:\/\/.*))/g;” < <file>
Prints out all the comments run together. The (?: notation must be used for non-capturing parenthesis. Each / must be escaped because it delimits the expression. $/=undef; is used so that the file is not matched line by line like grep.
Java"(?:/\\*(?:[^*]|(?:\\*+[^*/]))*\\*+/)|(?://.*)"
System.out.println(sourcecode.replaceAll(“(?:/\\*(?:[^*]|(?:\\*+[^*/]))*\\*+/)|(?://.*)”,””));
Prints out the contents of the string sourcecode with the comments removed. The (?: notation must be used for non-capturing parenthesis. Each \ must be escaped in a Java String.

An Easier Method

 

Non-greedy Matching

Most regular expression packages support non-greedy matching. This means that the pattern will only be matched if there is no other choice. We can modify our second try to use the non-greedy matcher *? instead of the greedy matcher *. With this new tool, the middle of our comment will only match if it doesn’t match the end:

/\*(.|[\r\n])*?\*/

ToolExpression and UsageNotes
nedit/\*(.|[\r\n])*?\*/
Ctrl+F to find, put in expression, check the Regular Expression check box.
[^] does not include new line
grep/\*.*?\*/
grep -E ‘/\*.*?\*/’ <file>
Does not support multi-line comments, will print out each line that completely contains a comment.
perl/\*(?:.|[\r\n])*?\*/
perl -0777ne ‘print m!/\*(?:.|[\r\n])*?\*/!g;’ <file>
Prints out all the comments run together. The (?: notation must be used for non-capturing parenthesis.
/ does not have to be escaped because ! delimits the expression.
-0777 is used to enable slurp mode and -n enables automatic reading.
Java"/\\*(?:.|[\\n\\r])*?\\*/"
System.out.println(sourcecode.replaceAll(“/\\*(?:.|[\\n\\r])*?\\*/”,””));
Prints out the contents of the string sourcecode with the comments removed. The (?: notation must be used for non-capturing parenthesis. Each \ must be escaped in a Java String.

Caveats

 

Comments Inside Other Elements

Although our regular expression describes c-style comments very well, there are still problems when something
appears to be a comment but is actually part of a larger element.

someString = "An example comment: /* example */";

// The comment around this code has been commented out.
// /*
some_code();
// */

The solution to this is to write regular expressions that describe each of the possible larger elements, find these as well, decide what type of element each is, and discard the ones that are not comments. There are tools called lexers or tokenizers that can help with this task. A lexer accepts regular expressions as input, scans a stream, picks out tokens that match the regular expressions, and classifies the token based on which expression it matched. The greedy property of regular expressions is used to ensure the longest match. Although writing a full lexer for C is beyond the scope of this document, those interested should look at lexer generators such as Flex and JFlex.


출처 : Finding Comments in Source Code Using Regular Expressions

by 아카마메 2019. 3. 12. 15:20

제가 했던 한프로젝트에서는 메인 프레임이 존재하며, Iframe에 저희 회사 제품을 제공하는 프로젝트인데, 

IE에서 SSO로그인 처리 후 세션이 유지되지않는 현상이 발생되었습니다.
이는 P3P (Platform for Personal Preferences) 규약을 도입했기 때문이라고 합니다.
P3P (Platform for Personal Preferences) 규약은 W3C ( World wide Consortium )에서 만들어 졌습니다.
(마이크로 소프트 p3p 정책 http://msdn.microsoft.com/library/default.asp?url=/workshop/security/privacy/overview/createprivacypolicy.asp)
(W3C - p3p 규약 http://www.w3.org/TR/2002/REC-P3P-20020416/ )
그래서 다른 주소지로 연결되는 프레임구조로(특히 포워딩 고정 연결시) 웹페이지가 열리게 되면, 쿠키가 적용되지 않게 됩니다.

이 문제를 해결하려면 3가지 방안이 있습니다.

1. IE 옵션 변경
2. 웹서버에 p3p 규약을 허용하는 HTTP 헤더 추가하는 방법
3. 웹페이지에서 p3p 규약을 허용하는 HTTP 헤더를 추가하는 방법

* 첫 번째 방법은 다음과 같습니다. 

(IE 11기준) 도구-인터넷옵션-개인정보-고급-자동으로 쿠키 처리 안 함-항상 세션에 쿠키허용 체크
이 방법은 사용자가 각자 설정을 해줘야하는 방법으로 추천하지않습니다.

* 두 번째 방법은 다음과 같습니다.

conf/httpd.conf 에 다음과 같이 추가한다.
<IfModule mod_headers.c> 
Header add P3P "CP=\"ALL CURa ADMa DEVa TAIa OUR BUS IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC OTC\"" 
Header set P3P "CP=\"ALL CURa ADMa DEVa TAIa OUR BUS IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC OTC\"" 
</IfModule> 

두 번째 방법도 대규모 프로젝트는 TA(Technical Architecture)에게 의존적이므로 추천하지않습니다.

* 세 번째 방법은 다음과 같습니다.

세션필터에 세션이 없을때만 아래 헤더를 추가합니다.
response.setHeader("P3P","CP='CAO PSA CONi OTR OUR DEM ONL'");

세 번째 방법은 개발자가 직접 컨트롤 가능하므로 추천드리는 방법입니다.

이상입니다. 해당 문제가 발생했을 때 도움이 되시기바랍니다.


by 아카마메 2018. 3. 9. 16:38
| 1 2 3 4 |