cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

404 while consuming SOAP API in Java

0 Likes
735

Trying to integrate SAOP based API in Java. Getting 404.

Error

Response code 404
2020-09-30T10:54:08.752+0000 [APP/PROC/WEB/0] OUT 2020-09-30 10:54:08.752 ERROR 7 --- [nio-8080-exec-5] c.k.e.c.AccessOnPremService         : Response messsage Not Found
2020-09-30T10:54:08.752+0000 [APP/PROC/WEB/0] OUT 2020-09-30 10:54:08.752 ERROR 7 --- [nio-8080-exec-5] c.k.e.c.AccessOnPremService         : Connection URL http://xxx.xxxx.xxx.xx:443/xxxxxxx.asmx
2020-09-30T10:54:08.753+0000 [APP/PROC/WEB/0] ERR java.io.FileNotFoundException: http://xxx.xxxx.xxx.xx:443/xxxxxxx.asmx
2020-09-30T10:54:08.753+0000 [APP/PROC/WEB/0] ERR at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1896)
2020-09-30T10:54:08.753+0000 [APP/PROC/WEB/0] ERR at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1498)

Configuration steps are:

  1. Configured http://yy.yyyy.yyy.yy URL in the cloud connector
  2. Configured generated virtual host and port in the destination service
  3. Created connectivity service instance
  4. Passing proxy object as created in Connectivity host and port
String result = "";
int userId= 800202;
HttpURLConnection conn = null;
try {
URL urlObjcet = new URL("http://xxx.xxxx.xxx.xx:443/xxxxxxx.asmx");
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("<Connectivity host>", <port>));
conn = (HttpURLConnection) urlObjcet.openConnection(proxy);

//
ByteArrayOutputStream bout = new ByteArrayOutputStream();
String xmlInput =
" <soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">\n" +
" <soap12:Body>\n" +
"  <GetUserInfoById xmlns=\"http://tempuri.org/\">\n" +
" <userId>" + userId + "</userId>\n" +
" </GetUserInfoById>\n" +
" </soap12:Body>\n" +
" </soap12:Envelope>";

byte[] buffer = new byte[xmlInput.length()];
buffer = xmlInput.getBytes();
bout.write(buffer);
byte[] b = bout.toByteArray();
String soapAction =
"http://xxx.xxxx.xxx.xx:443/xxxxxxx.asmx?op=GetUserInfoById";

conn.setRequestProperty("Content-Length",
String.valueOf(b.length));
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
conn.setRequestProperty("SOAPAction", soapAction);
conn.setRequestProperty("Proxy-Authorization", "Bearer " + getAccessToken());

conn.setDoOutput(true);
conn.setDoInput(true);
OutputStream out = conn.getOutputStream();
//Write the content of the request to the outputstream of the HTTP Connection.
out.write(b);
out.close();
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.flush();
BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
String output;
while ((output = br.readLine()) != null) {
result = output;
System.out.print(result);
}

} catch (Exception e) {
try {
LOG.error("Response code {}", conn.getResponseCode());
LOG.error("Response messsage {}", conn.getResponseMessage());
LOG.error("Connection URL {}", conn.getURL());
} catch (IOException e1) {
e1.printStackTrace();
}

BufferedReader br = new BufferedReader(new InputStreamReader((conn.getErrorStream())));
String output;
try {
while ((output = br.readLine()) != null) {
result = output;
}
System.out.print("Error stream ---> "+result);
} catch (IOException e1) {
e1.printStackTrace();
}
e.printStackTrace();
result = "failure";
}
}

Kindly help us.

Accepted Solutions (0)

Answers (1)

Answers (1)

gregorw
SAP Mentor
SAP Mentor
0 Likes

I would suggest you deploy HTML5UserAPIforCF with the needed adjustments so you can call the SOAP Endpoint via the destination you have. So get rid of any complexity and check first if you can reach the on premise service via the Cloud Connector.