Home » SQL & PL/SQL » SQL & PL/SQL » Consuming a webservice by UTL_HTTP (10g)
Consuming a webservice by UTL_HTTP [message #456333] Mon, 17 May 2010 05:34 Go to next message
ayush_anand
Messages: 417
Registered: November 2008
Senior Member
DECLARE
   TYPE cn_request_rec IS RECORD (
      cn_method      VARCHAR2 (256),
      cn_namespace   VARCHAR2 (256),
      cn_body        VARCHAR2 (32767)
   );

   TYPE cn_response_rec IS RECORD (
      cn_response_xml   XMLTYPE
   );

   FUNCTION new_request (method IN VARCHAR2, namespace IN VARCHAR2)
      RETURN cn_request_rec
   AS
      req   cn_request_rec;
   BEGIN
      req.cn_method := method;
      req.cn_namespace := namespace;
      RETURN req;
   END;

   PROCEDURE add_soap_parameter (
      req         IN OUT NOCOPY   cn_request_rec,
      par_name    IN              VARCHAR2,
      par_type    IN              VARCHAR2,
      par_value   IN              VARCHAR2
   )
   AS
   BEGIN
      req.cn_body :=
            req.cn_body
         || '<'
         || par_name
         || ' xsi:type="'
         || par_type
         || '">'
         || par_value
         || '</'
         || par_name
         || '>';
   END;

--
--
   PROCEDURE generate_envelope (
      req   IN OUT NOCOPY   cn_request_rec,
      env   IN OUT NOCOPY   VARCHAR2
   )
   AS
   BEGIN
      env :=
         '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
                         ||'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
                         ||'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'
          ||'<soap:Body><GetBibleWordsByBookTitleAndChapter xmlns="http://www.webserviceX.NET">'
          ||'<BookTitle>Nehemiah</BookTitle><chapter>1</chapter>'
          ||'</GetBibleWordsByBookTitleAndChapter> </soap:Body></soap:Envelope>';
      DBMS_OUTPUT.put_line (env);
   END;

   PROCEDURE check_fault (resp IN OUT NOCOPY cn_response_rec)
   AS
      fault_node     XMLTYPE;
      fault_code     VARCHAR2 (256);
      fault_string   VARCHAR2 (32767);
   BEGIN
      fault_node :=
         resp.cn_response_xml.EXTRACT
                     ('/soap:Fault',
                      'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/'
                     );

      IF (fault_node IS NOT NULL)
      THEN
         fault_code :=
            fault_node.EXTRACT
                     ('/soap:Fault/faultcode/child::text()',
                      'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/'
                     ).getstringval ();
         DBMS_OUTPUT.put_line ('fault_code ' || fault_code);
         fault_string :=
            fault_node.EXTRACT
                      ('/soap:Fault/faultstring/child::text()',
                       'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/'
                      ).getstringval ();
         DBMS_OUTPUT.put_line ('fault_string ' || fault_string);
         raise_application_error (-20021, fault_code || ' - ' || fault_string);
      END IF;
   END;

   FUNCTION invoke (
      req      IN OUT NOCOPY   cn_request_rec,
      url      IN              VARCHAR2,
      action   IN              VARCHAR2
   )
      RETURN cn_response_rec
   AS
      env         VARCHAR2 (32767);
      http_req    UTL_HTTP.req;
      http_resp   UTL_HTTP.resp;
      resp        cn_response_rec;
   BEGIN
      generate_envelope (req, env);
      http_req := UTL_HTTP.begin_request (url, 'POST', 'HTTP/1.1');
      UTL_HTTP.set_header (http_req, 'Content-Type',
                           'text/xml;charset=UTF-8');
      UTL_HTTP.set_header (http_req, 'Content-Length', LENGTHB (env));
      UTL_HTTP.set_header (http_req, 'SOAPAction', action);
      UTL_HTTP.write_text (http_req, env);
      http_resp := UTL_HTTP.get_response (http_req);

      BEGIN
         UTL_HTTP.read_text (http_resp, env);
      EXCEPTION
         WHEN UTL_HTTP.end_of_body
         THEN
            UTL_HTTP.end_response (http_resp);
      END;

      IF env IS NULL
      THEN
         raise_application_error (-20022, 'ERROR: SOAP response is null.');
      END IF;

      UTL_HTTP.end_response (http_resp);
      resp.cn_response_xml := XMLTYPE.createxml (env);
      resp.cn_response_xml :=
         resp.cn_response_xml.EXTRACT
                     ('/soap:Envelope/soap:Body/child::node()',
                      'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"'
                     );
      check_fault (resp);
      RETURN resp;
   END;

   FUNCTION get_return_value (
      resp        IN OUT NOCOPY   cn_response_rec,
      NAME        IN              VARCHAR2,
      namespace   IN              VARCHAR2
   )
      RETURN VARCHAR2
   AS
   BEGIN
      RETURN resp.cn_response_xml.EXTRACT ('//' || NAME || '/text()',
                                           namespace
                                          ).getstringval ();
   END;

   FUNCTION get_cn_status (cancel_msg IN VARCHAR)
      RETURN VARCHAR
   IS
      req                         cn_request_rec;
      resp                        cn_response_rec;
      soap_response               VARCHAR2 (500);
      fault_node                  EXCEPTION;
      PRAGMA EXCEPTION_INIT (fault_node, -20021);
      soap_resp_null              EXCEPTION;
      PRAGMA EXCEPTION_INIT (soap_resp_null, -20022);
      gedis_wallet_lookup_error   EXCEPTION;
      gedis_lookup_error          EXCEPTION;
      ws_cn_link                  VARCHAR2 (240);
      l_cancel_status_name        VARCHAR2 (32000);
      l_len                       NUMBER;
      l_max                       NUMBER;
      l_str                       LONG;
--      v_wallet_dir              gedis_lookups.meaning%TYPE;
   BEGIN
      req :=
         new_request ('GetBibleWordsbyKeyWord',
                      'xmlns="http://www.webserviceX.NET"'
                     );
--   FUNCTION new_request ( method      IN   VARCHAR2, namespace   IN   VARCHAR2 )
      ws_cn_link := 'http://www.webservicex.net/BibleWebservice.asmx';
                                                                      -- otc2d
      resp :=
         invoke
            (req,
             ws_cn_link,
             '"http://www.webserviceX.NET/GetBibleWordsByBookTitleAndChapter"'
            );
      DBMS_OUTPUT.put_line ('printing..');
      l_str := resp.cn_response_xml.EXTRACT ('/*').getstringval ();

      LOOP
         EXIT WHEN l_str IS NULL;
         DBMS_OUTPUT.put_line (SUBSTR (l_str, 1, INSTR (l_str, CHR (10)) - 1));
         l_str := SUBSTR (l_str, INSTR (l_str, CHR (10)) + 1);
      END LOOP;

      RETURN 'a';
   END;
BEGIN
   DBMS_OUTPUT.put_line (get_cn_status ('A'));
END;                                                           -- Package body
/

The above code throws this error ,Any help will be good
DECLARE
*
ERROR at line 1:
ORA-29273: HTTP request failed
ORA-06512: at "SYS.UTL_HTTP", line 1029
ORA-12535: TNS:operation timed out
ORA-06512: at line 99
ORA-06512: at line 170
ORA-06512: at line 188


I got this from google

http://www.dbmotive.com/oracle_error_codes.php?errcode=12535

my ping does not works probably some proxy settings

but can you check from your end if this is working at your box.




CM: Multi-lined the line that sets the env variable so you don't have to scroll the page right.

[Updated on: Mon, 17 May 2010 07:04] by Moderator

Report message to a moderator

Re: Consuming a webservice by UTL_HTTP [message #456340 is a reply to message #456333] Mon, 17 May 2010 06:22 Go to previous messageGo to next message
delna.sexy
Messages: 941
Registered: December 2008
Location: Surat, The Diamond City
Senior Member
Once upon a time, I used UTL_HTTP to read some online data. But I was using it in Oracle 11g R1 with all ACL settings. At that time, I directly used REQUEST and REQUEST_PIECES and was working very well.

regards,
Delna
Re: Consuming a webservice by UTL_HTTP [message #456372 is a reply to message #456333] Mon, 17 May 2010 09:23 Go to previous messageGo to next message
BlackSwan
Messages: 20085
Registered: January 2009
Senior Member
>ORA-12535: TNS:operation timed out
Most likely, an external networking problem exists & root cause is not Oracle related.

Oracle is victim; not culprit.
Re: Consuming a webservice by UTL_HTTP [message #456521 is a reply to message #456372] Tue, 18 May 2010 05:06 Go to previous messageGo to next message
ayush_anand
Messages: 417
Registered: November 2008
Senior Member
declare
service_ sys.utl_dbws.SERVICE;
call_ sys.utl_dbws.CALL;
service_qname sys.utl_dbws.QNAME;
port_qname sys.utl_dbws.QNAME;
operation_qname sys.utl_dbws.QNAME;
string_type_qname sys.utl_dbws.QNAME;
retx ANYDATA;
retx_string VARCHAR2(100);
retx_double number;
retx_len number;
params sys.utl_dbws.ANYDATA_LIST;
l_RET_QNAME_LIST sys.utl_dbws.QNAME_LIST;
l_input_params SYS.UTL_DBWS.anydata_list;
l_result ANYDATA;
l_namespace varchar2(1000);
begin
l_namespace := 'http://www.dataaccess.com/webservicesserver/';
--sys.utl_dbws.set_http_proxy('192.168.1.1:80');
service_qname := sys.utl_dbws.to_qname(l_namespace, 'NumberConversion');
service_ := sys.utl_dbws.create_service(HTTPURITYPE('http://www.dataaccess.com/webservicesserver/numberconversion.wso?WSDL'), service_qname);
port_qname := sys.utl_dbws.to_qname(l_namespace, 'NumberConversionSoap');
operation_qname := sys.utl_dbws.to_qname(l_namespace, 'NumberToWords');
call_ := sys.utl_dbws.create_call(service_, port_qname, operation_qname);
sys.utl_dbws.set_property(call_, 'SOAPACTION_USE', 'TRUE');
sys.utl_dbws.set_property(call_, 'SOAPACTION_URI', '');
--sys.utl_dbws.set_property(call_, 'ENCODINGSTYLE_URI', --'http://schemas.xmlsoap.org/soap/encoding/');
sys.utl_dbws.set_property(call_, 'OPERATION_STYLE', 'rpc');
string_type_qname := sys.utl_dbws.to_qname('http://www.w3.org/2001/XMLSchema', 'string');
sys.utl_dbws.add_parameter(call_, 'ubiNum', string_type_qname, 'ParameterMode.IN');
sys.utl_dbws.set_return_type(call_, string_type_qname);
params(0) := ANYDATA.convertvarchar('12345');
retx := sys.utl_dbws.invoke(call_, params);
retx_string := retx.accessvarchar2;
dbms_output.put_line('PL/SQL DII client return ' || retx_string);
sys.utl_dbws.release_service(service_);
end;
/



I tried this and this works fine from my home(no proxy)

I tried the same from office (god knows what proxy)
declare
*
ERROR at line 1:
ORA-29532: Java call terminated by uncaught Java exception:
java.lang.IllegalAccessException: error.build.wsdl.model:
oracle.j2ee.ws.common.tools.api.WsdlValidationException: WSDLException:
faultCode=PARSER_ERROR: Error reading file at:
http://www.dataaccess.com/webservicesserver/numberconversion.wso?WSDL:
Connection refused
ORA-06512: at "SYS.UTL_DBWS", line 159
ORA-06512: at "SYS.UTL_DBWS", line 156
ORA-06512: at line 21


Any ideas how to know the proxy getting used?

[Updated on: Tue, 18 May 2010 05:07]

Report message to a moderator

Re: Consuming a webservice by UTL_HTTP [message #456524 is a reply to message #456521] Tue, 18 May 2010 05:16 Go to previous messageGo to next message
cookiemonster
Messages: 9135
Registered: September 2008
Location: Rainy Manchester
Senior Member
Ask your network admin people?
Re: Consuming a webservice by UTL_HTTP [message #456545 is a reply to message #456521] Tue, 18 May 2010 07:35 Go to previous messageGo to next message
delna.sexy
Messages: 941
Registered: December 2008
Location: Surat, The Diamond City
Senior Member
Quote:
god knows what proxy

Laughing
That god is network Admin...

regards,
Delna
Re: Consuming a webservice by UTL_HTTP [message #456557 is a reply to message #456545] Tue, 18 May 2010 08:23 Go to previous messageGo to next message
rahulvb
Messages: 924
Registered: October 2009
Location: Somewhere Near Equator.
Senior Member
Very Happy
Re: Consuming a webservice by UTL_HTTP [message #456558 is a reply to message #456557] Tue, 18 May 2010 08:24 Go to previous messageGo to next message
ayush_anand
Messages: 417
Registered: November 2008
Senior Member
Guys are you interested in technical part of question or just increasing your message count ?
Re: Consuming a webservice by UTL_HTTP [message #456568 is a reply to message #456558] Tue, 18 May 2010 09:04 Go to previous messageGo to next message
BlackSwan
Messages: 20085
Registered: January 2009
Senior Member
>Guys are you interested in technical part of question or just increasing your message count ?

yes

Be patient while we collect details about the proxy on YOUR network
Re: Consuming a webservice by UTL_HTTP [message #456572 is a reply to message #456545] Tue, 18 May 2010 09:14 Go to previous messageGo to next message
ayush_anand
Messages: 417
Registered: November 2008
Senior Member
I suspected proxy issue but it may be due to any other issue as well .But you people are interested in increasing your messages by posting the same thing.

Foruming,Waste of time(my and yours as well) I guess.
Re: Consuming a webservice by UTL_HTTP [message #456574 is a reply to message #456572] Tue, 18 May 2010 09:21 Go to previous message
cookiemonster
Messages: 9135
Registered: September 2008
Location: Rainy Manchester
Senior Member
Well if it works in one place and not the other, what you do expect us to conclude other than network issues?
Network issues are a problem for your network people to sort out not us.
If you actually know of another issue with this then post the details and we'll have a look but otherwise there doesn't appear to be anything for us to do.
Previous Topic: problem with tcp/ip communication between client and server
Next Topic: How to use Substitution Variables in FROM phrase?
Goto Forum:
  


Current Time: Sat May 18 17:43:29 CDT 2013

Total time taken to generate the page: 0.56606 seconds