Java services call other services through the Java service proxy interface. You can generate proxy method invocations using drag-and-drop in the service editor. However, you may need to modify the generated code to supply appropriate input values and handle returned data.
Understanding parameter datatypes
Java datatypes used in the proxy methods are converted from the parameter types used in the WSDL specification of the service interface, with WSDL to Java conversion following the Apache AXIS XML-to-Java mappings. Mappings to standard Java types are provided for the commonly used XML schema types listed in the following table.
XML to Java mappings for commonly used datatypes
XML datatype | Java datatype |
---|---|
xsd:boolean | boolean or, if the parameter is nillable, java.lang.Boolean |
xsd:byte | byte or, if the parameter is nillable, java.lang.Byte |
xsd:double | double or, if the parameter is nillable, java.lang.Double |
xsd:float | float or, if the parameter is nillable, java.lang.Float |
xsd:int | int or, if the parameter is nillable, java.lang.Integer |
xsd:long | long or, if the parameter is nillable, java.lang.Long |
xsd:short | short or, if the parameter is nillable, java.lang.Short |
xsd:integer | java.math.BigInteger |
xsd:string | java.lang.String |
xsd:decimal | java.math.BigDecimal |
xsd:dateTime | java.util.Calendar |
xsd:QName | javax.xml.namespace.QName |
xsd:base64Binary | byte[] |
xsd:hexBinary | byte[] |
Other complex XML schema types convert to Java classes which typically follow the JavaBeans pattern with getter and setter methods for each subelement allowed by the XML schema. Use these resources to review the generated class's public interface:
The Java source editor content assist feature allows you to explore what methods and fields are available when working with an instance in your code.
The generated source code. The Java outline view and navigator allow you to browse the class's public methods and fields. To use these tools, open the source file for the class and switch to the Java perspective.
When you invoke a SOAP service, the proxy for the SOAP service uses Java types derived from the schema types used in the SOAP service WSDL. These generated classes wrap parameter input values and return values using the JavaBeans getter/setter pattern to access the wrapped value. You must write code to create these objects and get and set values. Use the techniques described above to inspect the interface of the wrapper types.
Handling input-output or output parameters
Input-output or output parameters in the WSDL operation are represented by JAX-RPC holder parameters in the proxy method prototype. A holder class implements the javax.xml.rpc.holders.Holder interface and typically has a public value field that contains the value being passed to or returned from the service invocation. The type of the value field matches the corresponding XML parameter type.
Since Java service operations cannot have input-output parameters, Java methods that are exposed as service operations cannot use JAX-RPC holder classes as parameters or return values. Java Service Datatypes describes the types that can be used in the Java service interface.
Example: Calling a database service operation
The example below shows a Java service method process that calls a database service method sp_product_info to invoke a stored procedure of the same name. The proxy for sp_product_info takes as parameters, respectively:
An integer holder to specify an input-output int parameter that specifies a product ID.
A holder for an output parameter that receives the update counts from the invocation (the number of rows affected by commands in the stored procedure)
A holder for an output parameter that receives warnings returned from the stored procedure
A holder for an output parameter that receives a tabular result set returned from the stored procedure.
Here is the code:
import org.apache.wsif.WSIFException; import mycompany.ASA_ProdInfoProxy; import com.sybase.schemas.services.jdbc.V1_1.sp_product_info.holders.*; import com.sybase.schemas.services.jdbc.V1_1.sp_product_info.*; import javax.xml.rpc.holders.*; public class Composite { /** * process * * @sws method;expose=true;visible=true;style=OPERATION_STYLE_REQRESPONSE;returnName=ProdInfo; * @version Thu Jul 28 15:10:18 MDT 2005 * @param prodID * @param null * @return */ public Sp_product_infoResultSet1Type process(int prodID) { IntHolder prod_id = new IntHolder(prodID); IntHolder return_value = new IntHolder(); UpdateCountsTypeHolder update_counts = new UpdateCountsTypeHolder(); WarningsTypeHolder warnings = new WarningsTypeHolder(); Sp_product_infoResultSet1TypeHolder sp_product_infoResultSet1 = new Sp_product_infoResultSet1TypeHolder(); ASA_ProdInfoProxy.sp_product_info(prod_id, return_value, update_counts, warnings, sp_product_infoResultSet1); return sp_product_infoResultSet1.value; } }
Implementing Service-to-Service Calls in a Java Service
Generating Java Service Proxies
Handling Exceptions in a Java Service
Viewing Services and Service Operations in the Service Explorer
Send your feedback on this help topic to Sybase Tech Pubs: pubs@sybase.com