Friday, 21 October 2011

Tomcat + Axis2 + Eclipse + Axis2 Code Gen Part 6

Part 6 Setup SSL on tomcat + Axis2

Key in the following commands to create the keystore at the cmd prompt.

%JAVA_HOME%\bin\keytool -genkey -alias <servername> -keyalg RSA -keystore C:/apache-tomcat-6.0.33/webapps/axis2/WEB-INF/conf/keystore.jks


eg,
If your server name to host the webservice is ebwmbl021, then the command will be like
%JAVA_HOME%\bin\keytool -genkey -alias ebwmbl021 -keyalg RSA -keystore C:/apache-tomcat-6.0.33/webapps/axis2/WEB-INF/conf/keystore.jks


You may just type 'hostname' to check your servername.


Keytool will as a list of question as below, please key in accordingly.


Keystore will be created in C:\apache-tomcat-6.0.33\webapps\axis2\WEB-INF\conf\


Open C:\apache-tomcat-6.0.33\webapps\axis2\WEB-INF\conf\axis2.xml with text editor.
Locate the line of <transportReceiver name="http" class="org.apache.axis2.transport.http.AxisServletListener"/>

Add in the lines below to enable the SSL.

<transportReceiver name="https" class="org.apache.axis2.transport.http.AxisServletListener">
<parameter name="port">8443</parameter>
</transportReceiver>



Open C:\apache-tomcat-6.0.33\conf\server.xml with text editor.
Locate the line <!-- Define a SSL HTTP/1.1 Connector on port 8443 -->
 
Add in the lines as below :




<!-- Define a SSL HTTP/1.1 Connector on port 8443 -->  
<Connector protocol="org.apache.coyote.http11.Http11Protocol" port="8443" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" disableUploadTimeout="true"
acceptCount="100" scheme="https" secure="true" SSLEnabled="true"
keystoreFile="C:/apache-tomcat-6.0.33/webapps/axis2/WEB-INF/conf/keystore.jks"
keystorePass="changeit" clientAuth="false" sslProtocol="TLS" />


Restart tomcat server.

Open web browser, browses https://localhost:8443/axis2/services/listServices
If you manage to see the screen below, means the service is already running on SSL.
 

Now we need to change the tester program as below to test via port 8443.


import org.apache.axis2.AxisFault;


import hookinforest.service.FTPAlternativeServiceStub;
import hookinforest.service.FTPAlternativeServiceStub.FTPAlternativeVO;
import hookinforest.service.FTPAlternativeServiceStub.GenerateFile;
import hookinforest.service.FTPAlternativeServiceStub.GenerateFileResponse;


public class HookInForestWSTester {
public static void main(String[] args) {
try {
System.setProperty("javax.net.ssl.trustStore","C:/apache-tomcat-6.0.33/webapps/axis2/WEB-INF/conf/keystore.jks");
System.setProperty("javax.net.ssl.trustStorePassword","changeit");


FTPAlternativeServiceStub ftpAlternativeServiceStub 
= new FTPAlternativeServiceStub("https://ebwmbl021:8443/axis2/services/FTPAlternativeService");

GenerateFile generateFile = new GenerateFile();
FTPAlternativeVO ftpAlternativeVO = new FTPAlternativeVO();
ftpAlternativeVO.setTicketPath("c:/HookInForestWSTesting.txt");
ftpAlternativeVO.setTicketContent("This is a test");
generateFile.setArgs0(ftpAlternativeVO);
GenerateFileResponse generateFileResponse = new GenerateFileResponse();
generateFileResponse = ftpAlternativeServiceStub.generateFile(generateFile);
   System.out.println("Call Result : "+ generateFileResponse.get_return().getStatus());
} catch (AxisFault e) {
e.printStackTrace();
}catch(Exception e)
{
e.printStackTrace();
}
}
}

That's it for SSL configuration for tomcat + Axis2!

Monday, 17 October 2011

Tomcat + Axis2 + Eclipse + Axis2 Code Gen Part 5

Part 5 Create a Tester program.


Create a new java class from HookInForestWSClient project.



Key in the class name as HookInForestWSTester and click on Finish button.






Copy and paste the below coding into the java class.



import org.apache.axis2.AxisFault;


import hookinforest.service.FTPAlternativeServiceStub;
import hookinforest.service.FTPAlternativeServiceStub.FTPAlternativeVO;
import hookinforest.service.FTPAlternativeServiceStub.GenerateFile;
import hookinforest.service.FTPAlternativeServiceStub.GenerateFileResponse;


public class HookInForestWSTester {
public static void main(String[] args) {
try {

FTPAlternativeServiceStub ftpAlternativeServiceStub = new FTPAlternativeServiceStub();
GenerateFile generateFile = new GenerateFile();
FTPAlternativeVO ftpAlternativeVO = new FTPAlternativeVO();
ftpAlternativeVO.setTicketPath("c:/HookInForestWSTesting.txt");
ftpAlternativeVO.setTicketContent("This is a test");
generateFile.setArgs0(ftpAlternativeVO);
GenerateFileResponse generateFileResponse = new GenerateFileResponse();
generateFileResponse = ftpAlternativeServiceStub.generateFile(generateFile);
   System.out.println("Call Result : "+ generateFileResponse.get_return().getStatus());
} catch (AxisFault e) {
e.printStackTrace();
}catch(Exception e)
{
e.printStackTrace();
}
}
}

