This example shows how to add attachments to a SOAP message from client and service side handlers. The service is a simple "Hello" service that takes a string parameter and returns a string result. In this example a client side handler adds an image attachment to the message. The service side handler examines the attachment and then add its own plain text attachment to the result.
Quick StartEnsure that you have installed the required software and set up your environment. You must have OC4J running. If it is not running on localhost, port 8888, you'll have to modify the ANT script (build.xml) to use the correct host and port to your server.
Once you have the server configured and running, just type ant from the attachments directory. The service artifacts and implementation class will be compiled and placed into a WAR which is then placed into an EAR. The EAR will be deployed to OC4J. Next the stubs and client will be compiled. Finally the service will be invoked by the client and you should see the output both in the server's message output and on the stdout of the client.
Step By Step
In this step you will generate the service artifacts which include interfaces
and Tie classes.
Examine the service-config.xml file: the implementation-class-name element
is filled in with the implentation class provided by the demo. This class
is not compiled yet so WSA will generate the artifacts and use the class
name as a place holder. Once the artifacts are generated, the implementation
class will have to be compiled and WSA will have to be run again with the
same config file.
To generate the service artifacts type: ant gen-service. The source code
for the service-artifacts will be placed in the src/service directory using
the package name oracle.demo.attachments.service.
Examine the type-mapping.xml file. This file is
used to instruct WSA how to map types to package name. A namespace URI is
mapped to a specific package name. Notice that this example maps its types
to the package oracle.demo.attachments.types. So for service artifacts the
types are generated in src/service/oracle/demo/attachments/types.
In this step you will generate the stubs for the service. A client application uses a stub to invoke operations on a remote service. To generate the stubs type: ant gen-stubs. The source for the stubs will be placed in build/client.
In this step you will compile the implementation classes and regenerate
the EAR file that will now contain both service artifacts and the implementation
class.
Examine the file AttachmentsImpl.java under src/service/oracle/demo/attachments/service.
Notice that the class implements AttachmentsPortType which is a service
artifact and thus generated by the tool. Before the first step there were
no generated files so compiling this class would have failed. Now that you
have already ran the gen-service task you are ready to compile the class
and update the EAR. To update the implementation type: ant update-impl.
The service is now ready to be deployed. Examine the attachments.ear in the build directory. It should contain a WAR file named attachments-web.war. This WAR file contains all the service artifacts, implementation classes, as well as the web deployment descriptor (web.xml) and the jaxrpc deployment descriptor (jaxrpc-ri-runtime.xml). To deploy this ear to a running instance of oc4j type: ant deploy-demo.
You are now ready to run the client. Examine the file AttachmentsClient.java in src/client/oracle/demo/attachments/ . Notice that this class uses the stubs to set an endpoint address and to invoke methods on the remote service. To run the client type: ant run-demo. You should see some sample output on both the oc4j and client output screens.