Thursday, October 17, 2013

OSB - Remove Namespace using XQuery



Recently, we came across a requirement , where we need to remove name space of XML before we send to MQ. this case IBM I Series application is receiving data from processing .

This is very common requirements specially when we are integrating with legacy system.  In order to achieve functionality, I use below X-Query function. 

Name -RemoveNamespace

xquery version "1.0" encoding "Cp1252";
(:: pragma  parameter="$anyType1" type="xs:anyType" ::)
(:: pragma  type="xs:anyType" ::)

declare namespace xf = "http://www.officedepot.org/Order/Remove_Namespace/";

declare function xf:removeNamespace($e as element())as element()
{element { xs:QName(local-name($e)) }
{ for $child in $e/(@*,node())
 return  
 if ($child instance of element())
    then xf:removeNamespace($child)
       else $child
       }
 };

declare variable $e as element() external;

xf:removeNamespace($e)

Now, we need to use replace action in proxy message flow to execute this XQuery, 






In side Proxy Flow, add replace action

Select "Replace node contents" radio button
XQuery  Bind Variables should be $body . Please note , it is not  $body/* .


This will remove namespace elements from XML . Happy codding. :)

Wednesday, October 9, 2013

SOA : XPATH BPEL4WS spec 1.1 section 14.3 Error

Some time we will be getting below error in BPEL flow for assign or transform activity.

<bpelFault><faultType>0</faultType><selectionFailure xmlns="http://schemas.xmlsoap.org/ws/2003/03/business-process/"><part name="summary"><summary>The &lt;from> value is invalid. The result of from-spec is null. Either the from node value or the xpath query in the from node value was invalid. According to BPEL4WS spec 1.1 section 14.3, the from node value should not be empty. Verify the from node value at line number no line in the BPEL source. </summary></part></selectionFailure></bpelFault>"

this can be happen either in assign or transform activity of BPEL flow. in order to avoid this error , assign dummy value to variable. This will be overwritten by the Assign activity in the next step anyways.

Happy codding :)

Tuesday, October 8, 2013

NTML Authentication - Oracle SOA suite

Recently my team had an issue where we need to call a NTML authenticated service and Oracle SOA suite, we are able to call from SOAP UI and not from BPEL SOA.
 

We tried different security header options and none of them is worked worked.

 

Current SOA is not support NTML authentication in Oracle SOA, we need to write a customer java code to call external NTML autheticated service.


In order to achieve that, we use java embedded inside  BPEL code to call external service. code looks .

 

 


 try {


 String userAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13";

 org.apache.commons.httpclient.HttpClient client = new org.apache.commons.httpclient.HttpClient();

 String soapAction ="NameSpaceof method"+"Method";

 org.apache.commons.httpclient.methods.PostMethod postMethod = new org.apache.commons.httpclient.methods.PostMethod("URL".trim());      postMethod.setRequestHeader("SOAPAction", soapAction);

 postMethod.setRequestHeader("Content-Type", "text/xml; charset=UTF-8");

 postMethod.setRequestHeader("SOAPAction", soapAction);

postMethod.setRequestHeader("User-Agent", userAgent);


postMethod.setRequestEntity(new org.apache.commons.httpclient.methods.StringRequestEntity(soapMessage.toString().trim(), "text/xml; charset=UTF-8", null));

String errorMessage ="";

String responseBodyString ="";


org.apache.commons.httpclient.NTCredentials ntCredentials = new org.apache.commons.httpclient.NTCredentials("Ravikumar-Punna", "xxxxxxx", "hostName", "NA");

client.getState().setCredentials(new org.apache.commons.httpclient.auth.AuthScope(null,-1,null), ntCredentials);

int status = client.executeMethod(postMethod);

if(status != org.apache.commons.httpclient.HttpStatus.SC_OK)

{

errorMessage = "Method Failed :" + postMethod.getStatusLine();

// System.out.println(errorMessage);

}

responseBodyString= postMethod.getResponseBodyAsString();

System.out.println("Response Message ;" +responseBodyString);


setVariableData("FantaticServiceResult", responseBodyString);

}catch(Exception e) {

}


 

 

This will call a NTML enabled external service .. simple :)

 

Jdeveloper Display line numbers in code editor

Quickest way to display line number in code editor , Right Click on  left hand side of code editor , then select "Toggle Line Numbers" . this will display line numbers in code editor - simple :)

 

Image

 

Have fun !