Java Integration
Transform Anything with Java
Creating a Mock Service in OSB
To Create a mock service we can take an existing WSDL and XSD file.
WSDL File is as below.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.sprajan.org/CustomerManagement" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:cus="http://www.sprajan.com/customer"
name="CustomerManagement" targetNamespace="http://www.sprajan.org/CustomerManagement">
<wsdl:types>
<xsd:schema targetNamespace="http://www.sprajan.org/CustomerManagement">
<xsd:import namespace="http://www.sprajan.com/customer"
schemaLocation="../xsd/Customer.xsd" />
<xsd:element name="FindCustomer">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="ID" type="xsd:long" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="FindCustomerResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Customer" type="cus:CustomerTyp" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="StoreCustomer">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Customer" type="cus:CustomerTyp" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="StoreCustomerResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="ID" type="xsd:long"></xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<wsdl:message name="FindCustomerRequest">
<wsdl:part element="tns:FindCustomer" name="parameters" />
</wsdl:message>
<wsdl:message name="FindCustomerResponse">
<wsdl:part element="tns:FindCustomerResponse" name="parameters" />
</wsdl:message>
<wsdl:message name="StoreCustomerRequest">
<wsdl:part name="parameters" element="tns:StoreCustomer"></wsdl:part>
</wsdl:message>
<wsdl:message name="StoreCustomerResponse">
<wsdl:part name="parameters" element="tns:StoreCustomerResponse"></wsdl:part>
</wsdl:message>
<wsdl:portType name="CustomerManagement">
<wsdl:operation name="FindCustomer">
<wsdl:input message="tns:FindCustomerRequest" />
<wsdl:output message="tns:FindCustomerResponse" />
</wsdl:operation>
<wsdl:operation name="StoreCustomer">
<wsdl:input message="tns:StoreCustomerRequest"></wsdl:input>
<wsdl:output message="tns:StoreCustomerResponse"></wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="CustomerManagementSOAP" type="tns:CustomerManagement">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="FindCustomer">
<soap:operation
soapAction="http://www.sprajan.org/CustomerManagement/FindCustomer" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="StoreCustomer">
<soap:operation
soapAction="http://www.sprajan.org/CustomerManagement/StoreCustomer" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="CustomerManagement">
<wsdl:port binding="tns:CustomerManagementSOAP" name="CustomerManagementSOAP">
<soap:address location="http://to-be-defined-by-user" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
XSD Files are as below.
Customer.xsd
<xs:schema xmlns:tns="http://www.sprajan.com/customer" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:credit="http://www.sprajan.com/creditcard" targetNamespace="http://www.sprajan.com/customer" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:import namespace="http://www.sprajan.com/creditcard" schemaLocation="CreditCard.xsd"/>
<xs:element name="Customer" type="tns:CustomerTyp"/>
<xs:complexType name="CustomerTyp">
<xs:sequence>
<xs:element name="ID" type="xs:long"/>
<xs:element name="FirstName" type="xs:string"/>
<xs:element name="LastName" type="xs:string"/>
<xs:element name="EmailAddress" type="xs:string"/>
<xs:element name="Addresses" type="tns:AddressesTyp"/>
<xs:element name="BirthDate" type="xs:date"/>
<xs:element name="Rating" type="tns:RatingTyp"/>
<xs:element name="Gender" type="xs:string"/>
<xs:element name="CreditCard" type="credit:CreditCardTyp"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="AddressesTyp">
<xs:sequence>
<xs:element name="Address" type="tns:AddressTyp" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="AddressTyp">
<xs:sequence>
<xs:element name="Street" type="xs:string"/>
<xs:element name="PostalCode" type="xs:string"/>
<xs:element name="City" type="xs:string"/>
<xs:element name="Country" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:simpleType name="RatingTyp">
<xs:restriction base="xs:string">
<xs:enumeration value="A"/>
<xs:enumeration value="AA"/>
<xs:enumeration value="AAA"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
Creditcard.xsd
<xs:schema xmlns:tns="http://www.sprajan.com/creditcard"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.sprajan.com/creditcard"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:element name="CreditCard" type="tns:CreditCardTyp"/>
<xs:complexType name="CreditCardTyp">
<xs:sequence>
<xs:element name="CardIssuer" type="tns:CardIssuerTyp"/>
<xs:element name="CardNumber" type="xs:string"/>
<xs:element name="CardholderName" type="xs:string"/>
<xs:element name="ExpirationDate" type="xs:string"/>
<xs:element name="CardValidationCode" type="xs:long"/>
</xs:sequence>
</xs:complexType>
<xs:simpleType name="CardIssuerTyp">
<xs:restriction base="xs:string">
<xs:enumeration value="visa"/>
<xs:enumeration value="amexco"/>
<xs:enumeration value="mastercard"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
1. Open Eclipse > New > Oracle Service Bus Project > Name it as mockservice.
2. Create the folders ProxyService, xsd, wsdl
3. Place the xsd's and wsdl's in their respective folders.

4. Right Click on the ProxyService Folder > New > Proxy Service (Name it)
5. On the General Tabm choose WSDL web service and click on Browse, and choose the CustomerManagement.wsdl that we created earlier.
Sekect the port and click OK.
6. The transport settings will automatically get updated.
7. Go to Message Flow tab. Add the components as the below image.


8. On the Assign > Expressions > Paste > fn:concat("Hello", $body/cus:FindCustomer/ID)
9. Name the variable as varCustomerID


10. On the replace set xpath=., Variable as body and Expression as below.
<soap-env:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<cus:FindCustomerResponse>
<cus1:ID>{$varCustomerID}</cus1:ID>
</cus:FindCustomerResponse>
</soap-env:Body>
11. Now export the OSB project to a jar and test it in console.

