From a5d708998f1825906bb6c421f7d1750dba60310a Mon Sep 17 00:00:00 2001 From: Sagara Gunathunga Date: Wed, 2 May 2012 09:29:03 +0000 Subject: [PATCH] TRANSPORTS-50 - Added a sample to demonstrate use of HTTPS transport. This sample is based on Jetty Maven plug-in and keytool-maven-plugin. --- modules/samples/https-sample/README.txt | 52 ++ .../samples/https-sample/httpsClient/pom.xml | 24 + .../httpsclient/SimpleServiceClient.java | 61 +++ .../samples/https-sample/httpsService/pom.xml | 76 +++ .../examples/httpsservice/SimpleService.java | 28 + .../src/main/webapp/WEB-INF/axis2.xml | 493 ++++++++++++++++++ .../SimpleService/META-INF/services.xml | 27 + .../src/main/webapp/WEB-INF/web.xml | 29 ++ modules/samples/https-sample/pom.xml | 64 +++ pom.xml | 1 + 10 files changed, 855 insertions(+) create mode 100644 modules/samples/https-sample/README.txt create mode 100644 modules/samples/https-sample/httpsClient/pom.xml create mode 100644 modules/samples/https-sample/httpsClient/src/main/java/org/apache/axis2/examples/httpsclient/SimpleServiceClient.java create mode 100644 modules/samples/https-sample/httpsService/pom.xml create mode 100644 modules/samples/https-sample/httpsService/src/main/java/org/apache/axis2/examples/httpsservice/SimpleService.java create mode 100644 modules/samples/https-sample/httpsService/src/main/webapp/WEB-INF/axis2.xml create mode 100644 modules/samples/https-sample/httpsService/src/main/webapp/WEB-INF/services/SimpleService/META-INF/services.xml create mode 100644 modules/samples/https-sample/httpsService/src/main/webapp/WEB-INF/web.xml create mode 100644 modules/samples/https-sample/pom.xml diff --git a/modules/samples/https-sample/README.txt b/modules/samples/https-sample/README.txt new file mode 100644 index 0000000..4b6b3d5 --- /dev/null +++ b/modules/samples/https-sample/README.txt @@ -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. + +Hello World + + + +Help +==== +Please contact java-user list (java-user@axis.apache.org) if you have any trouble running the sample. diff --git a/modules/samples/https-sample/httpsClient/pom.xml b/modules/samples/https-sample/httpsClient/pom.xml new file mode 100644 index 0000000..fad40ed --- /dev/null +++ b/modules/samples/https-sample/httpsClient/pom.xml @@ -0,0 +1,24 @@ + + + + 4.0.0 + + https-sample + org.apache.axis2.examples + 1.7.0-SNAPSHOT + + org.apache.axis2.examples + httpsClient + 1.7.0-SNAPSHOT + \ No newline at end of file diff --git a/modules/samples/https-sample/httpsClient/src/main/java/org/apache/axis2/examples/httpsclient/SimpleServiceClient.java b/modules/samples/https-sample/httpsClient/src/main/java/org/apache/axis2/examples/httpsclient/SimpleServiceClient.java new file mode 100644 index 0000000..3889479 --- /dev/null +++ b/modules/samples/https-sample/httpsClient/src/main/java/org/apache/axis2/examples/httpsclient/SimpleServiceClient.java @@ -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; + } + +} diff --git a/modules/samples/https-sample/httpsService/pom.xml b/modules/samples/https-sample/httpsService/pom.xml new file mode 100644 index 0000000..a517c7c --- /dev/null +++ b/modules/samples/https-sample/httpsService/pom.xml @@ -0,0 +1,76 @@ + + + + 4.0.0 + + https-sample + org.apache.axis2.examples + 1.7.0-SNAPSHOT + + org.apache.axis2.examples + httpsService + 1.7.0-SNAPSHOT + war + + + + org.codehaus.mojo + keytool-maven-plugin + + + generate-resources + clean + + clean + + + + generate-resources + genkey + + genkey + + + + + ${project.build.directory}/jetty-ssl.keystore + cn=localhost + axis2key + axis2key + axis2key + RSA + + + + org.mortbay.jetty + maven-jetty-plugin + + + / + + + + 8443 + 60000 + ${project.build.directory}/jetty-ssl.keystore + axis2key + axis2key + + + + + + + \ No newline at end of file diff --git a/modules/samples/https-sample/httpsService/src/main/java/org/apache/axis2/examples/httpsservice/SimpleService.java b/modules/samples/https-sample/httpsService/src/main/java/org/apache/axis2/examples/httpsservice/SimpleService.java new file mode 100644 index 0000000..e6cce09 --- /dev/null +++ b/modules/samples/https-sample/httpsService/src/main/java/org/apache/axis2/examples/httpsservice/SimpleService.java @@ -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; + } + +} diff --git a/modules/samples/https-sample/httpsService/src/main/webapp/WEB-INF/axis2.xml b/modules/samples/https-sample/httpsService/src/main/webapp/WEB-INF/axis2.xml new file mode 100644 index 0000000..144a770 --- /dev/null +++ b/modules/samples/https-sample/httpsService/src/main/webapp/WEB-INF/axis2.xml @@ -0,0 +1,493 @@ + + + + + + + true + false + false + false + + + + + false + + + true + + + + + + + + + + + + + + 30000 + + + + false + + + + + + false + + admin + axis2 + + + + + + + + + + + + + + + + + + + + + + + + + false + + + false + + + + + + + + + + + + + + + + + + + + + + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 8080 + + + + 8443 + + + + + + + + HTTP/1.1 + chunked + + + + + + + HTTP/1.1 + chunked + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + multicast + + + wso2.carbon.domain + + + true + + + 10 + + + 228.0.0.4 + + + 45564 + + + 500 + + + 3000 + + + 127.0.0.1 + + + 127.0.0.1 + + + 4000 + + + true + + + true + + + + + + + + + + + 127.0.0.1 + 4000 + + + 127.0.0.1 + 4001 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/samples/https-sample/httpsService/src/main/webapp/WEB-INF/services/SimpleService/META-INF/services.xml b/modules/samples/https-sample/httpsService/src/main/webapp/WEB-INF/services/SimpleService/META-INF/services.xml new file mode 100644 index 0000000..075d24e --- /dev/null +++ b/modules/samples/https-sample/httpsService/src/main/webapp/WEB-INF/services/SimpleService/META-INF/services.xml @@ -0,0 +1,27 @@ + + + + + + + org.apache.axis2.examples.httpsservice.SimpleService + + + + + + https + + + \ No newline at end of file diff --git a/modules/samples/https-sample/httpsService/src/main/webapp/WEB-INF/web.xml b/modules/samples/https-sample/httpsService/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..376b871 --- /dev/null +++ b/modules/samples/https-sample/httpsService/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,29 @@ + + + + + + + + + AxisServlet + org.apache.axis2.transport.http.AxisServlet + 1 + + + AxisServlet + /services/* + + \ No newline at end of file diff --git a/modules/samples/https-sample/pom.xml b/modules/samples/https-sample/pom.xml new file mode 100644 index 0000000..97cdd6a --- /dev/null +++ b/modules/samples/https-sample/pom.xml @@ -0,0 +1,64 @@ + + + + 4.0.0 + org.apache.axis2.examples + https-sample + 1.7.0-SNAPSHOT + pom + Apache Axis2 Transport-HTTPS sample + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.5 + 1.5 + + + + + + + org.apache.axis2 + axis2-adb + ${project.version} + + + org.apache.axis2 + axis2-transport-http + ${project.version} + + + org.apache.axis2 + axis2-transport-local + ${project.version} + + + + + apache.snapshots + Apache Snapshot Repository + http://repository.apache.org/snapshots + + false + + + + + httpsService + httpsClient + + diff --git a/pom.xml b/pom.xml index f115d9e..5aac3e4 100644 --- a/pom.xml +++ b/pom.xml @@ -157,6 +157,7 @@ modules/sms modules/testkit modules/all + modules/samples/https-sample