First try:
HttpClient client = HttpClientBuilder.create().build();
HttpGet request = new HttpGet(url);
The URL is a hardcoded String. This way the application works locally using the Tomcat server, but not when running on SAP Cloud Platform. On SCP it will result in Caused by: java.net.ConnectException: Connection timed out (Connection timed out) (local port 53603 to address 0.0.0.0, remote port 443 to address xxx.xxx.xxx.xxx
.
Second try:
Context ctx = new InitialContext();
HttpDestination destination = (HttpDestination) ctx.lookup("java:comp/env/myDestination");
HttpClient client = destination.createHttpClient();
using web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<display-name>myApp</display-name>
<resource-ref>
<res-ref-name>myDestination</res-ref-name>
<res-type>com.sap.core.connectivity.api.http.HttpDestination</res-type>
</resource-ref>
</web-app>
In this case the import com.sap.core.connectivity.api.http.HttpDestination;
cannot be resolved and when I run in ton SCP it shows similar errors:
with root cause java.lang.Error: Unresolved compilation problems:
HttpDestination cannot be resolved to a type
HttpDestination cannot be resolved to a type
FYI - Using neo-java-web-sdk-3.66.4.1 in Eclipse Oxygen.
Can you not use hardcoded URLs for an HTTPClient in a servlet?
How do I solve the com.sap.core.connectivity.api.http.HttpDestination
reference issue?
Can you still test an application locally if the code is using destinations?