Middleware
Application Server
First Created: August-2006
Author: Tugdual Grall
In order to exchange files with a web service we will:
1. Create a service interface (
FileExchangeService) . The service interface represents the functionality and operations we wish to provide to client applications:public interface FileExchangeService extends Remote {
public String put(String fileName,byte[] fileContent) throws
RemoteException, Exception;
public byte[] get(String fileName) throws
RemoteException, Exception;
}
2. Create a service implementation. The implementation class (FileExchangeServiceImpl) implements the service interface (FileExchangeService).
As you can see from the interface, as developer you won't need to manipulate any special Java class to get the content since it will be exchange using simple byte arrays. ( byte[]). In this sample application, you can find an helper class to manipulate the I/O. The how.to.ws.mtom.util.IOManager contains 2 methods:
<oracle:assemble appName="${app.name}"
serviceName="${app.name}"
input="${bld.webservice.dir}"
classpath="${bld.webservice.dir}"
output="${out.dir}"
ear="${lib.dir}/${ear.name}.ear"
>
<oracle:porttype interfaceName="how.to.ws.mtom.service.FileExchangeService" className=" how.to.ws.mtom.service .FileExchangeServiceImpl" >
< oracle:port soapVersion="1.2" uri="mtom-demo" name="mtom-demo-soap12" mtomsupport="true" />
< oracle:port soapVersion="1.1" uri="mtom-demo" name="mtom-demo-soap11" />
</oracle:porttype>
</oracle:assemble>
mtom-demo-soap12 where MTOM is enabled
<oracle:genProxy wsdl="http://${oracleas.host}:${oracleas.http.port}/${app.name}/ mtom-demo ?wsdl"
output="${src.cli.dir}"
packageName="how.to.ws.mtom.client.proxy"
>
< oracle:port name=" mtom-demo -soap12" mtomsupport="true" />
< oracle:port name=" mtom-demo -soap11" />
<classpath>
<pathelement path="${bld.cli.dir}"/>
<pathelement location="${OC4J_HOME}/webservices/lib/wsa.jar"/>
</classpath>
</oracle:genProxy>
In this sample we will create a banking web service that wraps and delegates its functionality to an underlying bank object.
The How-To zip file should contain the following:
In addition, please make sure that the ant command associated with the OC4J ant distribution is in your execution path ( %ORACLE_HOME%/ant/bin).
Stand Alone Installation: %ORACLE_HOME%/bin/oc4j start
Note that the oc4j command expects the JAVA_HOME environment variable to point to a full JDK installation.
OracleAS Managed Installation: %ORACLE_HOME%/opmn/bin/opmnctl startall
Executing the default "all" target of the supplied build.xml file performs the following steps:
<oracle:assemble appName="${app.name}"
serviceName="${app.name}"
input="${bld.webservice.dir}"
classpath="${bld.webservice.dir}"
output="${out.dir}"
ear="${lib.dir}/${ear.name}.ear"
>
<oracle:porttype interfaceName="how.to.ws.mtom.service.FileExchangeService" className=" how.to.ws.mtom.service. .FileExchangeServiceImpl" >
<oracle:port soapVersion="1.1" uri="mtom-demo" name="mtom-demo-soap11" />
<oracle:port soapVersion="1.2" uri="mtom-demo" name="mtom-demo-soap12" mtomsupport="true" />
</oracle:porttype>
</oracle:assemble>
mtom-demo / mtom-demo ?wsdl). The genProxy ant task is utilized for this purpose: <oracle:genProxy wsdl="http://${oracleas.host}:${oracleas.http.port}/${app.name}/ mtom-demo ?wsdl"
output="${src.cli.dir}"
packageName="how.to.ws.mtom.client.proxy"
>
< oracle:port name=" mtom-demo -soap12" mtomsupport="true" />
< oracle:port name=" mtom-demo -soap11" />
<classpath>
<pathelement path="${bld.cli.dir}"/>
<pathelement location="${OC4J_HOME}/webservices/lib/wsa.jar"/>
</classpath>
</oracle:genProxy>
Now that the web service is deployed and the client is generated and compiled we are ready to execute the application. From a command prompt in the root directory of the sample simply type:
This command executes the client application that performs the following operations and message exchanges (the message exchange figures below were captured by the JDeveloper 10g Http Analyzer and are provided to illustrate the underlying message exchanges performed during the execution of the remote service invocations):