Skip to Content
0

UPS webservice Error

Jun 02, 2017 at 06:17 AM

65

avatar image

Hello Experts,

I'm trying to consume UPS webservice from SAP and configured the logical port in SOAMANAGER using username and password.I'm not sure how to pass the username ,password and license token in the header part of webservice.I tried the code below but I'm getting 401 and 403 error..though I'm passing the correct username and password.If you have done a similar kind of development can you please share how you passed the username,password and access license to the Request in UPS webservice?

SPAN {
font-family: "Courier New";
font-size: 10pt;
color: #000000;
background: #FFFFFF;
}
.L0S31 {
font-style: italic;
color: #808080;
}
.L0S32 {
color: #3399FF;
}
.L0S33 {
color: #4DA619;
}
.L0S52 {
color: #0000FF;
}
.L0S55 {
color: #800080;
}
.L0S70 {
color: #808080;
}

*&---------------------------------------------------------------------*

*&

*& ---------------------------------------------------------------------*

*&

*&

*&---------------------------------------------------------------------*

************************************************************************

* Report demonstrates use of WS_HEADER protocol

************************************************************************



REPORT  /RB1A/test_ups.



DATA: interface TYPE REF TO /RB1A/CO_TRACK_PORT_TYPE1,

      request TYPE /RB1A/TRACK_REQUEST_MESSAGE1,

      response TYPE /RB1A/TRACK_RESPONSE_MESSAGE1,

      ws_header TYPE REF TO if_wsprotocol_ws_header,

      system_fault TYPE REF TO cx_ai_system_fault,

      flight_not_found TYPE REF TO cx_sxidag_flight_not_found,

      name TYPE string,

      namespace TYPE string.









data: lt_request type /RB1A/STRING_TAB4,

      ls_request like LINE OF lt_request.

ls_request = 1.

append ls_request to lt_request.





request-request-REQUEST_OPTION = lt_request.

request-INQUIRY_NUMBER = '1Z12345E1305277940'.



TRY.





*   create instance

    CREATE OBJECT interface

    EXPORTING

      LOGICAL_PORT_NAME = 'TEST1'.



*   get WS_HEADER protocol

    ws_header ?= interface->get_protocol('IF_WSPROTOCOL_WS_HEADER').



***************************************************************************

*   set somehow header as iXML-DOM tree

    DATA: ixml TYPE REF TO if_ixml,

          xml_document TYPE REF TO if_ixml_document,

          xml_root TYPE REF TO if_ixml_element,

          xml_element TYPE REF TO if_ixml_element,

          xml_node TYPE REF TO if_ixml_node.

    DATA l_xstring        TYPE xstring.

    DATA l_string         TYPE string.

    FIELD-SYMBOLS <fs_xstring> TYPE xstring.





   CONCATENATE



'<SOAP-ENV:Header >'

'<v1:UPSSecurity xmlns:v1="http://www.ups.com/XMLSchema/XOLTWS/UPSS/v1.0">'

'<v1:UsernameToken>'

'<v1:Username>*******</v1:Username>'

'<v1:Password>**************</v1:Password>'

'</v1:UsernameToken>'

'<v1:ServiceAccessToken>'

'<v1:AccessLicenseNumber>1CB80525F98C5155</v1:AccessLicenseNumber>'

'</v1:ServiceAccessToken>'

'</v1:UPSSecurity>'

'</SOAP-ENV:Header>'  INTO l_string.







*   convert to xstring

    l_xstring = cl_proxy_service=>cstring2xstring( l_string ).



    IF NOT l_string IS INITIAL.



*     create iXML DOM document from XML xstring

      CALL FUNCTION 'SDIXML_XML_TO_DOM'

        EXPORTING

           xml           = l_xstring

         IMPORTING

          document      = xml_document

         EXCEPTIONS

          invalid_input = 1

          OTHERS        = 2.



      IF sy-subrc = 0 AND NOT xml_document IS INITIAL.

        xml_root = xml_document->get_root_element( ).

        xml_element ?= xml_root->get_first_child( ).

*       add header element by element to SOAP header

        WHILE NOT xml_element IS INITIAL.

          name = xml_element->get_name( ).

          namespace = xml_element->get_namespace_uri( ).

          ws_header->set_request_header(

                      name = name

                      namespace = namespace

                      dom = xml_element ).



          xml_element ?= xml_element->get_next( ).

              ENDWHILE.

      ENDIF.

       ENDIF.





***************************************************************************

*   common coding....



*   call outbound

    CALL METHOD interface->PROCESS_TRACK

       EXPORTING

        TRACK_REQUEST = request

       IMPORTING

        TRACK_RESPONSE  = response.



***************************************************************************

*   if supported by WebService, -

*   here additional response header elements can be read

*   in this example we assume that the server has set the same header fields in

*   the response message.

    xml_element =  ws_header->get_response_header(

                            name = 'MessageHeader'

                           namespace = 'http://www.ebxml.org/namespaces/messageHeader' ).



    IF NOT xml_element IS INITIAL.

      PERFORM show_xml

         USING xml_element.

    ENDIF.



*   etc.....





  CATCH cx_ai_system_fault INTO system_fault.

    WRITE:/ 'System Fault'(sye).

    WRITE:/ system_fault->errortext.

    EXIT.

  CATCH cx_sxidag_flight_not_found INTO flight_not_found .

    WRITE:/ 'Requested flight not found'(fnf).

    EXIT.

  CATCH cx_ai_application_fault .

    WRITE:/ 'Application fault'(apf).

    EXIT.

ENDTRY.









*& --------------------------------------------------------------------*

*&           Form  show_Xml

*& --------------------------------------------------------------------*

*       text

*---------------------------------------------------------------------*

*         --> ELEMENT     text

*---------------------------------------------------------------------*

FORM show_xml

  USING element TYPE REF TO if_ixml_element.

  DATA:

      ixml_factory TYPE REF TO if_ixml,

      stream   TYPE REF TO if_ixml_ostream,

      encoding TYPE REF TO if_ixml_encoding,

      stream_factory TYPE REF TO if_ixml_stream_factory.



  DATA: l_x TYPE xstring, l_c TYPE string.



  ixml_factory =  cl_ixml=>create( ).

  stream_factory  = ixml_factory->create_stream_factory( ).

  encoding = ixml_factory->create_encoding( character_set = 'UTF-8'

                                      byte_order    = 0 ).

  stream = stream_factory->create_ostream_xstring( string = l_x ).

  stream->set_encoding( encoding = encoding ).



  element->render( ostream = stream ).



  cl_proxy_service=>show_xml_document( xml = l_x ).



ENDFORM.                     "show_Xml
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

0 Answers