Skip to content
Permalink
Browse files
TRANSPORTS-50 - Added a sample to demonstrate use of HTTPS transport.…
… This sample is based on Jetty Maven plug-in and keytool-maven-plugin.
  • Loading branch information
Sagara Gunathunga committed May 2, 2012
1 parent f9a7a5d commit a5d708998f1825906bb6c421f7d1750dba60310a
Showing 10 changed files with 855 additions and 0 deletions.
@@ -0,0 +1,52 @@
Sample: HTTPS Sample
===============

Introduction
============

This sample demonstrate use of HTTPS transport in both server and client sides. Jetty Maven plug-in used as
the web server and keytool-maven-plugin is used to generate secure key for the sample further same generated
key is used in client side too. This sample does not try to introduce secure key management best practices,
but in real world scenarios it's recommended to follow standard key management practices.


Pre-Requisites
==============

Apache Maven 2.X or 3.X



Running the Sample Service
=========================

1.) In a command line move to "samples/https-sample/httpsService" directory and run " mvn clean jetty:run"

2.) You should able to see following message on console.

"XXXX-XX-XX XX:XX:XX. XXX:INFO::Started SslSocketConnector@0.0.0.0:8443"

3.) Try to access WSDL file through the following URL, in some browsers you have to force to accepts the server certificate.

https://localhost:8443/services/SimpleService?wsdl


Running the Sample Client
=========================

1.) In a another command window move to this directory "samples/https-sample/httpsClient".

2.) Run following command.

"mvn exec:java -Dexec.mainClass="org.apache.axis2.examples.httpsclient.SimpleServiceClient" -Dexec.classpathScope=runtime"


3.) You should able to see the response as follows.

<ns:helloServiceResponse xmlns:ns="http://httpsservice.examples.axis2.apache.org"><ns:return>Hello World </ns:return></ns:helloServiceResponse>



Help
====
Please contact java-user list (java-user@axis.apache.org) if you have any trouble running the sample.
@@ -0,0 +1,24 @@
<!-- ~ Licensed to the Apache Software Foundation (ASF) under one ~ or more
contributor license agreements. See the NOTICE file ~ distributed with this
work for additional information ~ regarding copyright ownership. The ASF
licenses this file ~ to you under the Apache License, Version 2.0 (the ~
"License"); you may not use this file except in compliance ~ with the License.
You may obtain a copy of the License at ~ ~ http://www.apache.org/licenses/LICENSE-2.0
~ ~ Unless required by applicable law or agreed to in writing, ~ software
distributed under the License is distributed on an ~ "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY ~ KIND, either express or implied. See the
License for the ~ specific language governing permissions and limitations
~ under the License. -->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>https-sample</artifactId>
<groupId>org.apache.axis2.examples</groupId>
<version>1.7.0-SNAPSHOT</version>
</parent>
<groupId>org.apache.axis2.examples</groupId>
<artifactId>httpsClient</artifactId>
<version>1.7.0-SNAPSHOT</version>
</project>
@@ -0,0 +1,61 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.axis2.examples.httpsclient;

import javax.xml.stream.XMLStreamException;

import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;

public class SimpleServiceClient {

public static void main(String[] ars) throws AxisFault, XMLStreamException {
// Client side keystore location, here we use same keystore
System.setProperty("javax.net.ssl.trustStore", "../httpsService/target/jetty-ssl.keystore");
System.setProperty("javax.net.ssl.trustStorePassword", "axis2key");
String epr = "https://localhost:8443/services/SimpleService/";

Options options = new Options();
options.setTo(new EndpointReference(epr));
ServiceClient sender = new ServiceClient();
sender.setOptions(options);
OMElement ret = sender.sendReceive(creatMsg());
ret.serialize(System.out);

}

public static OMElement creatMsg() {
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace("http://httpsservice.examples.axis2.apache.org",
"ns1");
OMElement method = fac.createOMElement("helloService", omNs);
OMElement value = fac.createOMElement("msg", omNs);
value.setText("World ");
method.addChild(value);
return method;
}

}
@@ -0,0 +1,76 @@
<!-- ~ Licensed to the Apache Software Foundation (ASF) under one ~ or more
contributor license agreements. See the NOTICE file ~ distributed with this
work for additional information ~ regarding copyright ownership. The ASF
licenses this file ~ to you under the Apache License, Version 2.0 (the ~
"License"); you may not use this file except in compliance ~ with the License.
You may obtain a copy of the License at ~ ~ http://www.apache.org/licenses/LICENSE-2.0
~ ~ Unless required by applicable law or agreed to in writing, ~ software
distributed under the License is distributed on an ~ "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY ~ KIND, either express or implied. See the
License for the ~ specific language governing permissions and limitations
~ under the License. -->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>https-sample</artifactId>
<groupId>org.apache.axis2.examples</groupId>
<version>1.7.0-SNAPSHOT</version>
</parent>
<groupId>org.apache.axis2.examples</groupId>
<artifactId>httpsService</artifactId>
<version>1.7.0-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>keytool-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-resources</phase>
<id>clean</id>
<goals>
<goal>clean</goal>
</goals>
</execution>
<execution>
<phase>generate-resources</phase>
<id>genkey</id>
<goals>
<goal>genkey</goal>
</goals>
</execution>
</executions>
<configuration>
<keystore>${project.build.directory}/jetty-ssl.keystore</keystore>
<dname>cn=localhost</dname>
<keypass>axis2key</keypass>
<storepass>axis2key</storepass>
<alias>axis2key</alias>
<keyalg>RSA</keyalg>
</configuration>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<configuration>
<webAppConfig>
<contextPath>/</contextPath>
</webAppConfig>
<connectors>
<connector
implementation="org.mortbay.jetty.security.SslSocketConnector">
<port>8443</port>
<maxIdleTime>60000</maxIdleTime>
<keystore>${project.build.directory}/jetty-ssl.keystore</keystore>
<password>axis2key</password>
<keyPassword>axis2key</keyPassword>
</connector>
</connectors>
</configuration>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,28 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.axis2.examples.httpsservice;

public class SimpleService {

public String helloService(String msg) {
return "Hello " + msg;
}

}

0 comments on commit a5d7089

Please sign in to comment.