Friday, July 20, 2012

Java webservice considering the space/newline characters as an element


Java webservice considering the space/newline characters as an element

We have developed a java webservice to convert the xml to fixed length payload; unfortunately it was failing with Class cast Exception.

<faultstring>java.lang.String cannot be cast to javax.xml.bind.JAXBElement</faultstring>

 
After debugging we have identified the parser considering the new line character in the XML payload as the JAXBElement.

 
We tried removing the new line characters and the spaces in the xml payload and it worked fine.



After a long struggle we have identified the root cause.

Wednesday, July 18, 2012

Undeploying SOA Composite while soa-infra is down in Oracle SOA Suite

Undeploying SOA Composite while soa-infra is down in Oracle SOA Suite:

Recently we had an issue with soa-infra start-up, soa-infra application won’t come up due to corrupt composite. 

We have followed the Meta link note 1380835.1 to un-deploy the corrupted composite and bring up the soa-infra application.

Thought of sharing the same here, it may help whoever facing the same issue.

The SOA composites can’t be un-deployed when the soa-infra application. The below steps will help you to un-deploy the SOA composites when the soa-infra application is down.
  • First check the soa logs and identify which composite is causing the problem
  • Download and copy the ShareSoaInfraPartition.ear file to $MWHOME/Oracle_SOA/common/bin
  • Execute $MWHOME/Oracle_SOA/common/bin/wlst.sh
  •  connect()
             Provide username, password and server URL
  • Run the below command to deploy ShareSoaInfraPartition.ear
                 deploy('ShareSoaInfraPartition','ShareSoaInfraPartition.ear',upload='true')
  • Now run the below command by changing the "toLocation" ('/fmw11g/Middleware' is some location path on SOA machine)
   exportMetadata(application='ShareSoaInfraPartition',server='AdminServer',toLocation='/fmw11g/Middleware',docs='/deployed-composites/deployed-composites.xml')
A deployed-composites folder will be created at "toLocation" path with deployed-composites.xml in it
  • Delete the composite which is causing the problem from deployed-composites.xml and save the file
          for example FormatDate composite like below
            <composite-series name="default/FormatDate" default="default/FormatDate!1.0">
                  <composite-revision dn="default/FormatDate!1.0" state="on" mode="active"   location="dc/soa_b8c8782b-776e-42c3-8519-d29fdfb72032">
                 <composite dn="default/FormatDate!1.0*soa_b8c8782b-776e-42c3-8519-d29fdfb72032"  deployedTime="2012-07-11T04:14:47.665-07:00"/>
                </composite-revision>
            </composite-series>
  • Now run the below command by changing the "fromLocation" (this should be the same location as previous)
            importMetadata(application='ShareSoaInfraPartition',server='AdminServer',fromLocation='/fmw11g/fmw1115/Middleware',docs='/deployed-composites/deployed-composites.xml')

 Now bounce your server and the composite will not be deployed by SOA when it comes up and hence that should bring your soa-infra up.

DOWNLOAD ShareSoaInfraPartition.zip

Creating a wlfullclient.jar - Weblogic

Creating a wlfullclient.jar for JDK 1.6 client applications from weblogic server

    Change directories to the server/lib directory.

    cd WL_HOME/server/lib

    Use the following command to create wlfullclient.jar in the server/lib directory:

    java -jar wljarbuilder.jar

    You can now copy and bundle the wlfullclient.jar with client applications.

Creating a wlfullclient5.jar for JDK 1.5 client applications:

    Change directories to the server/lib directory.

    cd WL_HOME/server/lib

    Use the following command to create wlfullclient.jar in the server/lib directory:

    java -jar wljarbuilder.jar -profile wlfullclient5

    You can now copy and bundle the wlfullclient5.jar with client applications.

Monday, July 16, 2012

Retrieving the XML payload in Java Servlet

Retrieving the XML payload in Java Servlet:

If the request content type is text/xml and the method is POST, we can use the below code to retrieve the xml payload in servlet.

    public void doPost(HttpServletRequest request,
                       HttpServletResponse response) throws ServletException,
                                                            IOException {
        response.setContentType(CONTENT_TYPE);
        PrintWriter out = response.getWriter();
        BufferedReader br = request.getReader(); 
            String line = null; 
            StringBuffer inputXML = new StringBuffer(); 
            PrintWriter pout = response.getWriter(); 
             
            while ((line = br.readLine()) != null) { 
                inputXML.append(line); 
            } 
            br.close();
           
            System.out.println("Input "+inputXML);
           
        java.io.InputStream sbis = new java.io.StringBufferInputStream(inputXML.toString());

        javax.xml.parsers.DocumentBuilderFactory b = javax.xml.parsers.DocumentBuilderFactory.newInstance();
        b.setNamespaceAware(false);
        org.w3c.dom.Document doc = null;
        javax.xml.parsers.DocumentBuilder db = null;

        try {
            db = b.newDocumentBuilder();
            doc = db.parse(sbis);
        } catch (Exception e) {
            e.printStackTrace();
        }
     
        org.w3c.dom.Element element = doc.getDocumentElement();
       
        String empName=getPayloadValue(element, "EmpName");
        String empNo=getPayloadValue(element, "EmpNo");
     
      
       String output="<EmployeeCollection xmlns=\"http://xmlns.oracle.com/HttpAdapter/InvokeServlet/InvokeServlet\"><Employee><EmpName>"+empName+"</EmpName><EmpNo>"+empNo+"</EmpNo><EmpAge>27</EmpAge></Employee><Employee><EmpName>"+empName+"</EmpName><EmpNo>"+empNo+"</EmpNo><EmpAge>28</EmpAge></Employee></EmployeeCollection>";
       out.write(output);
        out.close();
    }

    public String getPayloadValue(Element taskPayloadElement, String nodeName){
       
     String output= "";  
    NodeList nodeList = taskPayloadElement.getElementsByTagName(nodeName);
    if(nodeList!=null && nodeList.getLength() > 0){
    Element myElement = (Element)nodeList.item(0);
    output= myElement.getFirstChild().getNodeValue();
    }
    return output;
   
}

Java utility to test the business rule with out deploying to server – Oracle SOA Suite

Java utility to test the business rule with out deploying to server – Oracle SOA Suite

This blog will explain how to use the Java API to test the Oracle Business rule with out deploying to server in Oracle SOA Suite. This utility will read the input from the XML file and generate the output XML.

Download the utility OracleBusinessRuleTester.rar

Steps to execute the utility from JDeveloper:

  • Unzip OracleBusinessRuleTester.rar and import the project to JDeveloper
  • Open OrderRequestRuleTester.java in JDeveloper
  • Change the value OrderLineRequestDictionary141008 with the package name of the JAXB classes e.g. com.rule.test (in my case the package name is OrderLineRequestDictionary141008).
  •   The package name can be seen in the .rule file, open the .rule file in text editor and search for JaxbFactType