BPEL Java Embed

Submitted by code_admin on Mon, 07/23/2018 - 14:56

Imports

  1.  <!--
  2.   <import location="oracle.xml.parser.v2.XMLElement" importType="http://schemas.oracle.com/bpel/extension/java"/&gt;  
  3.   <import location="ic.ac.uk.ic.utils.json_to_xml.ICJson_Converter" importType="http://schemas.oracle.com/bpel/extension/java"/&gt;
  4.   -->
  5.  
  6. <!--
  7.   <import location="ic.ac.uk.ic.utils.json_to_xml.XML" importType="http://schemas.oracle.com/bpel/extension/java"/&gt;  
  8.   <import location="ic.ac.uk.ic.utils.json_to_xml.JSONObject" importType="http://schemas.oracle.com/bpel/extension/java"/&gt;
  9.  
  10.   <import location="org.xml.sax.InputSource" importType="http://schemas.oracle.com/bpel/extension/java"/&gt;
  11.   <import location="java.io.StringReader" importType="http://schemas.oracle.com/bpel/extension/java"/&gt;
  12.   <import location="org.w3c.dom.Document" importType="http://schemas.oracle.com/bpel/extension/java"/&gt;
  13.   <import location="javax.xml.parsers.DocumentBuilderFactory" importType="http://schemas.oracle.com/bpel/extension/java"/&gt;
  14.   <import location="javax.xml.parsers.DocumentBuilder" importType="http://schemas.oracle.com/bpel/extension/java"/&gt;
  15. -->
  1.     <extensionActivity>
  2.       <bpelx:exec name="Java_Embedding1" language="java">
  3.         <![CDATA[XMLElement srcElem = (XMLElement) getVariableData("inputVariable", "part1", "/ns1:RequestMessage/ns1:InputMsg");            
  4.        
  5.        
  6.        
  7.  String JSONstr = "";      
  8.  JSONstr = srcElem.getTextContent();            
  9.     /*  
  10. JSONObject json = new JSONObject(JSONstr);      
  11. String xmlF = XML.toString(json);   */  
  12.  
  13. String xml = "DS";  
  14. //    String xml = "<xml xmlns=\"TESTNAMESPACE\">" + ICJson_Converter.toXML(JSONstr) + "</xml>";      
  15.          
  16. setVariableData("outputVariable","part1","ns1:ResponseMsg","JSON was: " + JSONstr);      
  17.      
  18. //setVariableData("outputVariable","part1","ns1:GeneratedXML",xml);      
  19. setVariableData("XMLString",xml);]]>
  20.       </bpelx:exec>
  21.     </extensionActivity>

Getting a string

Put import after process tag:

  1. <import location="oracle.xml.parser.v2.XMLElement" importType="http://schemas.oracle.com/bpel/extension/java"/&gt;  
  1.     <extensionActivity>
  2.       <bpelx:exec name="Java_CallRestfulService" language="java">
  3.         <![CDATA[
  4.        
  5.  
  6. String response = "";  
  7.  
  8. XMLElement uriE = (XMLElement) getVariableData("inputVariable","part1","/ns2:requestMessage/ns2:URI");  
  9. String uri = uriE.getTextContent();
  10.    
  11. response = "Test:" + uri;  
  12. } catch (Exception e) {  
  13.     response = "ERROR:" + e.getMessage();  
  14. }  
  15. setVariableData("JSON_Response", response);]]>
  16.       </bpelx:exec>
  17.     </extensionActivity>

Good Error Practice

  1. <import location="oracle.xml.parser.v2.XMLElement" importType="http://schemas.oracle.com/bpel/extension/java"/&gt;
  2. <import location="javax.xml.namespace.QName" importType="http://schemas.oracle.com/bpel/extension/java"/&gt;
  3. <import location="com.oracle.bpel.client.BPELFault" importType="http://schemas.oracle.com/bpel/extension/java"/&gt;
  1. try {
  2.  
  3. XMLElement responseEle = (XMLElement) getVariableData("outputVariable","response","/ns1:RequestResponse");
  4.  
  5. XMLElement StatusEle = new XMLElement("Status", "", ns);
  6. StatusEle.addText("OK");
  7. responseEle.appendChild(StatusEle);
  8.  
  9.  
  10. } catch (Exception e) {
  11.     QName qName = new QName("http://schemas.oracle.com/bpel/extension&quot;, "remoteFault");
  12.     BPELFault bpelFault = new BPELFault(qName);
  13.     bpelFault.setPart("code", "JAVAEMBEDDING");
  14.     bpelFault.setPart("summary", e.getClass().getName() + ": " + e.getMessage());
  15.     bpelFault.setPart("detail", e.getMessage());
  16.     // throw the fault
  17.     throw bpelFault;
  18. }

Simple String

Remember to CAST

  1. String ClientID = (String) getVariableData("ClientID");
  2.  
  3. ClientID = "SSS";
  4.  
  5. setVariableData("ClientID",ClientID);

Read String value that could be null

  1. XMLElement srcBatchID = null;
  2. String batchID = "";
  3. try {
  4.     srcBatchID = (XMLElement) getVariableData("inputVariable", "part1", "/ns2:Message/ns2:header/ns3:BatchID");  
  5.     batchID = srcBatchID.getTextContent();
  6. } catch (BPELFault bpfe) {
  7.     QName qName = new QName("http://docs.oasis-open.org/wsbpel/2.0/process/executable&quot;, "selectionFailure");  
  8.     if (!qName.equals(bpfe.getFaultName())) {
  9.         throw bpfe;
  10.     }
  11.     srcBatchID = null;
  12.     batchID = "";
  13. };
RJM Article Type
Work Notes