Java/Web Services SOA/CXF XFire
Содержание
- 1 MTOSI 1.1 Samples
- 2 This demo illustrates the use of the JAX-WS APIs to run a simple client against a standalone server using SOAP 1.1 over HTTP
- 3 This demo illustrates the use of the JAX-WS asynchronous invocation model
- 4 This demo shows a client creating a callback object by passing an EndpointReferenceType to the server
- 5 This demo shows how JAX-WS handlers are used
- 6 This demo shows how to develope an user interceptor and add the interceptor into the interceptor chain through configuration
MTOSI 1.1 Samples
MTOSI 1.1 Samples
=================
mtosi_1.1 contains the following subdirectories:
wsdl - contains the mtosi 1.1 wsdls
xsd - contains the mtosi 1.1 schemas
alarm_retrieval - contains a simple sample implementation of the
alarm_retrieval mtosi interface. Please refer to
the alarm_retrieval/README.txt for instructions to
run that demo.
code_gen - contains targets for generating code for mtosi
interfaces which do not have a sample implementation
Going beyond the basic sample
=============================
You can use the alarm_retrieval demo as a template for implementing
any of the other mtosi interfaces. The code_gen directory
demonstrates the wsdl2java targets needed to generate code for the
remaining mtosi interfaces.
This demo illustrates the use of the JAX-WS APIs to run a simple client against a standalone server using SOAP 1.1 over HTTP
Hello World Demo using Document/Literal Style
=============================================
This demo illustrates the use of the JAX-WS APIs to run a simple
client against a standalone server using SOAP 1.1 over HTTP.
It also shows how CXF configuration can be used to enable schema validation
on the client and/or server side: By default the message parameters would not
be validated, but the presence of the cxf.xml configuration file on
the classpath, and its content change this default behavior:
The configuration file specifies that
a) if a JAX-WS client proxy is created for port {http://apache.org/hello_world_soap_http}SoapPort
it should have schema validation enabled.
b) if a JAX-WS server endpoint is created for port {http://apache.org/hello_world_soap_http}SoapPort
it should have schema validation enabled.
The client"s second greetMe invocation causes an exception (a marshalling
error) on the client side, i.e. before the request with the invalid parameter
goes on the wire.
After commenting the definition of the <jaxws:client> element in cxf.xml you
will notice that the client"s second greetMe invocation still throws an exception,
but that this time the exception is caused by an unmarshalling error on the
server side.
Commenting both elements, or renaming/removing the cfg.xml file, and thus
restoring the default behavior, results in the second greetMe invocation
not causing an exception.
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 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.wsdl
For Windows:
mkdir build\classes
Must use back slashes.
wsdl2java -d build\classes -compile .\wsdl\hello_world.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 commands, 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.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.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?wsdl
For Windows:
java -Djava.util.logging.config.file=%CXF_HOME%\etc\logging.properties
demo.hw.client.Client http://localhost:#/helloworld/services/hello_world?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 favoriate 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.WebServiceException;
import org.apache.hello_world_soap_http.Greeter;
import org.apache.hello_world_soap_http.PingMeFault;
import org.apache.hello_world_soap_http.SOAPService;
import org.apache.hello_world_soap_http.types.FaultDetail;
public final class Client {
private static final QName SERVICE_NAME
= new QName("http://apache.org/hello_world_soap_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 (WebServiceException ex) {
System.out.println("Caught expected WebServiceException:");
System.out.println(" " + ex.getMessage());
}
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_soap_http.Greeter;
import org.apache.hello_world_soap_http.PingMeFault;
import org.apache.hello_world_soap_http.types.FaultDetail;
@javax.jws.WebService(portName = "SoapPort", serviceName = "SOAPService",
targetNamespace = "http://apache.org/hello_world_soap_http",
endpointInterface = "org.apache.hello_world_soap_http.Greeter")
public class GreeterImpl implements Greeter {
private static final Logger LOG =
Logger.getLogger(GreeterImpl.class.getPackage().getName());
/* (non-Javadoc)
* @see org.apache.hello_world_soap_http.Greeter#greetMe(java.lang.String)
*/
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;
}
/* (non-Javadoc)
* @see org.apache.hello_world_soap_http.Greeter#greetMeOneWay(java.lang.String)
*/
public void greetMeOneWay(String me) {
LOG.info("Executing operation greetMeOneWay");
System.out.println("Executing operation greetMeOneWay\n");
System.out.println("Hello there " + me);
}
/* (non-Javadoc)
* @see org.apache.hello_world_soap_http.Greeter#sayHi()
*/
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"?>
<!--
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.
-->
<wsdl:definitions name="HelloWorld" targetNamespace="http://apache.org/hello_world_soap_http"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://apache.org/hello_world_soap_http"
xmlns:x1="http://apache.org/hello_world_soap_http/types"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<schema targetNamespace="http://apache.org/hello_world_soap_http/types"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://apache.org/hello_world_soap_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="tns: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 element="x1:sayHi" name="in"/>
</wsdl:message>
<wsdl:message name="sayHiResponse">
<wsdl:part element="x1:sayHiResponse" name="out"/>
</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 message="tns:sayHiRequest" name="sayHiRequest"/>
<wsdl:output message="tns:sayHiResponse" name="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">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="sayHi">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="sayHiRequest">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="sayHiResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="greetMe">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="greetMeRequest">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="greetMeResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="greetMeOneWay">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="greetMeOneWayRequest">
<soap:body use="literal"/>
</wsdl:input>
</wsdl:operation>
<wsdl:operation name="pingMe">
<soap:operation style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
<wsdl:fault name="pingMeFault">
<soap:fault name="pingMeFault" use="literal"/>
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="SOAPService">
<wsdl:port binding="tns:Greeter_SOAPBinding" name="SoapPort">
<soap:address location="http://localhost:9000/SoapContext/SoapPort"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
This demo illustrates the use of the JAX-WS asynchronous invocation model
/**
* 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.
*/
Hello World Asynchronous Demo using Document/Literal Style
==========================================================
This demo illustrates the use of the JAX-WS asynchronous
invocation model. Please refer to the JAX-WS 2.0 specification
(http://jcp.org/aboutJava/communityProcess/pfd/jsr224/index.html)
for background.
The asynchronous model allows the client thread to continue after
making a two-way invocation without being blocked while awaiting a
response from the server. Once the response is available, it is
delivered to the client application asynchronously using one
of two alternative approaches:
- Callback: the client application implements the
javax.xml.ws.AsyncHandler interface to accept notification
of the response availability
- Polling: the client application periodically polls a
javax.xml.ws.Response instance to check if the response
is available
This demo illustrates both approaches.
Additional methods are generated on the Service Endpoint
Interface (SEI) to provide this asynchrony, named by
convention with the suffix "Async".
As many applications will not require this functionality,
the asynchronous variants of the SEI methods are omitted
by default to avoid polluting the SEI with unnecessary
baggage. In order to enable generation of these methods,
a bindings file (wsdl/async_bindings.xml) is passed
to the wsdl2java generator.
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 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_async 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_async directory, run the following wsdl2java
command to generate classes required in the async case.
For UNIX:
mkdir -p build/classes
wsdl2java -d build/classes -b ./wsdl/async_binding.xml -compile ./wsdl/hello_world_async.wsdl
For Windows:
mkdir build\classes
Must use back slashes.
wsdl2java -d build\classes -b .\wsdl\async_binding.xml -compile .\wsdl\hello_world_async.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_async directory run the commands, 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_async.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_async.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
///////////////////////////////////////////////////////////////////////////////
/**
* 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.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import javax.xml.namespace.QName;
import javax.xml.ws.Response;
import org.apache.hello_world_async_soap_http.GreeterAsync;
import org.apache.hello_world_async_soap_http.SOAPService;
import org.apache.hello_world_async_soap_http.types.GreetMeSometimeResponse;
public final class Client {
private static final QName SERVICE_NAME
= new QName("http://apache.org/hello_world_async_soap_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);
}
File wsdl = new File(args[0]);
SOAPService ss = new SOAPService(wsdl.toURL(), SERVICE_NAME);
ExecutorService executor = Executors.newFixedThreadPool(5);
ss.setExecutor(executor);
GreeterAsync port = ss.getSoapPort();
String resp;
// callback method
TestAsyncHandler testAsyncHandler = new TestAsyncHandler();
System.out.println("Invoking greetMeSometimeAsync using callback object...");
Future<?> response = port.greetMeSometimeAsync(System.getProperty("user.name"), testAsyncHandler);
while (!response.isDone()) {
Thread.sleep(100);
}
resp = testAsyncHandler.getResponse();
System.out.println();
System.out.println("Server responded through callback with: " + resp);
System.out.println();
//polling method
System.out.println("Invoking greetMeSometimeAsync using polling...");
Response<GreetMeSometimeResponse> greetMeSomeTimeResp =
port.greetMeSometimeAsync(System.getProperty("user.name"));
while (!greetMeSomeTimeResp.isDone()) {
Thread.sleep(100);
}
GreetMeSometimeResponse reply = greetMeSomeTimeResp.get();
System.out.println("Server responded through polling with: " + reply.getResponseType());
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 javax.xml.ws.AsyncHandler;
import javax.xml.ws.Response;
import org.apache.hello_world_async_soap_http.types.GreetMeSometimeResponse;
public class TestAsyncHandler implements AsyncHandler<GreetMeSometimeResponse> {
private GreetMeSometimeResponse reply;
public void handleResponse(Response<GreetMeSometimeResponse> response) {
try {
System.err.println("handleResponse called");
reply = response.get();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public String getResponse() {
return reply.getResponseType();
}
}
///////////////////////////////////////////////////////////////////////////////
/**
* 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.concurrent.Future;
import java.util.logging.Logger;
import javax.jws.WebService;
import javax.xml.ws.AsyncHandler;
import javax.xml.ws.Response;
import org.apache.hello_world_async_soap_http.GreeterAsync;
import org.apache.hello_world_async_soap_http.types.GreetMeSometimeResponse;
@WebService(serviceName = "SOAPService",
portName = "SoapPort",
endpointInterface = "org.apache.hello_world_async_soap_http.GreeterAsync",
targetNamespace = "http://apache.org/hello_world_async_soap_http")
public class GreeterImpl implements GreeterAsync {
private static final Logger LOG =
Logger.getLogger(GreeterImpl.class.getPackage().getName());
/* (non-Javadoc)
* @see org.apache.hello_world_soap_http.Greeter#greetMeSometime(java.lang.String)
*/
public String greetMeSometime(String me) {
LOG.info("Executing operation greetMeSometime");
System.out.println("Executing operation greetMeSometime\n");
return "How are you " + me;
}
public Future<?> greetMeSometimeAsync(String requestType,
AsyncHandler<GreetMeSometimeResponse> asyncHandler) {
return null;
/*not called */
}
public Response<GreetMeSometimeResponse> greetMeSometimeAsync(String requestType) {
return null;
/*not called */
}
}
///////////////////////////////////////////////////////////////////////////////
/**
* 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);
}
}
///////////////////////////////////////////////////////////////////////////////
<!--
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.
-->
<bindings
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
wsdlLocation="hello_world_async.wsdl"
xmlns="http://java.sun.ru/xml/ns/jaxws">
<bindings node="wsdl:definitions">
<enableAsyncMapping>true</enableAsyncMapping>
</bindings>
</bindings>
///////////////////////////////////////////////////////////////////////////////
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<wsdl:definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://apache.org/hello_world_async_soap_http" xmlns:x1="http://apache.org/hello_world_async_soap_http/types" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://apache.org/hello_world_async_soap_http" name="HelloWorld">
<wsdl:types>
<schema targetNamespace="http://apache.org/hello_world_async_soap_http/types" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:x1="http://apache.org/hello_world_async_soap_http/types" elementFormDefault="qualified">
<element name="greetMeSometime">
<complexType>
<sequence>
<element name="requestType" type="xsd:string"/>
</sequence>
</complexType>
</element>
<element name="greetMeSometimeResponse">
<complexType>
<sequence>
<element name="responseType" type="xsd:string"/>
</sequence>
</complexType>
</element>
</schema>
</wsdl:types>
<wsdl:message name="greetMeSometimeRequest">
<wsdl:part name="in" element="x1:greetMeSometime"/>
</wsdl:message>
<wsdl:message name="greetMeSometimeResponse">
<wsdl:part name="out" element="x1:greetMeSometimeResponse"/>
</wsdl:message>
<wsdl:portType name="GreeterAsync">
<wsdl:operation name="greetMeSometime">
<wsdl:input name="greetMeSometimeRequest" message="tns:greetMeSometimeRequest"/>
<wsdl:output name="greetMeSometimeResponse" message="tns:greetMeSometimeResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="GreeterAsync_SOAPBinding" type="tns:GreeterAsync">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="greetMeSometime">
<soap:operation style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="SOAPService">
<wsdl:port name="SoapPort" binding="tns:GreeterAsync_SOAPBinding">
<soap:address location="http://localhost:9000/SoapContext/SoapPort"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
This demo shows a client creating a callback object by passing an EndpointReferenceType to the server
/**
* 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.
*/
Callback Demo
=============================================
This demo shows a client creating a callback object by
passing an EndpointReferenceType to the server. The
EndpointRefrenceType is then used by the server to call
back on the callback object
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/basic_callback 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/basic_callback 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/basic_callback.wsdl
For Windows:
mkdir build\classes
Must use back slashes.
wsdl2java -d build\classes -compile .\wsdl\basic_callback.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/callback/client/*.java
javac -d build/classes src/demo/callback/server/*.java
For Windows:
set classpath=%classpath%;%CXF_HOME%\lib\cxf-manifest-incubator.jar;.\build\classes
javac -d build\classes src\demo\callback\client\*.java
javac -d build\classes src\demo\callback\server\*.java
Running the demo using java
---------------------------
From the samples/basic_callback directory run the commands, entered on a
single command line:
For UNIX (must use forward slashes):
java -Djava.util.logging.config.file=$CXF_HOME/etc/logging.properties
demo.callback.server.Server &
java -Djava.util.logging.config.file=$CXF_HOME/etc/logging.properties
demo.callback.client.Client ./wsdl/basic_callback.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.callback.server.Server
java -Djava.util.logging.config.file=%CXF_HOME%\etc\logging.properties
demo.callback.client.Client .\wsdl\basic_callback.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
////////////////////////////////////////////////////////////////
/**
* 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.callback.client;
import org.apache.callback.CallbackPortType;
@javax.jws.WebService(serviceName = "CallbackService",
portName = "CallbackPort",
endpointInterface = "org.apache.callback.CallbackPortType",
targetNamespace = "http://apache.org/callback")
public class CallbackImpl implements CallbackPortType {
/**
* serverSayHi
* @param: return_message (String)
* @return: String
*/
public String serverSayHi(String message) {
System.out.println("Callback object invoked");
System.out.println("Message recieved: " + message);
return new String("Hi " + message);
}
}
///////////////////////////////////////////////////////////////////
/**
* 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.callback.client;
import java.io.File;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Endpoint;
import org.apache.callback.SOAPService;
import org.apache.callback.ServerPortType;
import org.apache.cxf.ws.addressing.EndpointReferenceType;
import org.apache.cxf.wsdl.EndpointReferenceUtils;
public final class Client {
private static final QName SERVICE_NAME
= new QName("http://apache.org/callback", "SOAPService");
private static final QName SERVICE_NAME_CALLBACK
= new QName("http://apache.org/callback", "CallbackService");
private static final QName PORT_NAME_CALLBACK
= new QName("http://apache.org/callback", "CallbackPort");
private static final QName PORT_TYPE_CALLBACK
= new QName("http://apache.org/callback", "CallbackPortType");
private Client() {
}
public static void main(String args[]) throws Exception {
Object implementor = new CallbackImpl();
String address = "http://localhost:9005/CallbackContext/CallbackPort";
Endpoint.publish(address, implementor);
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]);
}
SOAPService ss = new SOAPService(wsdlURL, SERVICE_NAME);
ServerPortType port = ss.getSOAPPort();
EndpointReferenceType ref =
EndpointReferenceUtils.getEndpointReference(wsdlURL,
SERVICE_NAME_CALLBACK,
PORT_NAME_CALLBACK.getLocalPart());
EndpointReferenceUtils.setInterfaceName(ref, PORT_TYPE_CALLBACK);
String resp = port.registerCallback(ref);
System.out.println("Response from server: " + resp);
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.callback.server;
import javax.xml.ws.Endpoint;
public class Server {
protected Server() throws Exception {
System.out.println("Starting Server");
Object implementor = new ServerImpl();
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);
}
}
/////////////////////////////////////////////////////////////
/**
* 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.callback.server;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import org.apache.callback.CallbackPortType;
import org.apache.callback.ServerPortType;
import org.apache.cxf.jaxb.JAXBUtils;
import org.apache.cxf.ws.addressing.EndpointReferenceType;
import org.apache.cxf.wsdl.EndpointReferenceUtils;
import org.apache.cxf.wsdl.WSDLManager;
import org.apache.cxf.wsdl11.WSDLManagerImpl;
@javax.jws.WebService(serviceName = "SOAPService",
portName = "SOAPPort",
targetNamespace = "http://apache.org/callback",
endpointInterface = "org.apache.callback.ServerPortType")
public class ServerImpl implements ServerPortType {
public String registerCallback(EndpointReferenceType callback) {
try {
WSDLManager manager = new WSDLManagerImpl();
QName interfaceName = EndpointReferenceUtils.getInterfaceName(callback);
String wsdlLocation = EndpointReferenceUtils.getWSDLLocation(callback);
QName serviceName = EndpointReferenceUtils.getServiceName(callback);
String portString = EndpointReferenceUtils.getPortName(callback);
QName portName = new QName(serviceName.getNamespaceURI(), portString);
StringBuffer seiName = new StringBuffer();
seiName.append(JAXBUtils.namespaceURIToPackage(interfaceName.getNamespaceURI()));
seiName.append(".");
seiName.append(JAXBUtils.nameToIdentifier(interfaceName.getLocalPart(),
JAXBUtils.IdentifierType.INTERFACE));
System.out.println("the seiname is " + seiName.toString());
Class<?> sei = null;
try {
sei = Class.forName(seiName.toString(),
true, manager.getClass().getClassLoader());
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
URL wsdlURL = new URL(wsdlLocation);
Service service = Service.create(wsdlURL, serviceName);
CallbackPortType port = (CallbackPortType)service.getPort(portName, sei);
System.out.println("Invoking on callback object");
String resp = port.serverSayHi(System.getProperty("user.name"));
System.out.println("Response from callback object: " + resp);
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
return "registerCallback called";
}
}
///////////////////////////////////////////////////////////////////
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<wsdl:definitions name="basic_callback" targetNamespace="http://apache.org/callback"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:references="http://www.w3.org/2005/08/addressing"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://apache.org/callback"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.ru/xml/ns/jaxb" jaxb:version="2.0">
<wsdl:types>
<schema targetNamespace="http://apache.org/callback"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:jaxb="http://java.sun.ru/xml/ns/jaxb"
jaxb:version="2.0">
<xsd:import namespace="http://www.w3.org/2005/08/addressing" schemaLocation="/schemas/wsdl/ws-addr.xsd"/>
<element name="callback_message" type="xsd:string"/>
<element name="RegisterCallback" type="references:EndpointReferenceType"/>
<element name="returnType" type="xsd:string"/>
</schema>
</wsdl:types>
<wsdl:message name="server_sayHi">
<wsdl:part element="tns:callback_message" name="return_message"/>
</wsdl:message>
<wsdl:message name="register_callback">
<wsdl:part element="tns:RegisterCallback" name="callback_object"/>
</wsdl:message>
<wsdl:message name="returnMessage">
<wsdl:part element="tns:returnType" name="the_return"/>
</wsdl:message>
<wsdl:portType name="CallbackPortType">
<wsdl:operation name="ServerSayHi">
<wsdl:input message="tns:server_sayHi" name="ServerSayHiRequest"/>
<wsdl:output message="tns:returnMessage" name="ServerSayHiResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:portType name="ServerPortType">
<wsdl:operation name="RegisterCallback">
<wsdl:input message="tns:register_callback" name="RegisterCallbackRequest"/>
<wsdl:output message="tns:returnMessage" name="RegisterCallbackResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="CallbackPortType_SOAPBinding" type="tns:CallbackPortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="ServerSayHi">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="ServerSayHiRequest">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="ServerSayHiResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="ServerPortType_SOAPBinding" type="tns:ServerPortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="RegisterCallback">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="RegisterCallbackRequest">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="RegisterCallbackResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="CallbackService">
<wsdl:port binding="tns:CallbackPortType_SOAPBinding" name="CallbackPort">
<soap:address location="http://localhost:9005/CallbackContext/CallbackPort"/>
</wsdl:port>
</wsdl:service>
<wsdl:service name="SOAPService">
<wsdl:port binding="tns:ServerPortType_SOAPBinding" name="SOAPPort">
<soap:address location="http://localhost:9000/SoapContext/SoapPort"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
This demo shows how JAX-WS handlers are used
Handler Demo
============
This demo shows how JAX-WS handlers are used. The server uses a
SOAP protocol handler which logs incoming and outgoing messages
to the console.
The server code registers a handler using the @HandlerChain annotation
within the service implementation class. For this demo, LoggingHandler
is SOAPHandler that logs the entire SOAP message content to stdout.
The client includes a logical handler that checks the parameters on
outbound requests and short-circuits the invocation in certain
circumstances. This handler is specified programatically.
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/handlers directory, the ant build script can be used to
build and run the demo. The server and client targets automatically build
the demo.
Using either UNIX or Windows:
ant server
ant client
When using these ant targets, the server process uses the LoggingHandler
and the client process uses the SmallNumberHandler. Notice that both
the client and server consoles display short informative messages. The
client handler examines the operation parameters and, based on the
parameter values, may decide not to forward the request to the server. The server
handler displays the entire content of each message in its console.
The @HandlerChain annotation in the implementation class indicates that
the file demo_handler.xml includes the information needed to identify the
handler class.
@HandlerChain(file = "../common/demo_handlers.xml", name = "DemoHandlerChain")
The client side SmallNumberHandler is specified programatically:
SmallNumberHandler sh = new SmallNumberHandler();
List<Handler> newHandlerChain = new ArrayList<Handler>();
newHandlerChain.add(sh);
((BindingProvider)port).getBinding().setHandlerChain(newHandlerChain);
After running the client, terminate the server process.
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/handlers 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/addNumbers.wsdl
For Windows:
mkdir build\classes
Must use back slashes.
wsdl2java -d build\classes -compile .\wsdl\addNumbers.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/handlers/common/*.java
javac -d build/classes src/demo/handlers/client/*.java
javac -d build/classes src/demo/handlers/server/*.java
For Windows:
set classpath=%classpath%;%CXF_HOME%\lib\cxf-manifest-incubator.jar;.\build\classes
javac -d build\classes src\demo\handlers\common\*.java
javac -d build\classes src\demo\handlers\client\*.java
javac -d build\classes src\demo\handlers\server\*.java
Finally, copy the demo_handlers.xml file from the src/demo/handlers/common
directory into the build/classes/demo/handlers/common directory.
For UNIX:
cp ./src/demo/handlers/common/demo_handlers.xml ./build/classes/demo/handlers/common
For Windows:
copy src\demo\handlers\common\demo_handlers.xml build\classes\demo\handlers\common
Running the demo using java
---------------------------
From the samples/handlers directory run the commands (entered on a single command line):
For UNIX (must use forward slashes):
java -Djava.util.logging.config.file=$CXF_HOME%/etc/logging.properties
demo.handlers.server.Server &
java -Djava.util.logging.config.file=$CXF_HOME%/etc/logging.properties
demo.handlers.client.Client ./wsdl/addNumbers.wsdl
The server process starts in the background.
For Windows (may use either forward or back slashes):
start
java -Djava.util.logging.config.file=%CXF_HOME%\etc\logging.properties
demo.handlers.server.Server
java -Djava.util.logging.config.file=%CXF_HOME%\etc\logging.properties
demo.handlers.client.Client .\wsdl\addNumbers.wsdl
The server process starts in a new command window.
After running the client, terminate the server process.
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
This demo shows how to develope an user interceptor and add the interceptor into the interceptor chain through configuration
Stream GZIP Interceptor Demo
============================
This demo shows how to develope an user interceptor and add
the interceptor into the interceptor chain through configuration.
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 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/streamInterceptor 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/streamInterceptor 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.wsdl
For Windows:
mkdir build\classes
Must use back slashes.
wsdl2java -d build\classes -compile .\wsdl\hello_world.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/stream/interceptor/*.java
javac -d build/classes src/demo/stream/client/*.java
javac -d build/classes src/demo/stream/server/*.java
For Windows:
set classpath=%classpath%;%CXF_HOME%\lib\cxf-manifest-incubator.jar;.\build\classes
javac -d build\classes src\demo\stream\interceptor\*.java
javac -d build\classes src\demo\stream\client\*.java
javac -d build\classes src\demo\stream\server\*.java
Running the demo using java
---------------------------
From the samples/streamInterceptor directory run the commands, entered on a
single command line:
For UNIX (must use forward slashes):
java -Dcxf.config.file=server.xml
demo.stream.server.Server &
java -Dcxf.config.file=client.xml
demo.stream.client.Client ./wsdl/hello_world.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 -Dcxf.config.file=server.xml
demo.stream.server.Server
java -Dcxf.config.file=client.xml
demo.stream.client.Client .\wsdl\hello_world.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