Java/Web Services SOA/SOAP — различия между версиями

Материал из Java эксперт
Перейти к: навигация, поиск
 
м (1 версия)
 
(нет различий)

Текущая версия на 10:27, 1 июня 2010

A SOAP message with an attachment and XML-binary Optimized Packaging

   <source lang="java">

MTOM Demo for SWA & XOP

=================================

This demo illustrates the use of a SOAP message with an attachment and XML-binary Optimized Packaging. Please review the README in the samples directory before continuing.

Prerequisite


If your environment already includes cxf-manifest-incubator.jar on the CLASSPATH, and the JDK and ant bin directories on the PATH it is not necessary to set the environment as described in the samples directory"s README. If your environment is not properly configured, or if you are planning on using wsdl2java, javac, and java to build and run the demos, you must set the environment.

Building and running the demo using ant


From the samples/mtom directory, the ant build script can be used to build and run the demo. Using either UNIX or Windows:

 ant build
 ant server
 ant client
   

To remove the code generated from the WSDL file and the .class files, run:

 ant clean

Building the demo using wsdl2java and javac


From the samples/mtom directory, first create the target directory build/classes and then generate code from the WSDL file. For UNIX:

 mkdir -p build/classes
 wsdl2java -d build/classes -compile ./wsdl/mtom_xop.wsdl

For Windows:

 mkdir build\classes
   Must use back slashes.
 wsdl2java -d build\classes -compile .\wsdl\mtom_xop.wsdl
   May use either forward or back slashes.

