There are different approaches to invoke the SOA Composites through java like DirectConnection, ADFBinding etc. But in both the approaches we have to add the additional configurations in the Composite.xml file.
Instead of using this approach, we can use the Apache Axis framework to invoke all the composites as a webservice.
We have implemented a Service Invocation Framework to invoke the composites through JAVA.
We have to set the endpoint and the operation name correspondingly to invoke the service
We can call SOA composite from java in simple two steps. First write java code to call composite and second change binding in Composite.xml to adf binding.
First step is to write java code that will invoke SOA composite. To make java code work you need to import some packages. Basically you need to add three below mentioned jar files in your project.
following are the Jars to import in to your java project:
Instead of using this approach, we can use the Apache Axis framework to invoke all the composites as a webservice.
We have implemented a Service Invocation Framework to invoke the composites through JAVA.
We have to set the endpoint and the operation name correspondingly to invoke the service
We can call SOA composite from java in simple two steps. First write java code to call composite and second change binding in Composite.xml to adf binding.
First step is to write java code that will invoke SOA composite. To make java code work you need to import some packages. Basically you need to add three below mentioned jar files in your project.
following are the Jars to import in to your java project:
next step is changing the composite.xml to add binding.adf like below(bold) :
<service name="JavaBinding" ui:wsdlLocation="HelloBPELProcess.wsdl">
<interface.wsdl interface="http://xmlns.oracle.com/SOATECHBLOG/Hello_project/HelloBPELProcess#wsdl.interface(HelloBPELProcess)"/>
<binding.direct/>
</service>
and actual java code :
Locator locator = null;
try {
DirectConnectionFactory factory = JNDIDirectConnectionFactory.newInstance();
String serviceAddress = "soadirect:/default/Hello_project!1.0/JavaBinding";
DirectConnection dc;
dc = factory.createConnection(serviceAddress,jndiProps);
// Sample payload from em is as follows -
String inputPayload =
"<Order xmlns=\"http://www.example.org\">"+
"<customerId>38271</customerId>"+
"<customerName>deepthireddy</customerName>"+
"<customerdetails>CDH account</customerdetails>"+
"<CardType>ACH</CardType>"+
"<Product>iphone5</Product>"+
"<Quantity>4</Quantity>"+
"<TotalPrice>45,000</TotalPrice>"+
"</Order>"
;
System.out.println(inputPayload);
/* xmlns=\"http://www.example.org\\">
<customerId></customerId>
<customerName></customerName>
<customerdetails></customerdetails>
<CardType></CardType>
<Product></Product>
<Quantity></Quantity>
<TotalPrice></TotalPrice>
</Order>";*/
System.out.println("Input = " +"\n" + inputPayload);
//
// parse using the Oracle XML parser.
// Thanks Silviu!
oracle.xml.parser.v2.DOMParser op = new DOMParser();
op.parse(new InputSource(new StringReader(inputPayload)));
// just a print to check it
XMLPrintDriver pd = new XMLPrintDriver(System.out);
pd.setFormatPrettyPrint(true);
pd.printDocument(op.getDocument());
Map partData = new HashMap();
partData.put("payload", op.getDocument().getDocumentElement());
// Create the Message and pass in the payload
Payload payload = PayloadFactory.createXMLPayload(partData);
Message request = XMLMessageFactory.getInstance().createMessage();
request.setPayload(payload);
// Define conversation ID
String uuid = "uuid:" + UUID.randomUUID();
System.out.println("uuid = "+ uuid);
request.setProperty(request.CONVERSATION_ID, uuid);
// Invoke...
dc.post("process",request);
} catch (Exception e) {
e.printStackTrace();
}
}
}
<service name="JavaBinding" ui:wsdlLocation="HelloBPELProcess.wsdl">
<interface.wsdl interface="http://xmlns.oracle.com/SOATECHBLOG/Hello_project/HelloBPELProcess#wsdl.interface(HelloBPELProcess)"/>
<binding.direct/>
</service>
and actual java code :
Locator locator = null;
try {
DirectConnectionFactory factory = JNDIDirectConnectionFactory.newInstance();
String serviceAddress = "soadirect:/default/Hello_project!1.0/JavaBinding";
DirectConnection dc;
dc = factory.createConnection(serviceAddress,jndiProps);
// Sample payload from em is as follows -
String inputPayload =
"<Order xmlns=\"http://www.example.org\">"+
"<customerId>38271</customerId>"+
"<customerName>deepthireddy</customerName>"+
"<customerdetails>CDH account</customerdetails>"+
"<CardType>ACH</CardType>"+
"<Product>iphone5</Product>"+
"<Quantity>4</Quantity>"+
"<TotalPrice>45,000</TotalPrice>"+
"</Order>"
;
System.out.println(inputPayload);
/* xmlns=\"http://www.example.org\\">
<customerId></customerId>
<customerName></customerName>
<customerdetails></customerdetails>
<CardType></CardType>
<Product></Product>
<Quantity></Quantity>
<TotalPrice></TotalPrice>
</Order>";*/
System.out.println("Input = " +"\n" + inputPayload);
//
// parse using the Oracle XML parser.
// Thanks Silviu!
oracle.xml.parser.v2.DOMParser op = new DOMParser();
op.parse(new InputSource(new StringReader(inputPayload)));
// just a print to check it
XMLPrintDriver pd = new XMLPrintDriver(System.out);
pd.setFormatPrettyPrint(true);
pd.printDocument(op.getDocument());
Map partData = new HashMap();
partData.put("payload", op.getDocument().getDocumentElement());
// Create the Message and pass in the payload
Payload payload = PayloadFactory.createXMLPayload(partData);
Message request = XMLMessageFactory.getInstance().createMessage();
request.setPayload(payload);
// Define conversation ID
String uuid = "uuid:" + UUID.randomUUID();
System.out.println("uuid = "+ uuid);
request.setProperty(request.CONVERSATION_ID, uuid);
// Invoke...
dc.post("process",request);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Now you are ready to invoke SOA Composite by using this Java API.
Happy Learning
By DeepthiReddy
No comments:
Post a Comment