2017-03-01 25 views
0

我想從PL/SQL代碼調用webservice,它將接受itemnumber作爲輸入參數,並返回約8個輸出參數,其中一些是字符串而幾個將在base64binay編碼的PDF文件。從PL/SQL調用SOAP Web服務時獲取415不支持的介質類型錯誤

當我從SoapUI測試相同的WSDL時,它返回正確的響應。

但是在我的PL/SQL代碼中,我得到415 Unsupported Media Type Error。你能幫我解決這個問題嗎,我陷入了過去5天的這個錯誤。提前致謝。

下面是我的虛擬代碼,一旦它工作正常,那麼我需要轉換成一個適當的功能。

declare 
     soap_request varchar2(30000); 
     soap_respond CLOB; 
     soap_respond_temp CLOB; 
     http_req utl_http.req; 
     http_resp utl_http.resp; 
     l_resp XMLType; 
     i integer; 
     instr_start integer; 
     instr_end integer; 
     l_orgname varchar2(30000); 
     l_description   VARCHAR2(250); 
     l_long_description  VARCHAR2(1000); 
     l_segment1    VARCHAR2(250); 
     l_item_type    VARCHAR2(100); 
     l_isbn     VARCHAR2(100); 
     l_match_score   NUMBER; 
     l_pdh_id    NUMBER; 
     l_cross_reference_id NUMBER; 
     l_soap_request  CLOB; 
     l_soap_response CLOB; 
     l_soap_resp_raw LONG RAW; 
     l_buffer_size  NUMBER (10) := 512; 
     l_substring_msg VARCHAR2 (512); 
     l_string_request VARCHAR2 (512); 
     l_raw_data   RAW (512); 
     buffer    VARCHAR2 (32767); 
     i     NUMBER; 
     eob    BOOLEAN := FALSE; 
     resultvar VARCHAR2 (30000); 
    begin 
     --Item number 104PT is I/p parameter below to the SOAP webservice 
     soap_request:= '<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:grad="http://grades.web.spec.quality.asmorg.com/"> 
     <soap:Header/> 
     <soap:Body> 
      <grad:getGradeInfoForRM> 
      <strRMItem>104PT</strRMItem> 
      </grad:getGradeInfoForRM> 
     </soap:Body> 
    </soap:Envelope>';  
    http_req:= utl_http.begin_request 
       ('http://112.18.28.38:81/Itemspec/ItemGradeWSPort' 
       , 'POST' 
       , 'HTTP/1.1' 
       ); 
     utl_http.set_header(http_req, 'Content-Type', 'text/xml'); 
     utl_http.set_header(http_req, 'Content-Length', length(soap_request)); 
     utl_http.set_header(http_req, 'SOAPAction', ''); 
     utl_http.write_text(http_req, soap_request); 
     http_resp:= utl_http.get_response(http_req); 
    --dbms_output.put_line('got the soap response');  
    dbms_output.put_line('Response> status_code: "' ||http_resp.status_code || '"'); 
    dbms_output.put_line('Response> reason_phrase: "' ||http_resp.reason_phrase || '"'); 
    dbms_output.put_line('Response> http_version: "' ||http_resp.http_version || '"'); 
    DBMS_LOB.createtemporary (l_soap_response, TRUE); 
    fnd_file.put_line(fnd_file.log,'After create temporary'); 
    WHILE NOT (eob) 
     LOOP 
      BEGIN 
      dbms_output.put_line ('before read_text'); 
      UTL_HTTP.read_text (http_resp, buffer, 32767); 
      fnd_file.put_line(fnd_file.log,'Printing Buffer '||buffer); 
      dbms_output.put_line('Printing Buffer '||buffer); 
      IF buffer IS NOT NULL AND LENGTH (buffer) > 0 
      THEN 
       fnd_file.put_line(fnd_file.log,'Appending to l_soap_response using DBMS writeappend'); 
       dbms_output.put_line (' Appending to l_soap_response using DBMS writeappend'); 
       DBMS_LOB.writeappend (l_soap_response, LENGTH (buffer), buffer); 
      END IF; 
      EXCEPTION 
      WHEN UTL_HTTP.end_of_body 
      THEN 
      fnd_file.put_line(fnd_file.log,'end of body'); 
       eob := TRUE; 
      END; 
     END LOOP; 
    UTL_HTTP.end_response (http_resp); 
    fnd_file.put_line (fnd_file.log,'before XMLTYPE Call'); 
    dbms_output.put_line ('before XMLTYPE Call'); 
    l_resp := XMLTYPE.createxml (l_soap_response); 
    DBMS_LOB.freetemporary (l_soap_response); 
    fnd_file.put_line(fnd_file.log,'--after XMLTYPE Call'); 
    dbms_output.put_line ('after XMLTYPE Call'); 
    resultvar := l_resp.getstringval(); 
    fnd_file.put_line(fnd_file.log,'--after getstringval Call'); 
    fnd_file.put_line (fnd_file.log,resultvar); 
    fnd_file.put_line (fnd_file.log,'End DateTime:- ' || SYSTIMESTAMP); 
     EXCEPTION 
     WHEN UTL_HTTP.end_of_body THEN 
      dbms_output.put_line('end of body'); 
     UTL_HTTP.end_response(http_resp); 
      WHEN UTL_HTTP.TOO_MANY_REQUESTS THEN 
     UTL_HTTP.END_RESPONSE(http_resp); 
     WHEN OTHERS THEN 
      dbms_output.put_line('others eception '||SQLERRM); 
    end;  

這裏打印日誌消息:

響應> STATUS_CODE: 「415」 響應> reason_phrase:前XMLTYPE呼叫前read_text 「不支持的媒體類型」 別人eception ORA-31011:XML解析失敗 ORA-19202:在XML處理中發生錯誤 LPX-00229:輸入源爲空

回答

0

此問題現在已解決,問題在於設置標題並不適合按照SO AP web服務類型。

sys.UTL_HTTP.SET_HEADER(http_req, 'Content-Type', 'application/soap+xml;charset=UTF-8'); 
    utl_http.set_header(http_req, 'Content-Length', length(soap_request)); 
utl_http.set_header (http_req, 'Transfer-Encoding', 'chunked'); 
sys.utl_http.set_header(http_req, 'User-Agent', 'Apache-HttpClient/4.1.1 (java 1.5)'); 
    utl_http.set_header(http_req, 'SOAPAction', ''); 

這條線索有關正確的頭型,即「內容類型」和「用戶代理」,我從了SoapUI,而在尋找原始標籤了。

謝謝, Pradeep

相關問題