Now compile the provided client and server applications with the commands: For UNIX:

 export CLASSPATH=$CLASSPATH:$CXF_HOME/lib/cxf-manifest-incubator.jar:./build/classes
 javac -d build/classes src/demo/mtom/client/*.java
 javac -d build/classes src/demo/mtom/server/*.java
 cp src/demo/mtom/client/me.bmp build/classes/demo/mtom/client/me.bmp

For Windows:

 set classpath=%classpath%;%CXF_HOME%\lib\cxf-manifest-incubator.jar;.\build\classes
 javac -d build\classes src\demo\mtom\client\*.java
 javac -d build\classes src\demo\mtom\server\*.java
 copy src\demo\mtom\client\me.bmp build\classes\demo\mtom\client\me.bmp

Running the demo using java


From the samples/mtom directory run the following commands. They are entered on a single command line. For UNIX (must use forward slashes):

   java -Djava.util.logging.config.file=$CXF_HOME/etc/logging.properties
        demo.mtom.server.Server &
   java -Djava.util.logging.config.file=$CXF_HOME/etc/logging.properties
        demo.mtom.client.Client ./wsdl/mtom_xop.wsdl

The server process starts in the background. After running the client, use the kill command to terminate the server process. For Windows (may use either forward or back slashes):

 start 
   java -Djava.util.logging.config.file=%CXF_HOME%\etc\logging.properties
        demo.mtom.server.Server
   java -Djava.util.logging.config.file=%CXF_HOME%\etc\logging.properties
      demo.mtom.client.Client .\wsdl\mtom_xop.wsdl

A new command windows opens for the server process. After running the client, terminate the server process by issuing Ctrl-C in its command window. To remove the code generated from the WSDL file and the .class files, either delete the build directory and its contents or run:

 ant clean

Building and running the demo in a servlet container


From the samples/mtom directory, the ant build script can be used to create the war file that is deployed into the servlet container. Build the war file with the command:

 ant war
   

The war file will be included in the directory samples/mtom/build/war. Simply copy the war file into the servlet container"s deployment directory. For example, with Tomcat copy the war file into the directory <installationDirectory>/webapps. The servlet container will extract the war and deploy the application. Make sure already copy all jars from CXF_HOME/lib to <TomcatInstallationDirectory>/shared/lib Using ant, run the client application with the command:

 ant client-servlet -Dbase.url=http://localhost:#

Where # is the TCP/IP port used by the servlet container, e.g., 8080. Using java, run the client application with the command:

 For UNIX:
   
   java -Djava.util.logging.config.file=$CXF_HOME/etc/logging.properties
        demo.mtom.client.Client http://localhost:#/mtom/services/mtom?wsdl
 For Windows:
   java -Djava.util.logging.config.file=%CXF_HOME%\etc\logging.properties
      demo.mtom.client.Client http://localhost:#/mtom/services/mtom?wsdl

Where # is the TCP/IP port used by the servlet container, e.g., 8080.

//////////////////////////////////////////////////////////////////

/**

* 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 demo.mtom.client; import java.awt.Image; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.net.URL; import javax.activation.DataHandler; import javax.imageio.ImageIO; import javax.mail.util.ByteArrayDataSource; import javax.xml.namespace.QName; import javax.xml.ws.Binding; import javax.xml.ws.BindingProvider; import javax.xml.ws.Holder; import javax.xml.ws.soap.SOAPBinding; import org.apache.cxf.mime.TestMtom; import org.apache.cxf.mime.TestMtomService; public final class Client {

   private static final QName SERVICE_NAME = new QName("http://cxf.apache.org/mime", "TestMtomService");
   private static final QName PORT_NAME = new QName("http://cxf.apache.org/mime", "TestMtomPort");
   private Client() {
   }
   public static void main(String args[]) throws Exception {
       Client client = new Client();
       if (args.length == 0) {
           System.out.println("please specify wsdl");
           System.exit(1);
       }
       URL wsdlURL;
       File wsdlFile = new File(args[0]);
       if (wsdlFile.exists()) {
           wsdlURL = wsdlFile.toURL();
       } else {
           wsdlURL = new URL(args[0]);
       }
       System.out.println(wsdlURL);
       TestMtomService tms = new TestMtomService(wsdlURL, SERVICE_NAME);
       TestMtom port = (TestMtom) tms.getPort(PORT_NAME, TestMtom.class);
       Binding binding = ((BindingProvider)port).getBinding();
       ((SOAPBinding)binding).setMTOMEnabled(true);
       InputStream pre = client.getClass().getResourceAsStream("me.bmp");
       long fileSize = 0;
       for (int i = pre.read(); i != -1; i = pre.read()) {
           fileSize++;
       }
       Holder<byte[]> param = new Holder<byte[]>();
       param.value = new byte[(int) fileSize];
       System.out.println("Start test without Mtom enable!");
       System.out.println("Sending out the me.bmp Image content to server, data size is " + fileSize);
       InputStream in = client.getClass().getResourceAsStream("me.bmp");
       in.read(param.value);
       Holder<String> name = new Holder<String>("call detail");
       port.testXop(name, param);
       System.out.println("received byte[] back from server, the size is " + param.value.length);
       Image image = ImageIO.read(new ByteArrayInputStream(param.value));
       System.out.println("build image with the returned byte[] back from server successfully, hashCode="
               + image.hashCode());
       System.out.println("Successfully run demo without mtom enable");
       System.out.println("Start test with Mtom enable!");        
       System.out.println("Sending out the me.bmp Image content to server, data size is " + fileSize);
       Holder<DataHandler> handler = new Holder<DataHandler>();
       byte[] data = new byte[(int) fileSize];
       client.getClass().getResourceAsStream("me.bmp").read(data);
       handler.value = new DataHandler(new ByteArrayDataSource(data, "application/octet-stream"));
       port.testMtom(name, handler);
       InputStream mtomIn = handler.value.getInputStream();
       fileSize = 0;
       
       for (int i = mtomIn.read(); i != -1; i = mtomIn.read()) {
           fileSize++;
       }
       System.out.println("received DataHandler back from server, the size is " + fileSize);
       System.out.println("Successfully run demo with mtom enable");
       System.exit(0);
   }
   private static InputStream getResourceStream(File file) throws Exception {
       InputStream in = new FileInputStream(file);
       return in;
   }

}

///////////////////////////////////////////////////////////////////////////// /**

* 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 demo.mtom.server; import javax.xml.ws.Binding; import javax.xml.ws.Endpoint; import javax.xml.ws.soap.SOAPBinding; public class Server {

   protected Server() throws Exception {
       System.out.println("Starting Server");
       Object implementor = new TestMtomImpl();
       String address = "http://localhost:9000/mime-test";
       Endpoint ep = Endpoint.publish(address, implementor);
       Binding binding = ep.getBinding();        
       ((SOAPBinding)binding).setMTOMEnabled(true);        
   }
   public static void main(String args[]) throws Exception {
       new Server();
       System.out.println("Server ready...");
       Thread.sleep(5 * 60 * 1000);
       System.out.println("Server exiting");
       System.exit(0);
   }

}

///////////////////////////////////////////////////////////////////////////// /**

* 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 demo.mtom.server; import java.io.InputStream; import javax.activation.DataHandler; import javax.jws.WebService; import javax.xml.ws.Holder; import org.apache.cxf.mime.TestMtom; @WebService(serviceName = "TestMtomService",

               portName = "TestMtomPort",
               endpointInterface = "org.apache.cxf.mime.TestMtom",
               targetNamespace = "http://cxf.apache.org/mime")

public class TestMtomImpl implements TestMtom {

   public void testXop(Holder<String> name, Holder<byte[]> attachinfo) {
       System.out.println("Received image holder data from client");
       System.out.println("The image holder data length is " + attachinfo.value.length);        
       name.value = "return detail + " + name.value;        
   }
   public void testMtom(Holder<String> name, Holder<DataHandler> attachinfo) {
       try {
           System.out.println("Received image holder data with mtom enable from client");
           InputStream mtomIn = attachinfo.value.getInputStream();
           long fileSize = 0;
           System.out.println("The image holder data length is " + mtomIn.available());
           name.value = "return detail + " + name.value;
       } catch (Exception e) {
           e.printStackTrace();
       }
   }

} ///////////////////////////////////////////////////////////////////////////// <?xml version="1.0" encoding="utf-8"?>

<wsdl:definitions name="SOAPBuilders-mime-cr-test" xmlns:types="http://cxf.apache.org/mime/types"

   xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
   xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://cxf.apache.org/mime"
   xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" 
   xmlns:xmime="http://www.w3.org/2005/05/xmlmime"    
   targetNamespace="http://cxf.apache.org/mime">
   <wsdl:types>
       <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://cxf.apache.org/mime/types"
           xmlns:xmime="http://www.w3.org/2005/05/xmlmime" elementFormDefault="qualified">
           <complexType name="XopType">
               <sequence>
                   <element name="name" type="xsd:string" />
                   <element name="attachinfo" type="xsd:base64Binary"/>
               </sequence>
           </complexType>
           <element name="testXop" type="types:XopType" />
           <element name="testXopResponse" type="types:XopType" />
           
           <complexType name="MtomType">
               <sequence>
                   <element name="name" type="xsd:string" />
                   <element name="attachinfo" type="xsd:base64Binary" xmime:expectedContentTypes="application/octet-stream"/>
               </sequence>
           </complexType>
           <element name="testMtom" type="types:MtomType" />
           <element name="testMtomResponse" type="types:MtomType" />
       </schema>
   </wsdl:types>
   <wsdl:message name="testXopIn">
       <wsdl:part name="data" element="types:testXop" />
   </wsdl:message>
   <wsdl:message name="testXopOut">
       <wsdl:part name="data" element="types:testXopResponse" />
   </wsdl:message>
   <wsdl:message name="testMtomIn">
       <wsdl:part name="data" element="types:testMtom" />
   </wsdl:message>
   <wsdl:message name="testMtomOut">
       <wsdl:part name="data" element="types:testMtomResponse" />
   </wsdl:message>
   <wsdl:portType name="TestMtom">
       <wsdl:operation name="testXop">
           <wsdl:input message="tns:testXopIn" />
           <wsdl:output message="tns:testXopOut" />
       </wsdl:operation>
       <wsdl:operation name="testMtom">
           <wsdl:input message="tns:testMtomIn" />
           <wsdl:output message="tns:testMtomOut" />
       </wsdl:operation>
   </wsdl:portType>
   <wsdl:binding name="TestMtomBinding" type="tns:TestMtom">
       <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
       <wsdl:operation name="testXop">
           <soap:operation soapAction="" />
           <wsdl:input>
               <soap:body use="literal" />
           </wsdl:input>
           <wsdl:output>
               <soap:body use="literal" />
           </wsdl:output>
       </wsdl:operation>
       <wsdl:operation name="testMtom">
           <soap:operation soapAction="" />
           <wsdl:input>
               <soap:body use="literal" />
           </wsdl:input>
           <wsdl:output>
               <soap:body use="literal" />
           </wsdl:output>
       </wsdl:operation>
   </wsdl:binding>
   <wsdl:service name="TestMtomService">
       <wsdl:port name="TestMtomPort" binding="tns:TestMtomBinding">
           <soap:address location="http://localhost:9000/mime-test" />
       </wsdl:port>
   </wsdl:service>

</wsdl:definitions>

       </source>
   
  
 
  



Demonstrates the capabilities and power of SOAP with Attachment support and the Attachment API of AXIS2

   <source lang="java">

Sample: SOAP with Attachments

====================

Introduction

==

This sample demonstrates the capabilities and power of SOAP with Attachment support and the Attachment API of AXIS2. More information about Axis2 attachment implementation can be found at http://ws.apache.org/axis2/1_1/mtom-guide.html. This sample includes a service and a client which can be used to upload a file to the server using SOAP message containing a SOAP with Attachment type binary attachment. The service is written and deployed using the RCPMessageReceiver and a POJO(Plain Old Java Object). The POJO service class uses the Attachment API of the MessageContext to retrieve the received attachment.The client program is written using the OperationClient API of Axis2 together with the Attachment API of MessageContext.

Objectives

==

* Writing a POJO (Plain Old Java Object) based service to access attachments.
* Implement a Axis2 OperationClient based Web Service client to invoke the service with SOAP 
  with Attachment type attachments.
* Invoke the deployed service.

Prerequisites

=

Install Apache Ant 1.6.2 or later

Running the Sample:

=======

The files belonging to this sample are contained in the samples/soapwithattachments folder of the extracted Axis2 binary distribution, which will be called here after as SWA_SAMPLE_DIR. The location of the extracted binary distribution will be refered as AXIS2_DIST. There is a "build.xml" Ant script in the SWA_SAMPLE_DIR that contains build targets for building the service archive and running the client application - all described in steps below. 1. Generate the service Use "ant generate.service" command in the SWA_SAMPLE_DIR to build the service. Generated service will automatically gets copied in to the AXIS2_DIST/repository/services directory. Source file ralating to this service can be found at SWA_SAMPLE_DIR/src/sample/soapwithattachments/service/AttachmentService.java. The services.xml used when building this service can be found at SWA_SAMPLE_DIR/resources directory. 2. Deploy the service Run the AXIS2_DIST/bin/axis2server.{sh.bat} script to start the standalone axis2 server. This server will deploy all the srvices available at AXIS2_DIST/repository/services directory. Alternatively you can drop the sample-swa.aar service archive to the services directory of a running Axis2 servlet) 3. Running the client Use "ant run.client -Dfile <file to be send> -Ddest <destination file name>" command in the SWA_SAMPLE_DIR to build and run the client. Source file ralating to the client can be found at SWA_SAMPLE_DIR/src/sample/soapwithattachments/client/SWAClient.java. Help

==

Please contact axis-user list (axis-user@ws.apache.org) if you have any trouble running the sample.

       </source>
   
  
 
  



Hello World SOAP12 Demo using Document/Literal Style: the use of Apache CXF"s SOAP 1.2 capabilities

   <source lang="java">

Hello World SOAP12 Demo using Document/Literal Style

========================================

This demo shows the use of Apache CXF"s SOAP 1.2 capabilities. Please review the README in the samples directory before continuing.

Prerequisites


If your environment already includes cxf-manifest-incubator.jar on the CLASSPATH, and the JDK and ant bin directories on the PATH it is not necessary to set the environment as described in the samples directory"s README. If your environment is not properly configured, or if you are planning on using wsdl2java, javac, and java to build and run the demos, you must set the environment.

Building and running the demo using ant


From the samples/hello_world directory, the ant build script can be used to build and run the demo. Using either UNIX or Windows:

 ant build
 ant server
 ant client
   

To remove the code generated from the WSDL file and the .class files, run:

 ant clean

Building the demo using wsdl2java and javac


From the samples/hello_world directory, first create the target directory build/classes and then generate code from the WSDL file. For UNIX:

 mkdir -p build/classes
 wsdl2java -d build/classes -compile ./wsdl/hello_world_soap12.wsdl

For Windows:

 mkdir build\classes
   Must use back slashes.
 wsdl2java -d build\classes -compile .\wsdl\hello_world_soap12.wsdl
   May use either forward or back slashes.

Now compile the provided client and server applications with the commands: For UNIX:

 export CLASSPATH=$CLASSPATH:$CXF_HOME/lib/cxf-manifest-incubator.jar:./build/classes
 javac -d build/classes src/demo/hw/client/*.java
 javac -d build/classes src/demo/hw/server/*.java

For Windows:

 set classpath=%classpath%;%CXF_HOME%\lib\cxf-manifest-incubator.jar;.\build\classes
 javac -d build\classes src\demo\hw\client\*.java
 javac -d build\classes src\demo\hw\server\*.java

Running the demo using java


From the samples/hello_world directory run the following commands. They are entered on a single command line: For UNIX (must use forward slashes):

   java -Djava.util.logging.config.file=$CXF_HOME/etc/logging.properties
        demo.hw.server.Server &
   java -Djava.util.logging.config.file=$CXF_HOME/etc/logging.properties
        demo.hw.client.Client ./wsdl/hello_world_soap12.wsdl

The server process starts in the background. After running the client, use the kill command to terminate the server process. For Windows (may use either forward or back slashes):

 start 
   java -Djava.util.logging.config.file=%CXF_HOME%\etc\logging.properties
        demo.hw.server.Server
   java -Djava.util.logging.config.file=%CXF_HOME%\etc\logging.properties
      demo.hw.client.Client .\wsdl\hello_world_soap12.wsdl

A new command windows opens for the server process. After running the client, terminate the server process by issuing Ctrl-C in its command window. To remove the code generated from the WSDL file and the .class files, either delete the build directory and its contents or run:

 ant clean

Building and running the demo in a servlet container


From the samples/hello_world directory, the ant build script can be used to create the war file that is deployed into the servlet container. Build the war file with the command:

 ant war
   

Preparing deploy to APACHE TOMCAT

  • set CATALINA_HOME environment to your TOMCAT home directory

Deploy the application into APACHE TOMCAT with the commond: [NOTE] This step will check if the cxf jars present in Tomcat,

      if not, it will automatically copy all the jars into CATALINA_HOME/shared/lib
 
 ant deploy -Dtomcat=true

The servlet container will extract the war and deploy the application.

Using ant, run the client application with the command:

 ant client-servlet -Dbase.url=http://localhost:#

Where # is the TCP/IP port used by the servlet container, e.g., 8080. Or

 ant client-servlet -Dhost=localhost -Dport=8080

You can ignore the -Dhost and -Dport if your tomcat setup is same, i.e ant client-servlet Using java, run the client application with the command:

 For UNIX:
   
   java -Djava.util.logging.config.file=$CXF_HOME/etc/logging.properties
        demo.hw.client.Client http://localhost:#/helloworld/services/hello_world_soap12?wsdl
 For Windows:
   java -Djava.util.logging.config.file=%CXF_HOME%\etc\logging.properties
      demo.hw.client.Client http://localhost:#/helloworld/services/hello_world_soap12?wsdl

Where # is the TCP/IP port used by the servlet container, e.g., 8080. Undeploy the application from the APACHE TOMCAT with the command:

  ant undeploy -Dtomcat=true

Running demo with HTTP GET


APACHE CXF support HTTP GET to invoke the service, instead of running

  ant client

you can use

  ant client.get 

to invoke the service with simple HttpURLConnection, or you can even use your favorite browser to get the results back.

////////////////////////////////////////////////////////////////////////////

/**

* 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 demo.hw.client; import java.io.File; import java.net.URL; import javax.xml.namespace.QName; import javax.xml.ws.ProtocolException; import org.apache.hello_world_soap12_http.Greeter; import org.apache.hello_world_soap12_http.PingMeFault; import org.apache.hello_world_soap12_http.SOAPService; import org.apache.hello_world_soap12_http.types.FaultDetail; public final class Client {

   private static final QName SERVICE_NAME 
       = new QName("http://apache.org/hello_world_soap12_http", "SOAPService");
   private Client() {
   } 
   public static void main(String args[]) throws Exception {
       
       if (args.length == 0) { 
           System.out.println("please specify wsdl");
           System.exit(1); 
       }
       URL wsdlURL;
       File wsdlFile = new File(args[0]);
       if (wsdlFile.exists()) {
           wsdlURL = wsdlFile.toURL();
       } else {
           wsdlURL = new URL(args[0]);
       }
       
       System.out.println(wsdlURL);
       SOAPService ss = new SOAPService(wsdlURL, SERVICE_NAME);
       Greeter port = ss.getSoapPort();
       String resp; 
       System.out.println("Invoking sayHi...");
       resp = port.sayHi();
       System.out.println("Server responded with: " + resp);
       System.out.println();
       System.out.println("Invoking greetMe...");
       resp = port.greetMe(System.getProperty("user.name"));
       System.out.println("Server responded with: " + resp);
       System.out.println();
       System.out.println("Invoking greetMe with invalid length string, expecting exception...");
       try {
           resp = port.greetMe("Invoking greetMe with invalid length string, expecting exception...");
       } catch (ProtocolException e) {
           System.out.println("Expected exception has occurred: " + e.getClass().getName());
       }
       System.out.println();
       System.out.println("Invoking greetMeOneWay...");
       port.greetMeOneWay(System.getProperty("user.name"));
       System.out.println("No response from server as method is OneWay");
       System.out.println();
       try {
           System.out.println("Invoking pingMe, expecting exception...");
           port.pingMe();
       } catch (PingMeFault ex) {
           System.out.println("Expected exception: PingMeFault has occurred: " + ex.getMessage());
           FaultDetail detail = ex.getFaultInfo();
           System.out.println("FaultDetail major:" + detail.getMajor());
           System.out.println("FaultDetail minor:" + detail.getMinor());            
       }          
       System.exit(0); 
   }

}

///////////////////////////////////////////////////////////////////////////// /**

* 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 demo.hw.client; import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; import java.util.Properties; import javax.xml.transform.OutputKeys; import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; public final class Get {

   private Get() {
   } 
   public static void main(String args[]) throws Exception {
       // Sent HTTP GET request to invoke sayHi
       String target = "http://localhost:9000/SoapContext/SoapPort/sayHi";
       URL url = new URL(target);
       HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection();
       httpConnection.connect();
       System.out.println("Invoking server through HTTP GET to invoke sayHi");
       InputStream in = httpConnection.getInputStream();
       StreamSource source = new StreamSource(in);
       printSource(source);
       // Sent HTTP GET request to invoke greetMe FAULT
       target = "http://localhost:9000/SoapContext/SoapPort/greetMe/me/CXF";
       url = new URL(target);
       httpConnection = (HttpURLConnection) url.openConnection();
       httpConnection.connect();
       System.out.println("Invoking server through HTTP GET to invoke greetMe");
       try {
           in = httpConnection.getInputStream();
           source = new StreamSource(in);
           printSource(source);
       } catch (Exception e) {
           System.err.println("GreetMe Fault: " + e.getMessage());
       }
       InputStream err = httpConnection.getErrorStream();
       source = new StreamSource(err);
       printSource(source);
       // Sent HTTP GET request to invoke greetMe
       target = "http://localhost:9000/SoapContext/SoapPort/greetMe/requestType/CXF";
       url = new URL(target);
       httpConnection = (HttpURLConnection) url.openConnection();
       httpConnection.connect();
       System.out.println("Invoking server through HTTP GET to invoke greetMe");
       in = httpConnection.getInputStream();
       source = new StreamSource(in);
       printSource(source);
       // Sent HTTP GET request to invoke pingMe
       target = "http://localhost:9000/SoapContext/SoapPort/pingMe";
       url = new URL(target);
       httpConnection = (HttpURLConnection) url.openConnection();
       httpConnection.connect();
       System.out.println("Invoking server through HTTP GET to invoke pingMe");
       try {
           in = httpConnection.getInputStream();
       } catch (Exception e) {
           System.out.println("PingMe fault raised");
       }
       err = httpConnection.getErrorStream();
       source = new StreamSource(err);
       printSource(source);
   }
   private static void printSource(Source source) {
       try {
           ByteArrayOutputStream bos = new ByteArrayOutputStream();
           StreamResult sr = new StreamResult(bos);
           Transformer trans = TransformerFactory.newInstance().newTransformer();
           Properties oprops = new Properties();
           oprops.put(OutputKeys.OMIT_XML_DECLARATION, "yes");
           trans.setOutputProperties(oprops);
           trans.transform(source, sr);
           System.out.println();
           System.out.println("**** Response ******");
           System.out.println();
           System.out.println(bos.toString());
           bos.close();
           System.out.println();
       } catch (Exception e) {
           e.printStackTrace();
       }
   }    

} ///////////////////////////////////////////////////////////////////////////// /**

* 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 demo.hw.server; import java.util.logging.Logger; import org.apache.hello_world_soap12_http.Greeter; import org.apache.hello_world_soap12_http.PingMeFault; import org.apache.hello_world_soap12_http.types.FaultDetail; @javax.jws.WebService(portName = "SoapPort", serviceName = "SOAPService",

                     targetNamespace = "http://apache.org/hello_world_soap12_http", 
                     endpointInterface = "org.apache.hello_world_soap12_http.Greeter")

@javax.xml.ws.BindingType(value = "http://www.w3.org/2003/05/soap/bindings/HTTP/") public class GreeterImpl implements Greeter {

   private static final Logger LOG = 
       Logger.getLogger(GreeterImpl.class.getPackage().getName());
   
   public String greetMe(String me) {
       LOG.info("Executing operation greetMe");
       System.out.println("Executing operation greetMe");
       System.out.println("Message received: " + me + "\n");
       return "Hello " + me;
   }
   
   public void greetMeOneWay(String me) {
       LOG.info("Executing operation greetMeOneWay");
       System.out.println("Executing operation greetMeOneWay\n");
       System.out.println("Hello there " + me);
   }
   public String sayHi() {
       LOG.info("Executing operation sayHi");
       System.out.println("Executing operation sayHi\n");
       return "Bonjour";
   }
   
   public void pingMe() throws PingMeFault {
       FaultDetail faultDetail = new FaultDetail();
       faultDetail.setMajor((short)2);
       faultDetail.setMinor((short)1);
       LOG.info("Executing operation pingMe, throwing PingMeFault exception");
       System.out.println("Executing operation pingMe, throwing PingMeFault exception\n");
       throw new PingMeFault("PingMeFault raised by server", faultDetail);
   }
   

} ///////////////////////////////////////////////////////////////////////////// /**

* 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 demo.hw.server; import javax.xml.ws.Endpoint; public class Server {

   protected Server() throws Exception {
       System.out.println("Starting Server");
       Object implementor = new GreeterImpl();
       String address = "http://localhost:9000/SoapContext/SoapPort";
       Endpoint.publish(address, implementor);
   }
   public static void main(String args[]) throws Exception {
       new Server();
       System.out.println("Server ready...");
       Thread.sleep(5 * 60 * 1000);
       System.out.println("Server exiting");
       System.exit(0);
   }

}

//////////////////////////////////////////////////////////////////////////////// <?xml version="1.0" encoding="UTF-8"?>

<definitions name="HelloWorld"

      xmlns="http://schemas.xmlsoap.org/wsdl/"
      xmlns:tns="http://apache.org/hello_world_soap12_http"
      xmlns:x1="http://apache.org/hello_world_soap12_http/types"
      xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
      xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      targetNamespace="http://apache.org/hello_world_soap12_http"
      xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/">
   <wsdl:types>
 <schema targetNamespace="http://apache.org/hello_world_soap12_http/types" 
   xmlns="http://www.w3.org/2001/XMLSchema" 
   xmlns:x1="http://apache.org/hello_world_soap12_http/types" 
   elementFormDefault="qualified">
     <simpleType name="MyStringType">
   <restriction base="string">
       <maxLength value="30" />
   </restriction>
     </simpleType>
     <element name="sayHi">
   <complexType/>
     </element>
     <element name="sayHiResponse">
   <complexType>
       <sequence>
     <element name="responseType" type="string"/>
       </sequence>
   </complexType>
     </element>
           <element name="greetMe">
               <complexType>
                   <sequence>
                       <element name="requestType" type="x1:MyStringType"/>
                   </sequence>
               </complexType>
           </element>
           <element name="greetMeResponse">
               <complexType>
                   <sequence>
                       <element name="responseType" type="string"/>
                   </sequence>
               </complexType>
           </element>
           <element name="greetMeOneWay">
               <complexType>
                   <sequence>
                       <element name="requestType" type="string"/>
                   </sequence>
               </complexType>
           </element>
     <element name="pingMe">
   <complexType/>
     </element>
     <element name="pingMeResponse">
   <complexType/>
     </element>
     <element name="faultDetail">
   <complexType>
       <sequence>
     <element name="minor" type="short"/>
     <element name="major" type="short"/>
       </sequence>
               </complexType>
     </element>
       </schema>
   </wsdl:types>
   <wsdl:message name="sayHiRequest">
       <wsdl:part name="in" element="x1:sayHi"/>
   </wsdl:message>
   <wsdl:message name="sayHiResponse">
       <wsdl:part name="out" element="x1:sayHiResponse"/>
   </wsdl:message>
   <wsdl:message name="greetMeRequest">
       <wsdl:part element="x1:greetMe" name="in"/>
   </wsdl:message>
   <wsdl:message name="greetMeResponse">
       <wsdl:part element="x1:greetMeResponse" name="out"/>
   </wsdl:message>
   <wsdl:message name="greetMeOneWayRequest">
       <wsdl:part element="x1:greetMeOneWay" name="in"/>
   </wsdl:message>
   <wsdl:message name="pingMeRequest">
 <wsdl:part name="in" element="x1:pingMe"/>
   </wsdl:message>
   <wsdl:message name="pingMeResponse">
       <wsdl:part name="out" element="x1:pingMeResponse"/>
   </wsdl:message>    
   <wsdl:message name="pingMeFault">
 <wsdl:part name="faultDetail" element="x1:faultDetail"/>
   </wsdl:message>
   <wsdl:portType name="Greeter">
       <wsdl:operation name="sayHi">
           <wsdl:input name="sayHiRequest" message="tns:sayHiRequest"/>
           <wsdl:output name="sayHiResponse" message="tns:sayHiResponse"/>
       </wsdl:operation>
       <wsdl:operation name="greetMe">
           <wsdl:input message="tns:greetMeRequest" name="greetMeRequest"/>
           <wsdl:output message="tns:greetMeResponse" name="greetMeResponse"/>
       </wsdl:operation>
       
       <wsdl:operation name="greetMeOneWay">
           <wsdl:input message="tns:greetMeOneWayRequest" name="greetMeOneWayRequest"/>
       </wsdl:operation>
 <wsdl:operation name="pingMe">
     <wsdl:input name="pingMeRequest" message="tns:pingMeRequest"/>
     <wsdl:output name="pingMeResponse" message="tns:pingMeResponse"/>
     <wsdl:fault name="pingMeFault" message="tns:pingMeFault"/>
       </wsdl:operation> 
   </wsdl:portType>
   <wsdl:binding name="Greeter_SOAPBinding" type="tns:Greeter">
 <soap12:binding transport="http://www.w3.org/2003/05/soap/bindings/HTTP/" style="document" />
 <operation name="sayHi">
     <soap12:operation style="document" soapAction=""/>
     <input>
   <soap12:body use="literal" />
     </input>
     <output>
   <soap12:body use="literal" />
     </output>
 </operation>
       <wsdl:operation name="greetMe">
           <soap12:operation soapAction="" style="document"/>
           <wsdl:input name="greetMeRequest">
               <soap12:body use="literal"/>
           </wsdl:input>
           <wsdl:output name="greetMeResponse">
               <soap12:body use="literal"/>
           </wsdl:output>
       </wsdl:operation>
       
       <wsdl:operation name="greetMeOneWay">
           <soap12:operation soapAction="" style="document"/>
           <wsdl:input name="greetMeOneWayRequest">
               <soap12:body use="literal"/>
           </wsdl:input>
       </wsdl:operation>
 <operation name="pingMe">
     <soap12:operation style="document"/>
     <input>
               <soap12:body use="literal"/>
           </input>
           <output>
               <soap12:body use="literal"/>
           </output>
           <fault name="pingMeFault">
               <soap12:fault name="pingMeFault" use="literal"/>
           </fault>
       </operation>
   </wsdl:binding>
   <wsdl:service name="SOAPService">
       <wsdl:port name="SoapPort" binding="tns:Greeter_SOAPBinding">
           <soap12:address location="http://localhost:9000/SoapContext/SoapPort"/>
       </wsdl:port>
   </wsdl:service>

</definitions>


       </source>
   
  
 
  



JAX-WS: SOAP Element

JAX-WS: SOAP Element Any Type

This demo illustrates Apache CXF"s support for SOAP headers

   <source lang="java">

SOAP Headers

==

This demo illustrates Apache CXF"s support for SOAP headers. In the WSDL file, the SOAP header is included as an additional part within the message and binding definitions. Using this approach to defining a SOAP header, Apache CXF treats the header content as another parameter to the operation. Consequently, the header content is simply manipulated within the method body. The client application creates the header content, which is simply a string value. The server application views the supplied values and may set these values into the operation"s return values or out/inout headers. Please review the README in the samples directory before continuing.

Prerequisites


If your environment already includes cxf.jar on the CLASSPATH, and the JDK and ant bin directories on the PATH it is not necessary to set the environment as described in the samples directory"s README. If your environment is not properly configured, or if you are planning on using wsdl2java, javac, and java to build and run the demos, you must set the environment.

Building and running the demo using ant


From the samples/soap_header directory, the ant build script can be used to build and run the demo. Using either UNIX or Windows:

 ant build
 ant server 
 ant client
   

To remove the code generated from the WSDL file and the .class files, run:

 ant clean

Building the demo using wsdl2java and javac


From the samples/soap_header directory, first create the target directory build/classes and then generate code from the WSDL file. For UNIX:

 mkdir -p build/classes
 wsdl2java -d build/classes -compile ./wsdl/soap_header.wsdl

For Windows:

 mkdir build\classes
   Must use back slashes.
 wsdl2java -d build\classes -compile .\wsdl\soap_header.wsdl
   May use either forward or back slashes.

Now compile the provided client and server applications with the commands: For UNIX:

 export CLASSPATH=$CLASSPATH:$CXF_HOME/lib/cxf.jar:./build/classes
 javac -d build/classes src/demo/soap_header/client/*.java
 javac -d build/classes src/demo/soap_header/server/*.java

For Windows:

 set classpath=%classpath%;%CXF_HOME%\lib\cxf.jar;.\build\classes
 javac -d build\classes src\demo\soap_header\client\*.java
 javac -d build\classes src\demo\soap_header\server\*.java

Running the demo using java


From the samples/soap_header directory run the following commands. They are entered on a single command line: For UNIX (must use forward slashes):

   java -Djava.util.logging.config.file=$CXF_HOME/etc/logging.properties
        demo.soap_header.server.Server &
   java -Djava.util.logging.config.file=$CXF_HOME/etc/logging.properties
        demo.soap_header.client.Client ./wsdl/soap_header.wsdl

The server process starts in the background. After running the client, use the kill command to terminate the server process. For Windows (may use either forward or back slashes):

 start 
   java -Djava.util.logging.config.file=%CXF_HOME%\etc\logging.properties
        demo.soap_header.server.Server
   java -Djava.util.logging.config.file=%CXF_HOME%\etc\logging.properties
      demo.soap_header.client.Client .\wsdl\soap_header.wsdl

A new command windows opens for the server process. After running the client, terminate the server process by issuing Ctrl-C in its command window. To remove the code generated from the WSDL file and the .class files, either delete the build directory and its contents or run:

 ant clean

Building and running the demo in a servlet container


From the samples/soap_header directory, the ant build script can be used to create the war file that is deployed into the servlet container. Build the war file with the command:

 ant war

Preparing deploy to APACHE TOMCAT

  • set CATALINA_HOME environment to your TOMCAT home directory

Deploy the war file into APACHE TOMCAT with the commond: [NOTE] This step will check if the cxf jars present in Tomcat,

      if not, it will automatically copy all the jars into CATALINA_HOME/shared/lib
 
 ant deploy -Dtomcat=true

The servlet container will extract the war and deploy the application.

Using ant, run the client application with the command:

 ant client-servlet -Dbase.url=http://localhost:#

Where # is the TCP/IP port used by the servlet container, e.g., 8080. Or

 ant client-servlet -Dhost=localhost -Dport=8080

You can ignore the -Dhost and -Dport if your tomcat setup is same, i.e ant client-servlet Using java, run the client application with the command:

 For UNIX:
   
   java -Djava.util.logging.config.file=$CXF_HOME/etc/logging.properties
        demo.soap_header.client.Client http://localhost:#/soapheader/services/soap_header?wsdl
 For Windows:
   java -Djava.util.logging.config.file=%CXF_HOME%\etc\logging.properties
      demo.soap_header.client.Client http://localhost:#/soapheader/services/soap_header?wsdl

Where # is the TCP/IP port used by the servlet container, e.g., 8080. Undeploy the application from the APACHE TOMCAT with the command:

  ant undeploy -Dtomcat=true

///////////////////////////////////////////////////////////////////////// /**

* 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 demo.soap_header.client; import java.io.File; import java.net.URL; import javax.xml.namespace.QName; import javax.xml.ws.Holder; import org.apache.headers.HeaderService; import org.apache.headers.HeaderTester; import org.apache.headers.InHeader; import org.apache.headers.InHeaderResponse; import org.apache.headers.InoutHeader; import org.apache.headers.InoutHeaderResponse; import org.apache.headers.OutHeader; import org.apache.headers.OutHeaderResponse; import org.apache.headers.SOAPHeaderData; public final class Client {

   private static final QName SERVICE_NAME
       = new QName("http://apache.org/headers", "HeaderService");
   private Client() {
   }
   public static void main(String args[]) throws Exception {
       if (args.length == 0) {
           System.out.println("please specify wsdl");
           System.exit(1);
       }
       URL wsdlURL;
       File wsdlFile = new File(args[0]);
       if (wsdlFile.exists()) {
           wsdlURL = wsdlFile.toURL();
       } else {
           wsdlURL = new URL(args[0]);
       }
       
       HeaderService hs = new HeaderService(wsdlURL, SERVICE_NAME);
       HeaderTester proxy = hs.getSoapPort();
       invokeInHeader(proxy);
       invokeOutHeader(proxy);  
       invokeInOutHeader(proxy);  
   }
    
   private static void invokeInHeader(HeaderTester proxy) {
       // invoke inHeader operation
       System.out.println("Invoking inHeader operation");
       InHeader me = new InHeader();
       me.setRequestType("CXF user");
       SOAPHeaderData headerInfo = new SOAPHeaderData();
       headerInfo.setOriginator("CXF client");
       headerInfo.setMessage("Invoking inHeader operation");
       InHeaderResponse response = proxy.inHeader(me, headerInfo);
       System.out.println("\tinHeader invocation returned: ");
       System.out.println("\t\tResult: " + response.getResponseType());
   }
   private static void invokeOutHeader(HeaderTester proxy) {    
       // invoke outHeaderoperation
       System.out.println("Invoking outHeader operation");
       OutHeader me = new OutHeader();
       me.setRequestType("CXF user");
       Holder<OutHeaderResponse> theResponse = new Holder<OutHeaderResponse>();
       Holder<SOAPHeaderData> headerInfo = new Holder<SOAPHeaderData>();
       proxy.outHeader(me, theResponse, headerInfo);
       System.out.println("\toutHeader invocation returned: ");
       System.out.println("\t\tOut parameter: " + theResponse.value.getResponseType());
       System.out.println("\t\tHeader content:");
       System.out.println("\t\t\tOriginator: " + headerInfo.value.getOriginator());
       System.out.println("\t\t\tMessage: " + headerInfo.value.getMessage());
   }
   private static void invokeInOutHeader(HeaderTester proxy) {
       System.out.println("Invoking inoutHeader operation");
       InoutHeader me = new InoutHeader();
       me.setRequestType("CXF user");
       Holder<SOAPHeaderData> headerInfo = new Holder<SOAPHeaderData>();
       SOAPHeaderData shd = new SOAPHeaderData();
       shd.setOriginator("CXF client");
       shd.setMessage("Invoking inoutHeader operation");
       headerInfo.value = shd;
       InoutHeaderResponse response = proxy.inoutHeader(me, headerInfo);
       System.out.println("\tinoutHeader invocation returned: ");
       System.out.println("\t\tResult: " + response.getResponseType());
       System.out.println("\t\tHeader content:");
       System.out.println("\t\t\tOriginator: " + headerInfo.value.getOriginator());
       System.out.println("\t\t\tMessage: " + headerInfo.value.getMessage());
       System.exit(0);
   }

}

////////////////////////////////////////////////////////////////////////////// /**

* 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 demo.soap_header.server; import javax.xml.ws.Holder; import org.apache.headers.HeaderTester; import org.apache.headers.InHeader; import org.apache.headers.InHeaderResponse; import org.apache.headers.InoutHeader; import org.apache.headers.InoutHeaderResponse; import org.apache.headers.OutHeader; import org.apache.headers.OutHeaderResponse; import org.apache.headers.SOAPHeaderData;

@javax.jws.WebService(serviceName = "HeaderService",

           portName = "SoapPort", 
           endpointInterface = "org.apache.headers.HeaderTester",
           targetNamespace = "http://apache.org/headers")

public class HeaderTesterImpl implements HeaderTester {

   public InHeaderResponse inHeader(InHeader me,
                                    SOAPHeaderData headerInfo) {
       System.out.println("inHeader invoked");
       System.out.println("\tGetting Originator: " + headerInfo.getOriginator());
       System.out.println("\tGetting Message: " + headerInfo.getMessage());
       InHeaderResponse ihr = new InHeaderResponse();
       ihr.setResponseType("Hello " + me.getRequestType());
       return ihr;
   }
   public void outHeader(OutHeader me, 
                         Holder<OutHeaderResponse> theResponse,
                         Holder<SOAPHeaderData> headerInfo) {
       System.out.println("outHeader invoked");
       System.out.println("\tSetting originator: CXF server");
       System.out.println("\tSetting message: outHeader invocation succeeded");
       SOAPHeaderData sh = new SOAPHeaderData();
       sh.setOriginator("CXF server");
       sh.setMessage("outHeader invocation succeeded");
       headerInfo.value = sh;
       OutHeaderResponse ohr = new OutHeaderResponse();
       ohr.setResponseType("Hello " + me.getRequestType());
       theResponse.value = ohr;
   }
   public InoutHeaderResponse inoutHeader(InoutHeader me,
                                          Holder<SOAPHeaderData> headerInfo) {
       System.out.println("inoutHeader invoked");
       System.out.println("\tGetting Originator: " + headerInfo.value.getOriginator());
       System.out.println("\tGetting Message: " + headerInfo.value.getMessage());
       System.out.println("\tSetting originator: CXF server");
       System.out.println("\tSetting message: inoutHeader invocation succeeded");
       headerInfo.value.setOriginator("CXF server");
       headerInfo.value.setMessage("inoutHeader invocation succeeded");
       InoutHeaderResponse iohr = new InoutHeaderResponse();
       iohr.setResponseType("Hello " + me.getRequestType());
       return iohr;
   }    

}

////////////////////////////////////////////////////////////////////////////// /**

* 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 demo.soap_header.server; import javax.xml.ws.Endpoint; public class Server {

   protected Server() throws Exception {
       System.out.println("Starting Server");
       Object implementor = new HeaderTesterImpl();
       String address = "http://localhost:9000/headers";
       Endpoint.publish(address, implementor);
   }
   public static void main(String args[]) throws Exception {
       new Server();
       System.out.println("Server ready...");
       Thread.sleep(5 * 60 * 1000);
       System.out.println("Server exiting");
       System.exit(0);
   }

}

////////////////////////////////////////////////////////////////////////////// <?xml version="1.0" encoding="UTF-8"?>

<definitions name="soap_header" targetNamespace="http://apache.org/headers"

   xmlns="http://schemas.xmlsoap.org/wsdl/" 
   xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" 
   xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
   xmlns:tns="http://apache.org/headers" 
   xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
   xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <types>
       <schema targetNamespace="http://apache.org/headers" 
           xmlns="http://www.w3.org/2001/XMLSchema" 
           xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
           <complexType name="SOAPHeaderData">
               <sequence>
                   <element maxOccurs="1" minOccurs="1" name="originator" type="string"/>
                   <element maxOccurs="1" minOccurs="1" name="message" type="string"/>
               </sequence>
           </complexType>
           <element name="SOAPHeaderInfo" type="tns:SOAPHeaderData"/>
       <element name="inHeader">
          <complexType>
                   <sequence>
                       <element name="requestType" type="xsd:string"/>
                   </sequence>
               </complexType>
       </element>
       <element name="inHeaderResponse">
          <complexType>
                   <sequence>
                       <element name="responseType" type="xsd:string"/>
                   </sequence>
               </complexType>
       </element>
       <element name="outHeader">
          <complexType>
                   <sequence>
                       <element name="requestType" type="xsd:string"/>
                   </sequence>
               </complexType>
       </element>
       <element name="outHeaderResponse">
          <complexType>
                   <sequence>
                       <element name="responseType" type="xsd:string"/>
                   </sequence>
               </complexType>
       </element>
       <element name="inoutHeader">
          <complexType>
                   <sequence>
                       <element name="requestType" type="xsd:string"/>
                   </sequence>
               </complexType>
       </element>
       <element name="inoutHeaderResponse">
          <complexType>
                   <sequence>
                       <element name="responseType" type="xsd:string"/>
                   </sequence>
               </complexType>
       </element>
       </schema>
   </types>
   <message name="inHeaderRequest">
       <part element="tns:inHeader" name="me"/>
       <part element="tns:SOAPHeaderInfo" name="header_info"/>
   </message>
   <message name="inHeaderResponse">
       <part element="tns:inHeaderResponse" name="the_response"/>
   </message>
   <message name="outHeaderRequest">
       <part element="tns:outHeader" name="me"/>
   </message>
   <message name="outHeaderResponse">
       <part element="tns:outHeaderResponse" name="the_response"/>
       <part element="tns:SOAPHeaderInfo" name="header_info"/>
   </message>
   <message name="inoutHeaderRequest">
       <part element="tns:inoutHeader" name="me"/>
       <part element="tns:SOAPHeaderInfo" name="header_info"/>
   </message>
   <message name="inoutHeaderResponse">
       <part element="tns:inoutHeaderResponse" name="the_response"/>
       <part element="tns:SOAPHeaderInfo" name="header_info"/>
   </message>
   <portType name="headerTester">
       <operation name="inHeader">
           <input message="tns:inHeaderRequest" name="inHeaderRequest"/>
           <output message="tns:inHeaderResponse" name="inHeaderResponse"/>
       </operation>
       <operation name="outHeader">
           <input message="tns:outHeaderRequest" name="outHeaderRequest"/>
           <output message="tns:outHeaderResponse" name="outHeaderResponse"/>
       </operation>
       <operation name="inoutHeader">
           <input message="tns:inoutHeaderRequest" name="inoutHeaderRequest"/>
           <output message="tns:inoutHeaderResponse" name="inoutHeaderResponse"/>
       </operation>
   </portType>
   <binding name="headerTesterSOAPBinding" type="tns:headerTester">
       <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
       <operation name="inHeader">
           <soap:operation soapAction="" style="document"/>
           <input name="inHeaderRequest">
               <soap:body parts="me" use="literal"/>
               <soap:header message="tns:inHeaderRequest" part="header_info" 
                   use="literal"/>
           </input>
           <output name="inHeaderResponse">
               <soap:body use="literal"/>
           </output>
       </operation>
       <operation name="outHeader">
           <soap:operation soapAction="" style="document"/>
           <input name="outHeaderRequest">
               <soap:body use="literal"/>
           </input>
           <output name="outHeaderResponse">
               <soap:body parts="the_response" use="literal"/>
               <soap:header message="tns:outHeaderResponse" part="header_info" 
                   use="literal"/>
           </output>
       </operation>
       <operation name="inoutHeader">
           <soap:operation soapAction="" style="document"/>
           <input name="inoutHeaderRequest">
               <soap:body parts="me" use="literal"/>
               <soap:header message="tns:inoutHeaderRequest" part="header_info" 
                   use="literal"/>
           </input>
           <output name="inoutHeaderResponse">
               <soap:body parts="the_response" use="literal"/>
               <soap:header message="tns:inoutHeaderResponse" part="header_info" 
                   use="literal"/>
           </output>
       </operation>
   </binding>
   <service name="HeaderService">
       <port binding="tns:headerTesterSOAPBinding" name="SoapPort">
           <soap:address location="http://localhost:9000/headers"/>
       </port>
   </service>

</definitions>

       </source>