首页 > 解决方案 > 一种在 web 服务返回中禁用 Multipart / MTOM 的方法

问题描述

我正在使用 PL/SQL 过程连接到 Fusion / Oracle Cloud ERP WebService,一个使用 APEX API APEX_WEB_SERVICE,另一个使用 UTL_HTTP 包。

使用 SOAPUI 测试 Web 服务请求和响应时,它返回一个 XML,其中一个标记是另一个用 base64 编码的 XML,变成一个大字符串编码。

使用 PL/SQL 过程,Web 服务使用 XML 响应请求,但解码辅助 XML,并通知多部分内容的 http 标头,因此无法使用 APEX_WEB_SERVICE API 中的函数 make_request(因为函数的返回是正确格式的 XMLTYPE),并且需要大量工作来“清理”来自 UTL_HTTP 包的 clob 返回。

分析 SOAPUI 属性,我可以看到有一些属性指的是启用(或不启用)MTOM、强制(或不强制)MTOM、禁用多部分等。

是否有我可以发送到 Disable Multiparts / MTOM 的 http 标头或任何类型的参数?

我的代码

APEX_WEB_SERVICE API:

create or replace procedure prc_teste_webservice is
  l_envelope  CLOB;
  l_xml       XMLTYPE;
  l_result    VARCHAR2(32767);
  l_result_clob clob;
  v_txt    VARCHAR2(32767);
BEGIN

  -- Build a SOAP document appropriate for the web service.
  l_envelope := '<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ucm="http://www.oracle.com/UCM">
   <soapenv:Header/>
   <soapenv:Body>
      <ucm:GenericRequest webKey="cs">
         <ucm:Service IdcService="GET_FILE">
            <ucm:Document>
               <ucm:Field name="dID">33333</ucm:Field>
            </ucm:Document>
         </ucm:Service>
      </ucm:GenericRequest>
   </soapenv:Body>
</soapenv:Envelope>';

  l_xml := APEX_WEB_SERVICE.make_request(
    p_url      => 'https://host/idcws/GenericSoapPort',
    p_action   => 'GenericSoapOperation', 
    p_username => '*************',
    p_password => '*************',
    p_wallet_path => 'file:c:\app\Administrator\product\12.1.0\dbhome_1\wallet\',
    p_wallet_pwd => '************',
    p_envelope => l_envelope
  );

  l_result_clob := 'abcdefghij';

  -- Display the whole SOAP document returned.
  DBMS_OUTPUT.put_line('l_xml=' || l_xml.getClobVal());
  l_result_clob := l_xml.getClobVal();
  l_xml := xmltype.createxml(replace(replace(replace(replace(l_xml.getClobVal(), '&lt;', '<'), '&gt;', '>'), chr(13), ''), chr(10), ''));


  DBMS_OUTPUT.put_line('l_xml=' || l_result_clob);

END prc_teste_webservice;

UTL_HTTP:

create or replace procedure prc_wallet2 is
  l_envelope  CLOB;
  l_xml       XMLTYPE;
  l_result    VARCHAR2(32767);
  l_result_clob clob;
  v_txt    VARCHAR2(32767);
    soap_respond  CLOB;
    http_req      utl_http.req;
    http_resp     utl_http.resp;
    resp          XMLType;
    soap_err      exception;
    v_code        VARCHAR2(200);
    v_msg         VARCHAR2(1800);
    v_len number;
    v_txt Varchar2(32767);
BEGIN
  -- Build a SOAP document appropriate for the web service.
  l_envelope := '<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ucm="http://www.oracle.com/UCM">
   <soapenv:Header/>
   <soapenv:Body>
      <ucm:GenericRequest webKey="cs">
         <ucm:Service IdcService="GET_FILE">
            <ucm:Document>
               <ucm:Field name="dID">33333</ucm:Field>
            </ucm:Document>
         </ucm:Service>
      </ucm:GenericRequest>
   </soapenv:Body>
</soapenv:Envelope>';

  -- Make a HTTP request and get the response.
  utl_http.set_wallet('file:c:\app\Administrator\product\12.1.0\dbhome_1\wallet\', Null);
--  l_http_request  := UTL_HTTP.begin_request('https://www.google.com');
    http_req:= utl_http.begin_request
              ( 'https://host/idcws/GenericSoapPort'
              , 'POST'
              , 'HTTP/1.1'
              );
    UTL_HTTP.set_authentication(http_req, '******************', '*****************');
    utl_http.set_header(http_req, 'Content-Type', 'text/xml');
    utl_http.set_header(http_req, 'Content-Length', length(l_envelope));
    utl_http.set_header(http_req, 'SOAPAction', 'urn:GenericSoap/GenericSoapOperation');
    utl_http.write_text(http_req, l_envelope);


  http_resp := UTL_HTTP.get_response(http_req);

  -- Loop through the response.
  BEGIN
    LOOP
      UTL_HTTP.read_text(http_resp, l_result_clob);
      pkg_java.java_file_clob('c:\temp\teste1.txt', l_result_clob);
    END LOOP;
  EXCEPTION
    WHEN UTL_HTTP.end_of_body THEN
      UTL_HTTP.end_response(http_resp);
  END;
EXCEPTION
  WHEN OTHERS THEN
    UTL_HTTP.end_response(http_resp);
    RAISE;

end prc_wallet2;

标签: xmlweb-servicesplsqloracle-apex

解决方案


推荐阅读