Quantcast
Channel: SCN : All Content - SAP Manufacturing
Viewing all articles
Browse latest Browse all 1079

HTTP call using "Destination" does not return InputStream

$
0
0

Using AS Java Destination configuration we are able to make HTTP call successfully.  But problem is to get the input stream back.

 

This problem occurs only when we use SAP service DestinationService. Code works perfectly when we make direct HTTP call without using destination. But second option can not be used as in this approach passing password will be problem.

 

Using Net weaver Destination service, it does not return the input stream response of HTTP call, though it makes the HTTP call and returns the response code 200 and message. The highlighted line gives Stream closed IO exception.

Code Using Destination

Context ctx = new InitialContext();
DestinationService dstService = (DestinationService)ctx.lookup(DestinationService.JNDI_KEY);
if (dstService == null){
throw new NamingException("Destination Service not available");
}
Destination destination = dstService.getDestination("HTTP","MII_HTTP");

HTTPDestination httpDestination = (HTTPDestination) destination;

httpDestination.setUrl(
"http://msplsa101.corp.medtronic.com:52000/XMII/Runner?Transaction=Default/Soumen/SendFile&FileName=abc.txt&FilePath=&OutputParameter=OutputXML");
HttpURLConnection httpConnection1 = httpDestination.getURLConnection("GET");

int responseCode = httpConnection1.getResponseCode();

  StringBuffer inputLine1 = new StringBuffer();
String input1 = "";
InputStream inputStream1 = httpConnection1.getInputStream();
BufferedReader bufferedReader1 = new BufferedReader(new InputStreamReader(inputStream1));
while ((input1 = bufferedReader1.readLine()) != null) {
inputLine1.append(input1);
}
bufferedReader1.close();


Second Approach without destination Works.

Code without using destination

URL url = new URL("http://msplsa101.corp.medtronic.com:52000/XMII/Runner?Transaction=Default/Soumen/SendFile&FileName=abc.txt&FilePath=&OutputParameter=OutputXML");
HttpURLConnection httpConnection2 = (HttpURLConnection)url.openConnection();

httpConnection2.setRequestMethod("GET");
httpConnection2.connect();
StringBuffer inputLine2 = new StringBuffer();
String input2 = "";
InputStream inputStream2 = httpConnection2.getInputStream();

  while ((input2 = bufferedReader2.readLine()) != null) {
inputLine2.append(input2);
}

 

Can some one tell me, why HTTP call using destination does not work? Is it making asynchronous call?

Thanks,

Soumen


Viewing all articles
Browse latest Browse all 1079

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>