Category Archives: Network

[Server] Upgrade Hudson to lastest version on Ubuntu Server

1. Back up the Hudson global and job specific configurations with thinBackup

Install thinBackup Hudson’s plug-in

thinBackup

Configure

thinBackupSettings

Make directory: /home/hudson-backup

sudo mkdir /home/hudson-backup

sudo chmod 777 -R /home/hudson-backup

Backup: Chose Backup Now

Restore: Chose Restore. Restart Hudson

sudo service hudson stop

sudo service hudson start

Sometime, I use below command to make sure Hudson was stopped

sudo pkill -9 -f hudson

2. Upgrade Hudson

sudo sh -c “echo ‘deb http://hudson-ci.org/debian binary/’ > /etc/apt/sources.list.d/hudson.list”

sudo sh -c “echo ‘deb http://hudson-ci.org/debian /’ > /etc/apt/sources.list.d/hudson.list”

sudo apt-get update

sudo apt-get install hudson

sudo apt-get update

sudo apt-get upgrade

Restart Hudson

sudo service hudson stop

sudo service hudson start

References

[1]. http://wiki.hudson-ci.org/display/HUDSON/thinBackup

[2]. http://wiki.eclipse.org/Hudson-ci/Installing_Hudson_DEB

[3]. http://www.eclipse.org/hudson/the-hudson-book/book-hudson.chunked/ch02.html

Advertisements

[Server-Spring] Configure connection pool with Spring based – c3p0, Apache DBCP and BoneCP

Application Context

1. Without connection pool

</pre>
<!-- Data Source Declaration -->
<bean id="myDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="${db.url}" />
<property name="username" value="${db.username}" />
<property name="password" value="${db.password}" />
</bean>
<pre>

2. c3p0


<!-- C3P0 Connection Pool -->
<bean id="c3p0" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="org.postgresql.Driver" />
<property name="jdbcUrl" value="${db.url}" />
<property name="user" value="${db.username}" />
<property name="password" value="${db.password}" />

<property name="minPoolSize" value="5" />
<property name="maxPoolSize" value="20" />
<property name="maxStatements" value="50" />
<property name="idleConnectionTestPeriod" value="3000" />
<property name="loginTimeout" value="300" />
</bean>
<pre>

3. Apache DBCP

</pre>
<!-- DBCP configuration -->
<bean id="dbcp" class="com.jolbox.bonecp.BoneCPDataSource"
destroy-method="close">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="${db.url}" />
<property name="username" value="${db.username}" />
<property name="password" value="${db.password}" />
<property name="removeAbandoned" value="true" />
<property name="initialSize" value="20" />
<property name="maxActive" value="30" />
</bean>
<pre>

4. BoneCP

</pre>
<!-- BoneCP configuration -->
<bean id="boneCP" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClass" value="org.postgresql.Driver" />
<property name="jdbcUrl" value="${db.url}" />
<property name="username" value="${db.username}" />
<property name="password" value="${db.password}" />
<property name="idleConnectionTestPeriodInMinutes" value="60" />
<property name="idleMaxAgeInMinutes" value="240" />
<property name="maxConnectionsPerPartition" value="30" />
<property name="minConnectionsPerPartition" value="10" />
<property name="partitionCount" value="3" />
<property name="acquireIncrement" value="5" />
<property name="statementsCacheSize" value="100" />
</bean>

and session factory declaration…

</pre></pre>
<!-- Session Factory Declaration -->
<bean id="mySessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="myDataSource" /> <!-- without connection pool -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.enable_lazy_load_no_trans">true</prop>
<prop key="hibernate.default_schema">myagile</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
<pre>

Reference:
[1]. http://jolbox.com/
[2]. http://www.javacodegeeks.com/2012/04/jsf-2-primefaces-3-spring-3-hibernate-4.html
[3]. http://www.mchange.com/projects/c3p0/
[4]. http://www.mkyong.com/hibernate/how-to-configure-the-c3p0-connection-pool-in-hibernate/

[Server] Redirect HTTP to HTTPS using Servlet Filter

1. Write a filter to redirect from http to https


package vn.nvanhuong.servlet;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HTTPSFilter implements Filter {

public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws java.io.IOException, ServletException {

HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse res = (HttpServletResponse) response;

String uri = req.getRequestURI();
String getProtocol = req.getScheme();
String getDomain = req.getServerName();
String getPort = Integer.toString(req.getServerPort());

if (getProtocol.toLowerCase().equals(&quot;http&quot;)) {

// Set response content type
response.setContentType(&quot;text/html&quot;);

// New location to be redirected
String httpsPath = &quot;https&quot; + &quot;://&quot; + getDomain + &quot;:&quot; + getPort
+ uri;

String site = new String(httpsPath);
res.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
res.setHeader(&quot;Location&quot;, site);
}

// Pass request back down the filter chain
chain.doFilter(req, res);

}

@Override
public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub

}

@Override
public void destroy() {
// TODO Auto-generated method stub

}

}

2. Compile above filter and create following entries in web.xml


&lt;!-- HTTPS Redirect --&gt;
&lt;filter&gt;
&lt;filter-name&gt;HTTPS&lt;/filter-name&gt;
&lt;filter-class&gt;vn.nvanhuong.servlet.HTTPSFilter&lt;/filter-class&gt;
&lt;/filter&gt;
&lt;filter-mapping&gt;
&lt;filter-name&gt;HTTPS&lt;/filter-name&gt;
&lt;url-pattern&gt;/*&lt;/url-pattern&gt;
&lt;/filter-mapping&gt;

References
[1]. http://www.tutorialspoint.com/servlets/servlets-page-redirect.htm
[2]. http://www.easywayserver.com/blog/jsp-get-url/

[Network] Setup SSL Certificate for Geronimo from exist certificate

vi-ssl-certificate

We used certificate (cert) issued by a CA (certificate authority).
This document only shows that how to set up ssl cert from private key and cert that we need to create private key and buy certificate from a CA before.

Please view document https_geronimo

Advanced programming

Tự học lập trình Android, android wear - lập trình smartwatch, Windows phone, Web service, C++, C#, java, Swift, Python, kotlin...

Tôi IT - Change the world

Research + Technical -> Programming,

juliansherman.net/

Building A Business While Having A Life

VN.NVANHUONG

No Pain No Gain

Study and Share's Blog

Việt Nam tươi đẹp...

Broly

One of the best way to learn is by writing to the paper.