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" />
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!





No comments:
Post a Comment