Posted: Tue Aug 07, 2012 8:36 am Post subject: вызов сервиса
Здравствуйте! Мне необходимо вызвать внешний web-сервис из ABAP программы.
При этом необходимо передать параметры: логин и пароль для доступа к сервису.
Как реализоватеть данную задачу?
*&---------------------------------------------------------------------*
*& Types and Data
*&---------------------------------------------------------------------*
DATA: http_client TYPE REF TO if_http_client ,
http_url TYPE string ,
p_content TYPE string .
*&---------------------------------------------------------------------*
*& Start of Selection
*&---------------------------------------------------------------------*
START-OF-SELECTION .
*Build the url string based on input
CONCATENATE 'http://www.webservicex.net/globalweather.asmx'
'/GetCitiesByCountry?CountryName='
p_cnt
INTO http_url .
http_client->request->set_header_field( name = '~request_method'
value = 'GET' ).
* Send the request
http_client->send( ).
* Reterive the result
CALL METHOD http_client->receive
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
OTHERS = 4.
p_content = http_client->response->get_cdata( ).
REPLACE ALL OCCURRENCES OF '<' IN p_content WITH '<' .
REPLACE ALL OCCURRENCES OF '>' IN p_content WITH '>' .
*&---------------------------------------------------------------------*
*& Processing the string
*&---------------------------------------------------------------------*
DATA : moff TYPE syst-tabix ,
moff1 TYPE syst-tabix ,
len TYPE syst-tabix .
DO .
FIND '<City>' IN SECTION OFFSET moff OF p_content IGNORING CASE MATCH OFFSET moff .
IF sy-subrc = 0 .
moff = moff + 6 .
FIND '</City>' IN SECTION OFFSET moff OF p_content IGNORING CASE MATCH OFFSET moff1 .
len = moff1 - moff .
WRITE : / p_content+moff(len) .
ELSE.
EXIT.
ENDIF.
ENDDO .
Вопрос как вызвать сервис, который требует ввода логина и пароля ??
Всем спасибо
Age: 170 Joined: 04 Oct 2007 Posts: 1218 Location: Санкт-Петербург
Posted: Tue Aug 07, 2012 9:18 am Post subject:
PopUP окно в абап программе с запросом имени и пароля не подойдет?
Потом передавайте пароль во внешний сервис. _________________ Молитва - это запрос разработчику на изменение кода программы.
Вопрос как вызвать сервис, который требует ввода логина и пароля ??
В общем случае зависит от сервиса - может он логин с паролем принимает как параметры. Может у него есть отдельный метод, в который передаются логин с паролем, а в ответ он возвращает токен, который нужно в дальнейшем передавать в заголовке с каждым запросом. Может еще какие то варианты.
Age: 170 Joined: 04 Oct 2007 Posts: 1218 Location: Санкт-Петербург
Posted: Tue Aug 07, 2012 12:59 pm Post subject:
Джокер wrote:
А как передать логин и пароль во внешний веб-сервис??
Как минимум внешний сервис нужно видеть.
Данные вы получаете через метод GET, передавайте POST. _________________ Молитва - это запрос разработчику на изменение кода программы.
REPLACE ALL OCCURRENCES OF
'<' IN WF_STRING1 WITH '<' .
REPLACE ALL OCCURRENCES OF
'>' IN WF_STRING1 WITH '>' .
REPLACE ALL OCCURRENCES OF
'xmlns=' IN WF_STRING1 WITH 'xmlns:xsl=' .
TRY .
CALL TRANSFORMATION (`Y_CURR_XML2ABAP`)
SOURCE XML WF_STRING1
RESULT OUTTAB = OUTTAB.
CATCH CX_XSLT_EXCEPTION INTO XSLT_ERR.
DATA: S TYPE STRING.
S = XSLT_ERR->GET_TEXT( ).
WRITE: ': ', S.
STOP.
ENDTRY .
* LOOP AT OUTTAB INTO WA_OUTTAB .
WRITE:/ 'Moeda Origem', V_FROM.
WRITE:/ 'Moeda destino', V_TO.
WRITE:/ 'Taxa de conversão', OUTTAB.
WRITE:/ 'Data da conversão', SY-DATUM.
* ENDLOOP .
Code:
XSLT file for program example one
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:strip-space elements="*"/>
<xsl:output indent="yes"/>
<xsl:template match="ConversionRateResult">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<OUTTAB>
<xsl:value-of select= "."/>
</OUTTAB>
</asx:values>
</asx:abap>
</xsl:template>
</xsl:stylesheet>
Code:
*Program EXAMPLE TWO
*&---------------------------------------------------------------------*
*& Report Y_CONSUME_WEBSERVICE *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT Y_CONSUME_WEBSERVICE .
DATA: WF_USER TYPE STRING .
DATA: WF_PASSWORD TYPE STRING .
TYPES: BEGIN OF OUTTAB1 ,
AIRPORTCODE(6) ,
CITYOFAIRPORTNAME(50),
COUNTRY(30) ,
COUNTRYABBRIVATION(10),
COUNTRYCODE(6) ,
GMTOFFSET(10) ,
RUNWAYLENGTHFEET(15),
RUNWAYELEVATIONFEET(15),
LATITUDEDEGREE(10) ,
LATITUDEMINUTE(10) ,
LATITUDESECOND(10) ,
LATITUDENPEERS(10) ,
LONGITUDEDEGREE(10) ,
LONGITUDEMINUTE(10) ,
LONGITUDESECONDS(10) ,
LONGITUDEEPERW(10) ,
END OF OUTTAB1 .
DATA: OUTTAB TYPE TABLE OF OUTTAB1.
DATA: WA_OUTTAB TYPE OUTTAB1.
DATA: WF_O LIKE LINE OF OUTTAB .
DATA: XSLT_ERR TYPE REF TO CX_XSLT_EXCEPTION .
DATA: RLENGTH TYPE I,
TXLEN TYPE STRING .
DATA: HTTP_CLIENT TYPE REF TO IF_HTTP_CLIENT .
DATA: WF_STRING TYPE STRING .
DATA: WF_STRING1 TYPE STRING .
DATA: WF_PROXY TYPE STRING ,
WF_PORT TYPE STRING .
SELECTION-SCREEN: BEGIN OF BLOCK A WITH FRAME .
PARAMETERS: COUNTRY(2) TYPE C LOWER CASE .
SELECTION-SCREEN SKIP 1.
PARAMETERS: USER(50) LOWER CASE,
PASSWORD(50) LOWER CASE ,
P_PROXY(100) LOWER CASE DEFAULT 'mt01proxy.multibras.com.br' ,
P_PORT(4) DEFAULT '8081'.
SELECTION-SCREEN: END OF BLOCK A .
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF SCREEN-NAME = 'PASSWORD'.
SCREEN-INVISIBLE = '1'.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
START-OF-SELECTION .
CLEAR WF_STRING .
CONCATENATE '<?xml version="1.0" encoding="utf-8"?>' '<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>'
'<GetAirportInformationByCountry xmlns="http://www.webserviceX.NET">'
'<country>' COUNTRY '</country>'
'</GetAirportInformationByCountry>'
'</soap:Body>'
'</soap:Envelope>' INTO WF_STRING .
CLEAR :RLENGTH , TXLEN .
RLENGTH = STRLEN( WF_STRING ) .
MOVE: RLENGTH TO TXLEN .
CLEAR: WF_PROXY, WF_PORT .
MOVE: P_PROXY TO WF_PROXY ,
P_PORT TO WF_PORT .
REPLACE ALL OCCURRENCES OF
'<' IN WF_STRING1 WITH '<' .
REPLACE ALL OCCURRENCES OF
'>' IN WF_STRING1 WITH '>' .
REPLACE ALL OCCURRENCES OF
'xmlns=' IN WF_STRING1 WITH 'xmlns:xsl=' .
TRY .
CALL TRANSFORMATION (`Y_AIRPORT_XML2ABAP`)
SOURCE XML WF_STRING1
RESULT OUTTAB = OUTTAB.
CATCH CX_XSLT_EXCEPTION INTO XSLT_ERR.
DATA: S TYPE STRING.
S = XSLT_ERR->GET_TEXT( ).
WRITE: ': ', S.
STOP.
ENDTRY .
LOOP AT OUTTAB INTO WA_OUTTAB .
WRITE:/ WA_OUTTAB .
ENDLOOP .
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.