z

BLOG ARTICLE 개발/Web | 10 ARTICLE FOUND

  1. 2019.12.24 Tomcat SSL / HTTPS Redirect
  2. 2017.11.22 http session for httpclient
  3. 2013.05.24 Quartz cronExpression
  4. 2012.07.24 Flex Tabnavigator Error #1009
  5. 2011.03.29 JSP File download시 쓰레기값 처리 (CRLF)

https://offbyone.tistory.com/262

 

 

 

Tomcat SSL 적용시 https로 자동 리다이렉트 설정하기

요즘은 대부분의 사이트들이 SSL을 사용해서 https:// 로 연결을 합니다. SSL을 사용하던 초창기에는 성능 문제로 로그인, 회원가입 등 주요한 데이터가 전달되는 곳에 부분적으로 적용을 하였는데, 요즘은 서버와..

offbyone.tistory.com

 

AND

회사에서 login을 주기적으로 확인하여

 

 

HTTPClient 3.0으로 로그인을 테스트를 할 수 있다.

 

 
public class Login {

    private static Log log = LogFactory.getLog(Login.class);

 

    private static String LOGON_SITE = "i4h082.google.com";

 

    private static int LOGON_PORT = 80;

 

    static HttpClient client = new HttpClient();

    public static void loginID() {

        client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT, "http");
        client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);

        PostMethod authpost = new PostMethod("/login.ggl");
        NameValuePair nextURL = new NameValuePair("nxtURL","http://www.google.com/login.ggl");
        NameValuePair secukey = new NameValuePair("secukey", "");
        NameValuePair turtle = new NameValuePair("sqer", "knight76");
        NameValuePair earthworm = new NameValuePair("max", "xa");

        authpost.setRequestBody(new NameValuePair[] { nextURL, secukey, sqer,max });

        String response = null;
        try {
            client.executeMethod(authpost);
            response = authpost.getResponseBodyAsString();
        } catch (IOException ioe) {
            log.error(ioe, ioe);
        } finally {
            authpost.releaseConnection();
        }

        authpost.releaseConnection();
        int statuscode = authpost.getStatusCode();

        if (statuscode == HttpStatus.SC_OK && (response.indexOf("성공") > 0)) {
            System.out.println("login is successed");
        } else {
            System.out.println("login is failed");
        }

    }

 

 

 

 

HTTPClient 2.0으로도 로그인을 테스트를 할 수 있다.

 

 

 

 
public class Login {

    private static Log log = LogFactory.getLog(Login.class);

 

    private static String LOGON_SITE = "i4h082.google.com";

 

    private static int LOGON_PORT = 80;

 

    static HttpClient client = new HttpClient();

    public static void loginID() {

        client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT, "http");
        PostMethod authpost = new PostMethod("/login.ggl");
        NameValuePair nextURL = new NameValuePair("nxtURL","http://www.google.com/login.ggl");
        NameValuePair secukey = new NameValuePair("secukey", "");
        NameValuePair turtle = new NameValuePair("sqer", "knight76");
        NameValuePair earthworm = new NameValuePair("max", "xa");

        authpost.setRequestBody(new NameValuePair[] { nextURL, secukey, sqer,max });

        String response = null;
        try {
            client.executeMethod(authpost);
            response = authpost.getResponseBodyAsString();
        } catch (IOException ioe) {
            log.error(ioe, ioe);
        } finally {
            authpost.releaseConnection();
        }

        authpost.releaseConnection();
        int statuscode = authpost.getStatusCode();

        if (statuscode == HttpStatus.SC_OK && (response.indexOf("성공") > 0)) {
            System.out.println("login is successed");
        } else {
            System.out.println("login is failed");
        }

    }

 

 

 

문제는 https 다.

난 이렇게 해결했다.

 

HTTPClient 3.0 버젼

 

        HttpClient client = new HttpClient();

         client.getState().setCredentials(
            new AuthScope("ids.google.com", 443 ),
            new UsernamePasswordCredentials("", "" )
        );

         client.getHostConfiguration().setHost("i4h080.google.com", LOGON_PORT, "https");
        client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);

            PostMethod authpost = new PostMethod("/login.ggl");
        NameValuePair nextURL = new NameValuePair("nxtURL","http://www.google.com/login.ggl");
        NameValuePair secukey = new NameValuePair("secukey", "");
        NameValuePair turtle = new NameValuePair("sqer", "knight76");
        NameValuePair earthworm = new NameValuePair("max", "xa");

        authpost.setRequestBody(new NameValuePair[] { nextURL, secukey, sqer,max });

        String response = null;
        try {
            client.executeMethod(authpost);
            response = authpost.getResponseBodyAsString();
        } catch (IOException ioe) {
            log.error(ioe, ioe);
        } finally {
            authpost.releaseConnection();
        }

        authpost.releaseConnection();
        int statuscode = authpost.getStatusCode();

        if (statuscode == HttpStatus.SC_OK && (response.indexOf("성공") > 0)) {
            System.out.println("login is successed");
        } else {
            System.out.println("login is failed");
        }

    }

 

 

 

