2 Replies Latest reply: Nov 20, 2012 6:17 PM by 950658 RSS

    Getting SOAException while calling SOA web service via pl/sql procedure

    950658
      Hi All,
      I created a 'Helloworld' BPEL process and successfuly deployed it. I tested it in the WLS and it is working. Now I wrote a pl/sql procedure which calls this 'HelloWorld' bpel process. When ran this procedure it throw me an error

      GetPayload: resp3 IS NULL
      <HTML><HEAD><TITLE>Web Service</TITLE></HEAD><BODY><H1>Bad Request</H1><PRE>javax.xml.soap.SOAPException: Error parsing envelope: most likely due to an invalid SOAP message.: Unexpected character &#39;&#60;&#39; &#40;code 60&#41; excepted space, or &
      #62;&#39; or &#34;/&#62;&#34;
      at [row,col {unknown&#45;source}]: [1,120]</PRE></BODY></HTML>
      null response
      GetPayload: resp3 IS NULL
      <HTML><HEAD><TITLE>Web Service</TITLE></HEAD><BODY><H1>Bad Request</H1><PRE>javax.xml.soap.SOAPException: Error parsing envelope: most likely due to an invalid SOAP message.: Unexpected character &#39;&#60;&#39; &#40;code 60&#41; excepted space, or &
      #62;&#39; or &#34;/&#62;&#34;
      at [row,col {unknown&#45;source}]: [1,120]</PRE></BODY></HTML>
      null response

      Please suggest.
      WSDL - http://herbalife-mwdv4-new.hrbl.net:21000/soa-infra/services/SAI/HTTP_BPEL/bpelprocesshttp_client_ep?WSDL

      procedure code is as below:

      Create or Replace FUNCTION GetPayload(
      p_Payload IN VARCHAR2)
      RETURN VARCHAR2 IS
      soap_request VARCHAR2(30000);
      soap_respond VARCHAR2(30000);
      http_req UTL_HTTP.REQ;
      http_resp UTL_HTTP.RESP;
      resp XMLTYPE;
      response VARCHAR2(30000) := '';
      l_detail VARCHAR2(30000);
      i INTEGER;
      l_xsl_nonamespace VARCHAR2(640) := '<?xml version="1.0" encoding="UTF-8" ?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="comment()|processing-instruction()|/"> <xsl:copy> <xsl:apply-templates/> </xsl:copy> </xsl:template> <xsl:template match="*"> <xsl:element name="{local-name()}"> <xsl:apply-templates select="@*|node()"/> </xsl:element> </xsl:template> <xsl:template match="@*"> <xsl:choose> <xsl:when test="name() != ''xmlns''"> <xsl:attribute name="{local-name()}"> <xsl:value-of select="."/> </xsl:attribute> </xsl:when> </xsl:choose> </xsl:template></xsl:stylesheet>';
      --
      namespace VARCHAR2(128) := 'xmlns:ns1="http://xmlns.oracle.com/FusionServices/HTTP_BPEL/BPELProcessHTTP';
      endpoint VARCHAR2(128) := 'http://herbalife-mwdv4-new.hrbl.net:21000/soa-infra/services/SAI/HTTP_BPEL/bpelprocesshttp_client_ep';
      BEGIN

      soap_request:= '<?xml version = "1.0" encoding = "UTF-8"?>'||'<SOAP-ENV:Envelope '||'xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"'||'<SOAP-ENV:Body>'||'<'||namespace||'>'||'<ProcessRequest>'||'<input'||namespace||'>'||p_Payload||'</input>'||'</ProcessRequest>'||'</SOAP-ENV:Body>'||'</SOAP-ENV:Envelope>';
      http_req := utl_http.begin_request( endpoint, 'POST', 'HTTP/1.1');
      utl_http.set_header(http_req , 'Content-Type' , 'text/xml');
      -- dealing with plain text in XML documents
      utl_http.set_header(http_req , 'Content-Length' , lengthb(soap_request));
      utl_http.set_header(http_req , 'SOAPAction' , 'process'); -- required to specify a SOAP communication
      utl_http.write_text(http_req, soap_request);
      http_resp := utl_http.get_response(http_req);
      utl_http.read_text(http_resp, soap_respond);
      utl_http.end_response(http_resp);
      resp:= XMLType.createXML(soap_respond);
      IF (instr(resp.getStringVal(), 'ERROR:') > 0)THEN
      raise_application_error ( -20999, 'GetHelloWorldPayload: Failed! '||p_Payload);
      END IF;
      resp := resp.extract('/soap:Envelope/soap:Body/child::node()' , 'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"' );
      -- Remove namespaces
      SELECT XMLTransform(resp, xmlType(l_xsl_nonamespace)) INTO resp FROM dual;
      --
      -- resp := resp.extract('/ProcessResponse/child::node()', 'xmlns:ns1="http://xmlns.oracle.com/FusionServices/HTTP_BPEL/BPELProcessHTTP');
      IF (resp IS NULL)THEN
      dbms_output.put_line('GetPayload: resp3 IS NULL');
      ELSE
      dbms_output.put_line('GetPayload: resp3 ' ||resp.getStringVal());
      END IF;
      --
      i:=0;
      LOOP
      dbms_output.put_line(SUBSTR(soap_respond,1+ i*255,250));
      i := i+1;
      IF i*250> LENGTH(soap_respond) THEN
      EXIT;
      END IF;
      END LOOP;
      IF (resp IS NULL)THEN
      response := 'null response';
      ELSE
      response := REPLACE( REPLACE( REPLACE( resp.getStringVal(), '<', '<') , '>', '>') , '"', '"');
      END IF;
      RETURN response;
      END GetPayload;
      /
        • 1. Re: Getting SOAException while calling SOA web service via pl/sql procedure
          vladodias
          Hi,

          You can eventually get it right doing the way you doing... But I recommend you try using UTL_DBWS PLSQL package rather than utl_http...
          http://orasoa.blogspot.com.au/2006/11/calling-bpel-process-with-utldbws.html

          Also, create xml representations by using string concatenation is to ask for trouble... Maybe good for a quick test but never for prod environment... Use DBMS_XMLDOM instead...
          http://docs.oracle.com/cd/E11882_01/appdev.112/e10492/xdb10pls.htm

          Hope this helps...

          Cheers,
          Vlad
          • 2. Re: Getting SOAException while calling SOA web service via pl/sql procedure
            950658
            vladodias thanks for the reply. I went through the link before also but i am not comfortable with the utl_dbws that's why i am following utl_http.
            I also changed my procedure now i am not getting any error but it is not printing the output as well. New procedure is as below.

            I tried 'set serveroutput on size 1000000;' also but still not working.

            Create or Replace FUNCTION GetPayload(
            p_Payload IN VARCHAR2)
            RETURN VARCHAR2 IS
            soap_request VARCHAR2(30000);
            soap_respond VARCHAR2(30000);
            http_req UTL_HTTP.REQ;
            http_resp UTL_HTTP.RESP;
            resp XMLTYPE;
            response VARCHAR2(30000) := '';
            l_detail VARCHAR2(30000);
            i INTEGER;
            l_xsl_nonamespace VARCHAR2(3000) := '<?xml version="1.0" encoding="UTF-8" ?>
            <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
            <xsl:template match="comment()|processing-instruction()|/">
            <xsl:copy>
            <xsl:apply-templates/>
            </xsl:copy>
            </xsl:template>
            <xsl:template match="*">
            <xsl:element name="{local-name()}">
            <xsl:apply-templates select="@*|node()"/>
            </xsl:element>
            </xsl:template>
            <xsl:template match="@*">
            <xsl:choose>
            <xsl:when test="name() != ''xmlns''">
            <xsl:attribute name="{local-name()}">
            <xsl:value-of select="."/>
            </xsl:attribute>
            </xsl:when>
            </xsl:choose>
            </xsl:template>
            </xsl:stylesheet>';
            --
            namespace VARCHAR2(128) := 'xmlns:ns1="http://xmlns.oracle.com/FusionServices/HTTP_BPEL/BPELProcessHTTP';
            endpoint VARCHAR2(128) := 'http://herbalife-mwdv4-new.hrbl.net:21000/soa-infra/services/SAI/HTTP_BPEL/bpelprocesshttp_client_ep';
            BEGIN
            soap_request:= '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:bpel="http://xmlns.oracle.com/FusionServices/HTTP_BPEL/BPELProcessHTTP">
            <soapenv:Header/>
            <soapenv:Body>
            <bpel:process>
            <bpel:input>test</bpel:input>
            </bpel:process>
            </soapenv:Body>
            </soapenv:Envelope>';
            http_req := utl_http.begin_request( endpoint, 'POST', 'HTTP/1.1');
            utl_http.set_header(http_req , 'Content-Type' , 'text/xml');
            -- dealing with plain text in XML documents
            utl_http.set_header(http_req , 'Content-Length' , lengthb(soap_request));
            utl_http.set_header(http_req , 'SOAPAction' , 'process'); -- required to specify a SOAP communication
            utl_http.write_text(http_req, soap_request);
            http_resp := utl_http.get_response(http_req);
            utl_http.read_text(http_resp, soap_respond);
            utl_http.end_response(http_resp);
            resp:= XMLType.createXML(soap_respond);
            IF (instr(resp.getStringVal(), 'ERROR:') > 0)THEN
            raise_application_error ( -20999, 'GetHelloWorldPayload: Failed! '||p_Payload);
            END IF;
            resp := resp.extract('/soap:Envelope/soap:Body/child::node()' , 'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"' );
            -- Remove namespaces
            SELECT XMLTransform(resp, xmlType(l_xsl_nonamespace)) INTO resp FROM dual;
            --
            -- resp := resp.extract('/ProcessResponse/child::node()', 'xmlns:ns1="http://xmlns.oracle.com/FusionServices/HTTP_BPEL/BPELProcessHTTP');
            IF (resp IS NULL)THEN
            dbms_output.put_line('GetPayload: resp3 IS NULL');
            ELSE
            dbms_output.put_line('GetPayload: resp3 ' ||resp.getStringVal());
            END IF;
            --
            i:=0;
            LOOP
            dbms_output.put_line(SUBSTR(soap_respond,1+ i*255,250));
            i := i+1;
            IF i*250> LENGTH(soap_respond) THEN
            EXIT;
            END IF;
            END LOOP;
            IF (resp IS NULL)THEN
            response := 'null response';
            ELSE
            response := REPLACE( REPLACE( REPLACE( resp.getStringVal(), '<', '<') , '>', '>') , '"', '"');
            END IF;
            RETURN response;
            END GetPayload;
            /