Right click the source code and run as java application.


If you see the message "Call Result : true" from console, that means you have successfully run the tester application.

Go to C drive and check, you should able to find the HookInForestWSTesting.txt at there.


Tomcat + Axis2 + Eclipse + Axis2 Code Gen Part 4

Part 4 Generate Webservice Client


Download and install the Axis2 code gen tool for eclipse plugin.
Please follow the instruction stated as in
http://axis.apache.org/axis2/java/core/tools/eclipse/plugin-installation.html

Start Eclipse, Choose from menu, File -> New-> Other...
Browse to Axis2 Wizards and select Axis2 Code Generator and click Next button.



Select the option Generate Java source code from WSDL file and click Next button.



Click on Browse button, in the File name entry box, key in http://localhost:8080/axis2/services/FTPAlternativeService?wsdl to refer to the webservice WSDL and click on open button.



Click next button to see the screen as below, don't change anything for this screen and click next button to proceed.


Key in the information as screen below and click on the Finish button.


If you see the screen below, that means you have successfully generated the java code from WSDL file.


Create a new java project from eclipse, key in the project name HookInForestWSClient and click Finish button.



After created the project, you will be able to see the previous generated source codes in the project.
Right click on the build.xml and run as ant build.


That's it for the webservice client generation!

Saturday, 15 October 2011

Tomcat + Axis2 + Eclipse + Axis2 Code Gen Part 3

Part 3 Start Webservice


Go to C:\apache-tomcat-6.0.33\bin, click on startup.bat to start tomcat.

Axis2 will be automatically installed when you start tomcat.
It will detect there is a axis2.war in the C:\apache-tomcat-6.0.33\webapps\ and automatically install the Axis2.

After tomcat started, copy the C:\HookInForestSampleWS\build\ftp-alternative-ws.aar into C:\apache-tomcat-6.0.33\webapps\axis2\WEB-INF\services\

Web service will be installed upon the file copied into C:\apache-tomcat-6.0.33\webapps\axis2\WEB-INF\services\

Open the internet browser, browse URL http://localhost:8080/axis2/services/listServices
You will be able to see the deployed webservice.




Tomcat + Axis2 + Eclipse + Axis2 Code Gen Part 2

Part 2 Build Project

After download all the files that stated in Part 1.
It is time for us to open the project using eclipse.

use explorer go to C:\eclipse, click on eclipse.exe to start.
It will prompt to select a workspace. Please key in c:\ as screen below.



If it doesn't prompt to ask for selecting workspace or you have selected a wrong workspace, you may always go to File menu-> Switch Workspace-> Other.. to reselect project workspace.
For a better picture of what I am saying, please refer the screen below.


After select the workspace, Create a java project from File menu->Java Project.
Key in the project information as below:



Click on the finish button to proceed.
Once java project created, you should be able to our sample folder structure from Project explorer.



The next step is to build the project, right click on the build.xml, choose run as ant build to build the project file.



After build, ftp-alternative-ws.aar will be the output file that we going to be deployed with tomcat.
you should be able to found it at C:\HookInForestSampleWS\build\

Tuesday, 11 October 2011

Tomcat + Axis2 + Eclipse + Axis2 Code Gen Part 1

Recently done some works on tomcat webservice.
I am here to post some simple example, hoping that it can help some of you that working on the similar thing.

Part 1 Download & Setup

For part 1, please download the components as listed below :

Axis2 will run on JDK 5 and above.
I will use JDK 6 in this example, Please download the JDK 6 at
http://www.oracle.com/technetwork/java/javase/downloads/index.html
Install it after download.

For Tomcat, please download the tomcat 6.0 version at
http://tomcat.apache.org/download-55.cgi
After download, please unzip it to C drive as C:\apache-tomcat-6.0.33

For Eclipse, please download the Eclipse IDE for Java EE Developers at
http://www.eclipse.org/downloads/packages/release/helios/sr2
After download, please unzip it to C drive as c:\eclipse

For Axis2, please download the Axis2-1.6.1 at
http://axis.apache.org/axis2/java/core/download.cgi
There are Binary distribution and War distribution, download both and
for Binary distribution, please unzip it to C drive as c:\axis2-1.6.1
for War distribution, please unzip it into C:\apache-tomcat-6.0.33\webapps

I have prepared a very simple java project folder 'HookInForestSampleWS', please download at
http://www.filedude.com/download/TM3rcNjgFra118029a7a
http://www.mediafire.com/?b3w6ni4byi7wbp2


After download please unzip to C drive as C:\HookInForestSampleWS