HTTPClient 2.0으로도 로그인을 테스트를 할 수 있다.

 

 

 

 
public class Login {

    private static Log log = LogFactory.getLog(Login.class);

 

    private static String LOGON_SITE = "i4h082.google.com";

 

    private static int LOGON_PORT = 80;

 

    static HttpClient client = new HttpClient();

    public static void loginID() {

        client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT, "http");
        PostMethod authpost = new PostMethod("/login.ggl");
        NameValuePair nextURL = new NameValuePair("nxtURL","http://www.google.com/login.ggl");
        NameValuePair secukey = new NameValuePair("secukey", "");
        NameValuePair turtle = new NameValuePair("sqer", "knight76");
        NameValuePair earthworm = new NameValuePair("max", "xa");

        authpost.setRequestBody(new NameValuePair[] { nextURL, secukey, sqer,max });

        String response = null;
        try {
            client.executeMethod(authpost);
            response = authpost.getResponseBodyAsString();
        } catch (IOException ioe) {
            log.error(ioe, ioe);
        } finally {
            authpost.releaseConnection();
        }

        authpost.releaseConnection();
        int statuscode = authpost.getStatusCode();

        if (statuscode == HttpStatus.SC_OK && (response.indexOf("성공") > 0)) {
            System.out.println("login is successed");
        } else {
            System.out.println("login is failed");
        }

 

 

 

 

 

HTTPClient 2.0 버젼

 

 

         HttpClient client = new HttpClient();

         client.getState().setCredentials(
                "realm", "ids.google.com",
                new UsernamePasswordCredentials("", "" )
            );

       client.getHostConfiguration().setHost("i4h080.google.com", LOGON_PORT, "https");

 

       PostMethod authpost = new PostMethod("/login.ggl");
        NameValuePair nextURL = new NameValuePair("nxtURL","http://www.google.com/login.ggl");
        NameValuePair secukey = new NameValuePair("secukey", "");
        NameValuePair turtle = new NameValuePair("sqer", "knight76");
        NameValuePair earthworm = new NameValuePair("max", "xa");

        authpost.setRequestBody(new NameValuePair[] { nextURL, secukey, sqer,max });

        String response = null;
        try {
            client.executeMethod(authpost);
            response = authpost.getResponseBodyAsString();
        } catch (IOException ioe) {
            log.error(ioe, ioe);
        } finally {
            authpost.releaseConnection();
        }

        authpost.releaseConnection();
        int statuscode = authpost.getStatusCode();

        if (statuscode == HttpStatus.SC_OK && (response.indexOf("성공") > 0)) {
            System.out.println("login is successed");
        } else {
            System.out.println("login is failed");
        }

    }

 

 

 

HTTPClient 2.0으로도 로그인을 테스트를 할 수 있다.

 

 

 

 
public class Login {

    private static Log log = LogFactory.getLog(Login.class);

 

    private static String LOGON_SITE = "i4h082.google.com";

 

    private static int LOGON_PORT = 80;

 

    static HttpClient client = new HttpClient();

    public static void loginID() {

        client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT, "http");
        PostMethod authpost = new PostMethod("/login.ggl");
        NameValuePair nextURL = new NameValuePair("nxtURL","http://www.google.com/login.ggl");
        NameValuePair secukey = new NameValuePair("secukey", "");
        NameValuePair turtle = new NameValuePair("sqer", "knight76");
        NameValuePair earthworm = new NameValuePair("max", "xa");

        authpost.setRequestBody(new NameValuePair[] { nextURL, secukey, sqer,max });

        String response = null;
        try {
            client.executeMethod(authpost);
            response = authpost.getResponseBodyAsString();
        } catch (IOException ioe) {
            log.error(ioe, ioe);
        } finally {
            authpost.releaseConnection();
        }

        authpost.releaseConnection();
        int statuscode = authpost.getStatusCode();

