Archive

Archive for December, 2009

How to install wordpress 2.9 in Apache on your localhost in Ubuntu 9.10

December 28th, 2009 Karthikeyan C No comments

This post contains the steps involved to setup wordpress on your local machine in Ubuntu. ( You may want to setup a wordpress blog on local machine to customize your blog (look and feel etc) so as to save the time to FTP to a remote location.)

  1. Install Apache server using the command sudo apt-get install apache2
  2. Install PHP with sudo apt-get install php5
  3. Install the MySQL Database  sudo apt-get install mysql-server
  4. Install the PHP module for the Database sudo apt-get install php5-mysql
  5. Download the latest stable version of wordpress from http://wordpress.org/download/
  6. Extract the wordpress tar.gz or zip file to /var/www (using the command tar -C /var/www -zxvf wordpress-2.9.tar.gz)
  7. Create a MySQL database and if needed a new user who has required privileges.
  8. Navigate to /var/www/wordpress and execute the following command cp wp-config-sample.php wp-config.php (You may do this logging in as root user with the command sudo su )
  9. Edit wp-config.php using the command nano wp-config.php (or use any other editor like gedit) and configure the values for Database connection.
  10. Edit /etc/apache2/httpd.conf file to add the following lines. 
    LoadModule php5_module modules/libphp5.so
    AddType application/x-httpd-php  .php .phtml
  11. Restart apache server using the command sudo /etc/init.d/apache2 restart
  12. You can access the blog using http://localhost/wordpress
  • Share/Bookmark
Categories: Installation / Configuration Tags:

Tutorial – Your first CXF web service in 10 minutes

December 16th, 2009 Karthikeyan C 1 comment

This post is for Java developers who wish to start developing web services using CXF.It is assumed you have Tomcat 6.0.x installed on your machine and an IDE that supports Maven projects.

There are 2 Maven projects involved.

  • Project 1 is the web application (deployed in Tomcat) which contains the CXF web service which accepts time in milliseconds and returns the related java.util.Date object.
  • Project 2 is the client side standalone Java code invoking this web service.

Please click here to browse/checkout the source code of the web application is available in Google code.

Please click here to browse/checkout the source code of the standalone Java client.

We start with the web service interface provided below which has the method to convert time in milli seconds to Date format.


package com.karthik;

import javax.jws.WebParam;
import javax.jws.WebService;

@WebService
public interface DateConversionService {
 java.util.Date convertDate(@WebParam(name="timeInMilliSecs") Long timeInMilliSecs);
}

The implementation class is as below.


package com.karthik;

import java.util.Date;
import javax.jws.WebService;

@WebService(endpointInterface="com.karthik.DateConversionService")
public class DateConversionServiceImpl implements DateConversionService{

 @Override
 public Date convertDate(Long timeInMilliSecs) {
 return new Date(timeInMilliSecs);
 }

}

We have to inform CXF to deploy the web service by providing the necessary details in a Spring Bean configuration file. The file name is cxf.xml and contains the following code (Few XML name spaces are not needed but provided so that we can reuse the same for future posts in CXF series).


<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:jaxws="http://cxf.apache.org/jaxws"
 xmlns:cxf="http://cxf.apache.org/core"
 xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
 xsi:schemaLocation
 ="http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
 http://cxf.apache.org/jaxws
 http://cxf.apache.org/schemas/jaxws.xsd
 http://cxf.apache.org/core
 http://cxf.apache.org/schemas/core.xsd
 http://cxf.apache.org/transports/http/configuration
 http://cxf.apache.org/schemas/configuration/http-conf.xsd">

 <!-- Load CXF modules from cxf.jar -->
 <import resource="classpath:META-INF/cxf/cxf.xml" />
 <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
 <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

 <jaxws:endpoint id="dateconversion"  address="/DateConversionWS" implementor="com.karthik.DateConversionServiceImpl"/>

</beans>

Now in web.xml we configure the URL at which CXF servlet will be listening and also inform the location of the configuration file (that is the above cxf.xml).


<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
 xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 <displayname>karthikeyanc.com CXF example</displayname>
 <context-param>
 <param-name>contextConfigLocation</param-name>
 <param-value>classpath:cxf.xml</param-value>
 </context-param>
 <listener>
 <listener-class>
 org.springframework.web.context.ContextLoaderListener
 </listener-class>
 </listener>
 <servlet>
 <servlet-name>CXFServlet</servlet-name>
 <servlet-class>
 org.apache.cxf.transport.servlet.CXFServlet
 </servlet-class>
 </servlet>
 <servlet-mapping>
 <servlet-name>CXFServlet</servlet-name>
 <url-pattern>/services/*</url-pattern>
 </servlet-mapping>
 </web-app>

Note: The pom.xml of this web application uses Maven assembly plugin to pack the web service interface which will  be referred as a dependency from the standalone Java client. By doing this we do not duplicate the web service interface file.

Please navigate to the project root folder and run mvn install. Under Tomcat_Home/conf/Catalina/localhost, create file called convertdate.xml to configure the context for this web application (As convertdate) and point to the target directory of the maven project as below. (Please change the docBase accordingly). Then start Tomcat. The WSDL can be obtained by typing the following in the URL http://localhost:8080/convertdate/services/DateConversionWS?wsdl


<Context path="/convertdate" docBase="/home/pathtoprojectroot/cxfwebappdateconverter/target/cxfdate"/>

Running the standalone Java client:

Now you may open the stand alone client project in an IDE (I use NetBeans 6.8) and run DateConversionServiceClient.java. This is the only Java file in the client project. The web service interface comes from the distribution jar ( created when running mvn install command for the web application Maven project). The source code of DateConversionServiceClient.java is as below. (Please change port number accordingly).


package com.karthik.client;

import com.karthik.DateConversionService;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;

public class DateConversionServiceClient {

 private static final String ADDRESS="http://localhost:8080/convertdate/services/DateConversionWS";
 public static void main(String[] args) {
 JaxWsProxyFactoryBean fb=new JaxWsProxyFactoryBean();
 fb.setAddress(ADDRESS);
 fb.setServiceClass(DateConversionService.class);
 DateConversionService service=(DateConversionService) fb.create();
 System.out.println("The date converted is :"+service.convertDate(System.currentTimeMillis()));

 }
}
  • Share/Bookmark
Categories: Development Tags: ,

JBoss Tricks – How to deploy WAR JAR EAR in an external folder (directory)

December 11th, 2009 Karthikeyan C No comments

With JBoss 6.0.0.M1 out to try out the new JSRs the following may be helpful in reducing time to deploy.

The usual way in which we deploy an application (war , jar or ear ) is to drop the application archive ( or in expanded mode with the folder name ending with .war or .ear) under deploy folder of the server.

But how to deploy an application archive or a folder when it is not residing under deploy folder but resides in some other external folder?

Let’s say the application ROOT folder is E:\javaapps\myapptodeploy\webapplication.war, then in jboss-service.xml (under conf folder of the JBoss server profile (like default, all)),  we mention the following. This is very helpful when we build the project using Maven as we can mention the target directory directly without copying the files after each build.


<attribute name="URLs">
 deploy/,file:///E:/javaapps/myapptodeploy
</attribute>
  • Share/Bookmark