httpclient를 쓰지 않고, 자바의 URLConnection(HTTPURLConnection)만을 이용하여 post, get, multipart 파일 전송을 할 수 있도록 하는 아이디어를 제공

http://javacan.tistory.com/entry/65

'web' 카테고리의 다른 글

Apache Mina 파일이나 특정 스트림 보내기  (1) 2009.10.21
Apache Mina 2.0 Connector 부분 변경  (0) 2009.10.21
Tux 설치하기  (0) 2009.07.13
NGINX 설치하기  (0) 2009.07.13
apache httpd와 light httpd의 성능 비교  (0) 2009.07.13
Posted by '김용환'
,

Tux 설치하기

web 2009. 7. 13. 21:32


Handos303 서버에 tux 설치해놨어요.

 

1.     yum install tux

2.     vi /etc/sysctl.tux 수정하기

net/tux/virtual_server =0

net/tux/clientport = 81

net/tux/referer_logging = 0

net/tux/logging = 0

net/tux/max_keepalives = 0

net/tux/keepalive_timeout = 0

net/tux/TDprintk = 0

net/tux/Dprintk = 0

net/tux/generate_cache_control = 1

net/tux/generate_etags = 1

net/tux/generate_last_mod = 1

net/tux/defer_accept = 0

net.tux.compression=1

 

만약 81포트를 아파치를 뛰워놓고 fowarding할 수 있도록 사용.

3.
     /var/www/html/index.html 생성 및 내용 추가

<script>setTimeout("location.href='http://www1.google.com/index.jsp'",10);</script>

4.     Killall httpd

5.     /etc/init.d/tux restart

 

 

 

 

'web' 카테고리의 다른 글

Apache Mina 2.0 Connector 부분 변경  (0) 2009.10.21
URLConnection을 이용한 파일 전송  (0) 2009.07.29
NGINX 설치하기  (0) 2009.07.13
apache httpd와 light httpd의 성능 비교  (0) 2009.07.13
Restarting Tomcat, log4j error  (0) 2009.07.09
Posted by '김용환'
,

NGINX 설치하기

web 2009. 7. 13. 21:31

최근에 NGINX라고 http 서버 성능이 좋다고 해서 서버를 설치해본다. 성능 평가는 추후에..

http://www.nginx.net/

참조(http://www.mman.pe.kr/?p=53)


yum install pcre
yum install pcre-devel
yum install zlib
yum install zlib-devel
yum install openssl
yum install openssl-devel

./configure --sbin-path=/usr/local/sbin --with-http_ssl_module \
--with-http_ssl_module --with-http_realip_module --with-http_addition_module \
--with-http_sub_module --with-http_dav_module --with-http_stub_status_module --with-mail \
--with-mail_ssl_module --with-cc-opt="-I /usr/include/pcre" --pid-path=/var/run/nginx.pid \
--lock-path=/var/lock/subsys/nginx --conf-path=/etc/nginx/nginx.conf

make
make install



기존 소스
    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

#        location / {
#            root   html;
#            index  index.html index.htm;
#        }

=> 수정


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;
       location / {
            #root   html;
            #index  index.html index.htm;
            proxy_pass http://xxx.google.com
        }


실행 및 종료

nginx -c /etc/nginx/nginx.conf

killall nginx


'web' 카테고리의 다른 글

URLConnection을 이용한 파일 전송  (0) 2009.07.29
Tux 설치하기  (0) 2009.07.13
apache httpd와 light httpd의 성능 비교  (0) 2009.07.13
Restarting Tomcat, log4j error  (0) 2009.07.09
How to protect direct calling of jsp  (0) 2009.07.01
Posted by '김용환'
,

apache httpd와 light httpd의 성능 비교
약 10~20% 정도 성능차이로 보인다.

http://www.howtoforge.com/benchmark-apache2-vs-lighttpd-images



'web' 카테고리의 다른 글

Tux 설치하기  (0) 2009.07.13
NGINX 설치하기  (0) 2009.07.13
Restarting Tomcat, log4j error  (0) 2009.07.09
How to protect direct calling of jsp  (0) 2009.07.01
아파치 에러 해결 No space left on device  (0) 2009.02.17
Posted by '김용환'
,

You can find hint, when you see the tomcat error.

log4j:WARN No appenders could be found for logger (org.apache.catalina.startup.Embedded).
log4j:WARN Please initialize the log4j system properly.
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:432)
Caused by: java.lang.NullPointerException
    at org.apache.catalina.startup.Catalina.await(Catalina.java:615)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:575)

    ... 6 more

It means error occured in starting tomcat. so that you should look carefully at tomcat configuration files such as server.xml.

