2013年5月23日 星期四

Nginx

1. Install Nginx on CentOS

 sudo yum install nginx  

  A. Install the EPEL repository (No package nginx available)
 
 sudo rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm  
 rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6  


  B. Change EPEL 5 version of the repo instead of 6
           Error: Package: nginx-0.8.55-2.el5.x86_64 (epel)
           Requires: perl(:MODULE_COMPAT_5.8.8)

 vi /etc/yum.repos.d/epel.repo  
 #mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-5&arch=$basearch  
 mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-6&arch=$basearch  
 yum clean all  
 yum install munin --nogpgcheck  

2. Configration
          The default vhost is defined in the file /etc/nginx/conf.d/default.conf.
          My case is setting up a reverse proxy to a Tomcat.

location /webportal {
   proxy_pass http://localhost:8080/;
   proxy_redirect   http://localhost:8080/    http://$host:$server_port/;
   proxy_set_header Host $host;
   proxy_set_header X-Real-IP $remote_addr;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

3. Start

 sudo /etc/init.d/nginx start  




Reference :
http://articles.slicehost.com/2008/12/17/centos-installing-nginx-via-yum
http://gingerjoos.com/blog/linux/installing-jetty-on-centos


2013年4月22日 星期一

ThreadPoolExecutor waitForTasksToCompleteOnShutdown doesn't work as expected

https://jira.springsource.org/browse/SPR-5387


ThreadPoolTaskExecutor doesn't work when setting up the WaitForTasksToCompleteOnShutdown property as true, also need to set up the AwaitTerminationSeconds property.


@Bean
public ThreadPoolTaskExecutor processTaskExecutor() {
   ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
   taskExecutor.setCorePoolSize(5);
   taskExecutor.setMaxPoolSize(10);
   taskExecutor.setQueueCapacity(40);
   taskExecutor.setKeepAliveSeconds(200);
   taskExecutor.setWaitForTasksToCompleteOnShutdown(true);
   taskExecutor.setAwaitTerminationSeconds(60);
   taskExecutor.setThreadFactory(new CustomizableThreadFactory("DeployThread"));
   return taskExecutor;
}

2012年11月25日 星期日

Websockets and SSE (Server Sent Events)

I don't even know exactly the difference between websocket and server-side event until reading these articles.

http://www.html5rocks.com/en/tutorials/eventsource/basics/
http://stackoverflow.com/questions/5195452/websockets-vs-server-sent-events-eventsource

Here is a great chart to explain that.













from YOW! Webbit - A Lightweight WebSocket Web Server in Java

2012年9月7日 星期五

Apache Proxy : HTTP Error 502 Bad gateway problem



Description
Around 2-4 times a day, mod_proxy will close the connection and return a HTTP/Bad_Gateway.

For circumstances where mod_proxy is sending requests to an origin server that doesn't properly implement keepalives or HTTP/1.1, there are two environment variables that can force the request to use HTTP/1.0 with no keepalive. These are set via the SetEnv directive.
These are the force-proxy-request-1.0 and proxy-nokeepalive notes.

 
   ProxyPass http://buggyappserver:7001/foo/  
   SetEnv force-proxy-request-1.0 1  
   SetEnv proxy-nokeepalive 1  
 

References

2012年9月5日 星期三

CAS SSO flow chart



Java client certificates over HTTPS/SSL

1. Using keytool to import SSL certificates into Sun JDK

A.Download certificate through Firefox. 
B.Create cacerts file.

 keytool -import -keystore "d:/cacerts" -file d:\SERVICE.cer  
 move d:/cacerts to /java-home/lib/security/cacerts  
 keytool -v -list -keystore /java-home/lib/security/cacerts  


C.Write Jersey Client to connect https service.
 public class SSLClient {  
   private WebResource baseResource;  
   private final static MediaType RESPONSE_TYPE = MediaType.APPLICATION_JSON_TYPE;  
   public SSLClient() throws Exception {  
     ClientConfig clientConfig = new DefaultClientConfig();  
     clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);  
     Client client = Client.create(clientConfig);  
     baseResource = client.resource("https://xxx.xxx");  
     // Added Logging filter to make debugging easier.  
     baseResource.addFilter(new LoggingFilter());  
   }  
   public VoObject getService() {  
     return baseResource.type(RESPONSE_TYPE).get(VoObject.class);  
   }  
   public static void main(String[] args) throws Exception {  
     System.out.println(new SSLClient().getService());  
   }  
 }  

2.  Create All trust manager
A.Download certificate through Firefox. 

 public class SSLClient {  
   private WebResource baseResource;  
   private final static MediaType RESPONSE_TYPE = MediaType.APPLICATION_JSON_TYPE;  
   public SSLClient() throws Exception {  
     ClientConfig clientConfig = new DefaultClientConfig();  
     // =======================================================SSL  
     SSLContext ctx = SSLContext.getInstance("SSL");  
     ctx.init(null, getAllTrustManager(), null);  
     clientConfig.getProperties().put(  
       HTTPSProperties.PROPERTY_HTTPS_PROPERTIES,  
       new HTTPSProperties(getHostnameVerifier(), ctx)  
     );  
     // =======================================================  
     clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);  
     Client client = Client.create(clientConfig);  
     baseResource = client.resource("https://xxx.xxx/");  
     baseResource.addFilter(new LoggingFilter());  
   }  
   private HostnameVerifier getHostnameVerifier() {  
     return new HostnameVerifier() {  
       public boolean verify(String hostname, javax.net.ssl.SSLSession sslSession) {  
         return true;  
       }  
     };  
   }  
   // Trust all the certificates  
   private TrustManager[] getAllTrustManager() {  
     return new TrustManager[] { new X509TrustManager() {  
       public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {}  
       public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {}  
       public X509Certificate[] getAcceptedIssuers() {  
         return null;  
       }  
     } };  
   }  
   public VoService getService() {  
     return baseResource.type(RESPONSE_TYPE).get(VoService.class);  
   }  
   public static void main(String[] args) throws Exception {  
     System.out.println(new SSLClient().getService());  
   }  
 }  

References