Setting service naming defaults
You can modify the service naming defaults in the Web Service Components [WebLogic toolkit] Properties dialog box. Right-click the Web Service Components node in the project pane and choose Properties.
Here you can choose how to generate the service and choose naming options. For more information on these options, choose the Help button.
If you modify these properties, they are immediately reflected in the WLDU files for EJBs. But for Java classes, since they are statically created by wizards, the changes won’t be reflected unless you export the Java classes again as a web service.
C h a p t e r
9
Chapter9
Using the Apache SOAP 2
toolkit
This is a feature of JBuilder Enterprise.
Support for the Apache SOAP 2 toolkit is not provided in the JBuilder WebLogic Edition
If you’re using the Apache SOAP 2 toolkit, you’ll need to make some modifications when using the JBuilder wizards and do additional hand coding. Because SOAP 2 is an older version of Apache Axis and pre-dates the WSDL specification, there isn’t any built-in WSDL support for SOAP.
However, you can use the Import A Web Service and Export As A Web Service wizards and the Axis toolkit, because JBuilder provides an Axis to Apache SOAP cross-deployer that converts Axis deployment information into Apache SOAP.
Caution Note that Apache SOAP 2 is an older version of Axis and does not support JAX-RPC or WSDL. Due to these limitations, it’s recommended that you use Axis instead.
For more information on the Apache SOAP 2 toolkit, see the documentation in <jbuilder>/thirdparty/apache-soap/docs or visit the Apache web site at http://xml.apache.org/soap/
Create this simple example, and then make the appropriate changes in the wizards and the WSDL document.
1 Create a new project named Untitled1 (File|New Project).
2 Create a JavaBean named Bean1 with the JavaBean wizard, choose java.lang.Object as the base class, and check the Generate Sample Property option (File|New|General).
3 Right-click Bean1.java in the project pane and choose Export As A Web Service. Because the project isn’t configured for web services, the Web Services Configuration wizard opens first so you can configure the project.
E x p o r t i n g a c l a s s a s a w e b s e r v i c e
4 Create a new WebApp named soapsample to host the service, choose Apache SOAP 2 as the toolkit in the the Web Services Configuration wizard, and click Finish. Now the Export As A Web Service wizard opens.
5 Choose Axis as the toolkit in the Export As A Web Service wizard and make the changes specified in “Exporting a class as a web service” on page 9-2. Note that there isn’t a SOAP toolkit available in the wizard because SOAP doesn’t support WSDL.
Exporting a class as a web service
When exporting a class as a web service, you need to make the following changes in the Export As A Web Service wizard:
1 Uncheck the Generate Client Stub option on Step 1.
2 Change the Location URL on Step 2 of the wizard from
"http://localhost:8080/axis/services/Bean1" to
"http://localhost:8080/<soapsample>/servlet/rpcrouter", where
<soapsample> is the WebApp name.
3 Choose the methods you want to expose on Step 4.
a Choose Allow All Methods from the Selection Mode drop-down list.
b Select the methods you want to expose in the tree.
4 Click Finish to close the wizard.
Importing a WSDL
Before importing a WSDL to create a client, modify the WSDL. Then import the WSDL with the Import A Web Service wizard.
1 Modify the operation input and output namespace attributes in the binding section of the WSDL to match the port of the service. For example, change namespace="http://untitled1" to the port name, "Bean1".
The reason this change is required is that SOAP’s dispatcher servlet needs to know about the service to dispatch and namespace is the mechanism it uses. Note that in the next generation of toolkits, such as Axis, this change isn’t required because URL mapping is used.
I m p o r t i n g a W S D L
WSDL before editing
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://untitled1"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:apachesoap="http://xml.apache.org/xml-soap"
xmlns:impl="http://untitled1-impl" xmlns:intf="http://untitled1"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
[... rest of WSDL snipped for brevity ...]
<wsdl:binding name="Bean1SoapBinding" type="intf:Bean1">
<wsdlsoap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getSample">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getSampleRequest">
<wsdlsoap:body encodingStyle=
"http://schemas.xmlsoap.org/soap/encoding/"
namespace="http://untitled1" use="encoded"/>
</wsdl:input>
<wsdl:output name="getSampleResponse">
<wsdlsoap:body encodingStyle=
"http://schemas.xmlsoap.org/soap/encoding/"
namespace="http://untitled1" use="encoded"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="setSample">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="setSampleRequest">
<wsdlsoap:body encodingStyle=
"http://schemas.xmlsoap.org/soap/encoding/"
namespace="http://untitled1" use="encoded"/>
</wsdl:input>
<wsdl:output name="setSampleResponse">
<wsdlsoap:body encodingStyle=
<wsdl:port binding="intf:Bean1SoapBinding" name="Bean1">
<wsdlsoap:address location=
"http://localhost:8080/soapsample/servlet/rpcrouter"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
I m p o r t i n g a W S D L
Edited WSDL
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://untitled1"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:apachesoap="http://xml.apache.org/xml-soap"
xmlns:impl="http://untitled1-impl"
xmlns:intf="http://untitled1"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
[... rest of WSDL snipped for brevity ...]
<wsdl:binding name="Bean1SoapBinding" type="intf:Bean1">
<wsdlsoap:binding style="rpc" transport=
"http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getSample">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getSampleRequest">
<wsdlsoap:body encodingStyle=
"http://schemas.xmlsoap.org/soap/encoding/"
namespace="Bean1" use="encoded"/>
</wsdl:input>
<wsdl:output name="getSampleResponse">
<wsdlsoap:body encodingStyle=
"http://schemas.xmlsoap.org/soap/encoding/"
namespace="Bean1" use="encoded"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="setSample">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="setSampleRequest">
<wsdlsoap:body encodingStyle=
"http://schemas.xmlsoap.org/soap/encoding/"
namespace="Bean1" use="encoded"/>
</wsdl:input>
<wsdl:output name="setSampleResponse">
<wsdlsoap:body encodingStyle=
<wsdl:port binding="intf:Bean1SoapBinding" name="Bean1">
<wsdlsoap:address location=
"http://localhost:8080/soapsample/servlet/rpcrouter"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
I m p o r t i n g a W S D L
2 Right-click the edited WSDL file and choose Import A Web Service to open the Import A Web Service wizard.
3 Choose Apache Axis as the toolkit.
4 Uncheck the Generate Server-side Classes on Step 2 of the Import A Web Service wizard.
5 Change the package name on step 3 of the wizard to
untitled1.generated. If you don’t change the package name, the wizard will overwrite the Bean1 class you’re exporting.
6 Click Finish.
7 Build and run the project with the Web Services Server configuration.
8 Right-click the test case and run it to test the service.
If you prefer to hand code the client, follow this client example.
public class Test {
public static void main(String[] args) throws Exception {
URL url = new URL("http://localhost:8082/soapsample/servlet/rpcrouter");
// String nameToLookup = "Bean1";
Call call = new Call();
call.setTargetObjectURI("Bean1");
call.setMethodName("getSample");
call.setEncodingStyleURI(encodingStyleURI);
// Vector params = new Vector();
//
// params.addElement(new Parameter("sample", String.class, nameToLookup, null));
// call.setParams(params);
System.err.println("Caught SOAPException (" + e.getFaultCode() + "): " + e.getMessage());
return;
}
I m p o r t i n g a W S D L
// Check the response.
if (!resp.generatedFault()) {
Parameter ret = resp.getReturnValue();
Object value = ret.getValue();
System.out.println(value != null ? "\n" + value : "I don't know.");
} else {
Fault fault = resp.getFault();
System.err.println("Generated fault: ");
System.out.println (" Fault Code = " + fault.getFaultCode());
System.out.println (" Fault String = " + fault.getFaultString());
} } }
C h a p t e r
10
Chapter10