Wow!!! port string is not wrapped by double quotation("), 'port=6101' must be changed to 'port="6101"'.

<Server port="5101" shutdown="SHUTDOWN">
  <Service name="Catalina">
    <Connector port=6101 enableLookups="false" redirectPort="8443" protocol="AJP/1.3" URIEncoding="UTF-8" />
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="hangame_hsec">
      <Host workDir="work/google_hsec" name="localhost" debug="0" appBase="webapps" unpackWARs="true" autoDeploy="true">
        <Context docBase="/home/www/work/project/google_hsec/web" path="">
          <Logger className="org.apache.catalina.logger.SystemOutLogger" verbosity="4" timestamp="true" />
        </Context>
      </Host>
    </Engine>
  </Service>
</Server>

'web' 카테고리의 다른 글

NGINX 설치하기  (0) 2009.07.13
apache httpd와 light httpd의 성능 비교  (0) 2009.07.13
How to protect direct calling of jsp  (0) 2009.07.01
아파치 에러 해결 No space left on device  (0) 2009.02.17
Content-disposition 속성  (0) 2009.02.13
Posted by '김용환'
,


In web.xml, you can add this security-constraints.

<security-constraint>
    <display-name>JSP Protection</display-name>
    <web-resource-collection>
      <web-resource-name>SecureJSPPages</web-resource-name>
      <url-pattern>*.jsp</url-pattern>
      <http-method>GET</http-method>
      <http-method>POST</http-method>
    </web-resource-collection>
    <auth-constraint>
      <role-name>nobody</role-name>
    </auth-constraint>
  </security-constraint>
  <security-role>
    <description>
      Nobody should be in this role so JSP files are protected from direct access.
    </description>
    <role-name>nobody</role-name>
  </security-role>




Sometime, some servlet or jsp may be not protected.


  <security-constraint>
    <display-name>JSP Protection</display-name>
    <web-resource-collection>
      <web-resource-name>SecureJSPPages</web-resource-name>
      <url-pattern>*.jsp</url-pattern>
      <http-method>GET</http-method>
      <http-method>POST</http-method>
    </web-resource-collection>
    <auth-constraint>
      <role-name>nobody</role-name>
    </auth-constraint>
  </security-constraint>
  <security-constraint>
    <display-name>NOT JSP Protection</display-name>
    <web-resource-collection>
      <web-resource-name>NOTSecureJSPPages</web-resource-name>
      <url-pattern>/common/L7check.jsp</url-pattern>
      <http-method>GET</http-method>
      <http-method>POST</http-method>
    </web-resource-collection>
  </security-constraint>
 

  <security-role>
    <description>
      Nobody should be in this role so JSP files are protected from direct access.
    </description>
    <role-name>nobody</role-name>
  </security-role>



참조
http://www.jboss.org/file-access/default/members/jbossas/freezone/docs/Server_Configuration_Guide/4/html/J2EE_Declarative_Security_Overview-Web_Content_Security_Constraints.html


http://java.sun.com/xml/ns/j2ee/

http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd


'web' 카테고리의 다른 글

apache httpd와 light httpd의 성능 비교  (0) 2009.07.13
Restarting Tomcat, log4j error  (0) 2009.07.09
아파치 에러 해결 No space left on device  (0) 2009.02.17
Content-disposition 속성  (0) 2009.02.13
dbcp가 자주 끊길 때..  (0) 2009.02.11
Posted by '김용환'
,

No space left on device:
에러로그에 이렇게 남기면서 아파치 데몬이 뜨지 않는 않는 경우는 2가지 정도이다.

1. 정말 파일 시스템이 찬 경우.

df로 확인

2. 파일 시스템이 차지 않았다면.. 아파치 모듈과 연동하면서 resource leak(아마도 거의 세마포일듯)이라 생각하면 된다.

httpd 프로세스가 뜨지 않았는데...

ipcs -s | grep www

이걸로 보면, 세마포를 잡고 있는 것이 보인다..

 

다음의 명령으로 자원 릭을 다 제거한다..

ipcs -s | grep www | perl -e 'while (<STDIN>) { @a=split(/\s+/); print `ipcrm sem $a[1]`}'

 

 

Posted by '김용환'
,

Content-disposition 속성

web 2009. 2. 13. 19:50

Content-Disposition 은 컨텐트 타입의 옵션이기도 하며 실제로 지정된 파일명을 지정함으로써 더 자세한 파일의 속성을 알려줄 수 있다.

 

http://www.ietf.org/rfc/rfc2183.txt 스펙을 보면..


2.1  The Inline Disposition Type

   A bodypart should be marked `inline' if it is intended to be
   displayed automatically upon display of the message.  Inline
   bodyparts should be presented in the order in which they occur,
   subject to the normal semantics of multipart messages.

2.2  The Attachment Disposition Type

   Bodyparts can be designated `attachment' to indicate that they are
   separate from the main body of the mail message, and that their
   display should not be automatic, but contingent upon some further
   action of the user.  The MUA might instead present the user of a
   bitmap terminal with an iconic representation of the attachments, or,
   on character terminals, with a list of attachments from which the
   user could select for viewing or storage.

 

이렇게 정의되어 있다.

 


즉  "Content-disposition: inline"은

브라우저 인식 파일확장자를 가진 파일들에 대해서는 웹브라우저 상에서 바로 파일을 자동으로 보여줄 수 있어서 의미상인 멀티파트 메시지를 표현하는데 있다. 그외의 파일들에 대해서는 "파일 다운로드" 대화상자가 뜨도록 하는 헤더속성이다.

"Content-disposition: attachment"은
브라우저 인식 파일확장자를 포함하여 모든 확장자의 파일들에 대해,  다운로드시 무조건 "파일 다운로드" 대화상자가 뜨도록 하는 헤더속성이라 할 수 있다.

 

스펙에 보면. 다음과 같은 BNF 는 이렇게 정의되어 있다.

 

     disposition := "Content-Disposition" ":"
                    disposition-type
                    *(";" disposition-parm)

     disposition-type := "inline"
                       / "attachment"
                       / extension-token
                       ; values are not case-sensitive

     disposition-parm := filename-parm
                       / creation-date-parm
                       / modification-date-parm
                       / read-date-parm
                       / size-parm
                       / parameter

     filename-parm := "filename" "=" value

     creation-date-parm := "creation-date" "=" quoted-date-time

     modification-date-parm := "modification-date" "=" quoted-date-time

     read-date-parm := "read-date" "=" quoted-date-time

     size-parm := "size" "=" 1*DIGIT

     quoted-date-time := quoted-string
                      ; contents MUST be an RFC 822 `date-time'
                      ; numeric timezones (+HHMM or -HHMM) MUST be used

 

 

 

샘플 예제는 다음과 같다. 게시판에서 자주 쓸 수 있다.

게시판 서버에서 html, htm, jsp은 보여주고 나머지는 attachment로 알려주는 것이다. 

    <Location  / >
        Header set Content-Disposition "attachment"
    </Location>

    <Location ~ "/.*(html|htm|jsp|)" >
        Header unset Content-Disposition
    </Location>

만약  swf 파일도 그냥 보여주고 싶다면, attachment 속성 대신 inline을 쓰면 되겠다.

Posted by '김용환'
,

dbcp가 자주 끊길 때..

web 2009. 2. 11. 05:26

 

 

validationQuery는 커넥션이 살아 있는지 체크, 보통  오라클은 "select 1 from dual", MySQL은 "select 1" 로 사용한다. 

testWhileIdle은 커넥션에 아무런 데이터 송수신이 없는 긴 시간에가 (while ide) 체크를 하지는 한다. 


 timeBetweenEvictionRunsMillis는 커넥션이 쉬고 있을 때, (사실은 강제 철거중에) 커넥션 체크 쿼리를 실행하는 시간 간격을 지정한다. 1분정도 주면 좋을 듯.

Posted by '김용환'
,

OSCahce에 존재하지 않는 데이터를 반복적으로 호출하는 경우, 쓰레드 락이 걸려서 어플리케이션이 문제 될 수 있다.

 

List result = null;
try {
  result = (List) admin.getFromCache("aaa");
} catch (NeedsRefreshException e) {
  throw e;

}

 

OSCache GeneralCacheAdministrator 객체안에 Cache가 있고, updateStatus라는 object를 이용하여 key에 대한 wait를 하고, notify하는 구조로 되어 있다.

즉, get을 할 때는 wait() 콜을, set을 할 때는 notifyAll()로 구성되었다.

 

웹에서는 한꺼번에 리퀘스트가 몰려오거나, 리스타트시에 자주 발생될 수 있다.

현상은 CLOSE_WAIT가 많이 생기고 apache full이 일어나면서 L4에서 서버가 빠진다.

 

이 문제를 해결하기 위해서는 미리 oscache에 데이터를 미리 넣어두는 것이 최고다. 그게 어렵다면.. putIncache나 cancelupdate () 메소드를 호출해서 notifyAll() 시켜라~

 

List result = null;
try {
  result = (List) admin.getFromCache("aaa");
} catch (NeedsRefreshException e) {

  admin.cancelUpdate("aaa"); // 내부적으로 notifyAll()을 호출. wait하고 있는 객체를 깨움

 // 또는 admin.putInCache(...);

  throw e;

}

 

 

 

 

Posted by '김용환'
,