t-code : sm49
- 실행 하고자 하는 command 입력 & 저장
- 필요한 parameter 입력
- 결과
- HTTP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | logger.info( "IF call Start" ); String address = ConnectionInfo.address; String parameter = URLEncoder.encode( "service" , "UTF-8" ) + "=" + URLEncoder.encode(ConnectionInfo.service, "UTF-8" ); parameter += "&" + URLEncoder.encode( "interface" , "UTF-8" ) + "=" + URLEncoder.encode(ConnectionInfo.poc0020interface, "UTF-8" ); parameter += "&" + URLEncoder.encode( "namespace" , "UTF-8" ) + "=" + URLEncoder.encode(ConnectionInfo.namespace, "UTF-8" ); parameter += "&" + URLEncoder.encode( "qos" , "UTF-8" ) + "=" + URLEncoder.encode( "BE" , "UTF-8" ); parameter += "&" + URLEncoder.encode( "sap-user" , "UTF-8" ) + "=" + URLEncoder.encode(ConnectionInfo.sapuser, "UTF-8" ); parameter += "&" + URLEncoder.encode( "sap-password" , "UTF-8" ) + "=" + URLEncoder.encode(ConnectionInfo.sappw, "UTF-8" ); address += parameter; logger.debug( "Call URL : " + address); URL url = new URL(address); URLConnection urlConnection = url.openConnection(); urlConnection.setDoOutput( true ); // post 설정 OutputStreamWriter wr = new OutputStreamWriter(urlConnection.getOutputStream()); wr.write(ReqXmlMsg); // body 데이터 입력 wr.flush(); // return 메세지 BufferedReader rd = new BufferedReader( new InputStreamReader(urlConnection.getInputStream(), "UTF-8" )); String returnDAta = "" ; String line = "" ; while ((line = rd.readLine()) != null ) { returnDAta += line; } logger.info( "IF call End" ); |
- HTTPS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | logger.info( "IF call Start" ); String address = ConnectionInfo.httpsAddress; String parameter = URLEncoder.encode( "service" , "UTF-8" ) + "=" + URLEncoder.encode(ConnectionInfo.service, "UTF-8" ); parameter += "&" + URLEncoder.encode( "interface" , "UTF-8" ) + "=" + URLEncoder.encode(ConnectionInfo.poc0020interface, "UTF-8" ); parameter += "&" + URLEncoder.encode( "namespace" , "UTF-8" ) + "=" + URLEncoder.encode(ConnectionInfo.namespace, "UTF-8" ); parameter += "&" + URLEncoder.encode( "qos" , "UTF-8" ) + "=" + URLEncoder.encode( "BE" , "UTF-8" ); parameter += "&" + URLEncoder.encode( "sap-user" , "UTF-8" ) + "=" + URLEncoder.encode(ConnectionInfo.sapuser, "UTF-8" ); parameter += "&" + URLEncoder.encode( "sap-password" , "UTF-8" ) + "=" + URLEncoder.encode(ConnectionInfo.sappw, "UTF-8" ); address += parameter; logger.debug( "Call URL : " + address); TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { public X509Certificate[] getAcceptedIssuers() { return null ; } public void checkClientTrusted(X509Certificate[] certs, String authType) { } public void checkServerTrusted(X509Certificate[] certs, String authType) { } } }; SSLContext sc = SSLContext.getInstance( "SSL" ); sc.init( null , trustAllCerts, new java.security.SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); HostnameVerifier hv = new HostnameVerifier() { @Override public boolean verify(String arg0, SSLSession arg1) { // TODO Auto-generated method stub return true ; } }; HttpsURLConnection.setDefaultHostnameVerifier((javax.net.ssl.HostnameVerifier) hv); URL url = new URL(address); HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection(); urlConnection.setRequestMethod( "POST" ); // post 설정 urlConnection.setDoOutput( true ); urlConnection.setDoInput( true ); OutputStreamWriter wr = new OutputStreamWriter(urlConnection.getOutputStream()); wr.write(ReqXmlMsg); // body 데이터 입력 wr.flush(); // return 메세지 BufferedReader rd = new BufferedReader( new InputStreamReader(urlConnection.getInputStream(), "UTF-8" )); String returnDAta = "" ; String line = "" ; while ((line = rd.readLine()) != null ) { returnDAta += line; } logger.info( "IF call End" ); |
If you have started using Java based HTTP sender adapter, either you might have spent some time in finding out how to pass user name and password in the query string or you might still be wondering how to pass user name and password in query string.
If you use sap-user and sap-password, you might have noticed that it is not working anymore and you would get authentication error "HTTP/1.1 401 Unauthorized".
Instead of sap-user, j_username can be used to pass username in query string.
Instead of sap-password, j_password can be used to pass password in query string.
The url should look like
http://<server>:<port>/HttpAdapter/HttpMessageServlet?interfaceNamespace=test.com&interface=Test_Out&senderService=TEST_BS&senderParty=&receiverParty=&receiverService=&qos=BE&j_username=testuser&j_password=testpwd
Additional details on Java based HTTP adapter test tool are available at PI 7.30 HTTP Java Adapter Test Tools.
Additiona details on configuring the Java HTTP sender adapter and URL details are available at AAE - Configuring the Java HTTP Adapter on the Sender Channel.
Caution: You should avoid using this method of authentication in your landscape. This short blog is written just to inform the readers on what parameter names to be used for user name and password in query string of http client that is sending request to Java HTTP adapter.