        if (statuscode == HttpStatus.SC_OK && (response.indexOf("성공") > 0)) {
            System.out.println("login is successed");
        } else {
            System.out.println("login is failed");
        }



출처: http://knight76.tistory.com/298 [김용환 블로그(2004-2017)]

 

 

https://stackoverflow.com/questions/6272575/how-to-handle-the-session-in-httpclient-4-1

 

I am using the HttpClient 4.1.1 to test my server's REST API.

I can manage to login seem to work fine but when I try to do anything else I am failing.

Most likely I have a problem setting the cookie in the next request.

Here is my code currently:

HttpGet httpGet = new HttpGet(<my server login URL>);
httpResponse = httpClient.execute(httpGet)
sessionID = httpResponse.getFirstHeader("Set-Cookie").getValue();
httpGet.addHeader("Cookie", sessionID);
httpClient.execute(httpGet);

Is there a better way to manage the session/cookies setting in the HttpClient package?

 

 

The correct way is to prepare a CookieStore which you need to set in the HttpContext which you in turn pass on every HttpClient#execute() call.

HttpClient httpClient = new DefaultHttpClient();
CookieStore cookieStore = new BasicCookieStore();
HttpContext httpContext = new BasicHttpContext();
httpContext.setAttribute(HttpClientContext.COOKIE_STORE, cookieStore);
// ...

HttpResponse response1 = httpClient.execute(method1, httpContext);
// ...

HttpResponse response2 = httpClient.execute(method2, httpContext);
// ...

 

AND

Quartz cronExpression

개발/Web 2013. 5. 24. 14:41


출처:http://darkhorizon.tistory.com/287



Cron의 실행주기를 설정하는 방법


<property name="cronExpression">

<!--  -->

<value>* * * * * * *</value>

</property>


왼쪽부터 초 분 시간 일(Day of Month) 월 요일(Day of Week, 1-7 : SUN-SAT) 년도(생략가능) 의 순이다.


표현식

* : 모든 값
? : 특정 값 없음
- : 범위 지정
, : 여러 값 지정 구분에 사용
/ : 초기값과 증가치 설정에 사용
L : 지정할 수 있는 범위의 마지막 값
W : 월~금요일 또는 가장 가까운 월/금요일
# : 몇 번째 무슨 요일 2#1 => 첫 번째 월요일

예제)

"0 0 12 * * ?"   매일 정오 12시에 실행


"0 15 10 ? * *"   매일 오전 10시 15분에 실행


"0 15 10 * * ?"   매일 오전 10시 15분에 실행


"0 15 10 * * ? *"         매일 오전 10시 15분에 실행


"0 15 10 * * ? 2005" 2005년 동안 매일 오전 10시 15분에 실행


"0 * 14 * * ?"   매일 오후 2시부터 시작하여 오후 2시 59분까지 실행


"0 0/5 14 * * ?"         매일 오후 2시부터 2시 55분까지 5분 간격으로 실행


"0 0/5 14,18 * * ?" 매일 오후 2시부터 2시 55분까지, 오후 6시부터 6시 55분까지 5분 간격으로 실행


"0 0-5 14 * * ?"         매일 오후 2시부터 2시 05분까지 분 단위로 실행


"0 10,44 14 ? 3 WED" 3월의 매주 수요일 오후 2시 10분과 2시 44분에 실행


"0 15 10 ? * MON-FRI" 매주 월요일부터 금요일까지 오전 10시 15분에 실행


"0 15 10 15 * ?"         매달 15일 오전 10시 15분에 실행


"0 15 10 L * ?"   매달 마지막 날 오전 10시 15분에 실행


"0 15 10 ? * 6L"         매월 마지막 금요일 오전 10시 15분에 실행


"0 15 10 ? * 6#3"         매월 세번째 금요일 오전 10시 15분에 실행



!! 주의)


요일(Day of Week) 에 명시적인 특정값이 지정되었을 때, 일(Day of Month)의 표현식이 ?나 특정값이 아닌 모든 값(*)으로 설정되었을 때 아래의 Exception이 발생한다. 


Support for specifying both a day-of-week AND a day-of-month parameter is not implemented

AND


Flex Error #1009


TabNavigator에서 UI 컨트롤의 로드시간 차로 발생하는 널 포인터 문제


해결 방법은 creationPolicy="all"로 줄 것.


AND


 jsp를 서블릿으로 변경 or 스크립틀릿의 시작/종료태그를 아래와 같이 일렬로 처리

from:
<% 문1... %>
<% 문2... %>

to:
<% 문1... %><%
문2... %>

원인은 잘 모르겠음. 다만. <%를 데이터가 쓰여진 후 개행으로 처리하는 것 같음.

AND