Hi,
I am deploying my first Java App into HANA cloud.
What I want to do:
- My App tries to read from a remote wsdl and returns a JSON object containing the data I need.
So I thought I do a spring boot app and then deploy the WAR file into HANA cloud running on a Tomcat 7 container.
The problem I face is quite basic : I cannot read from the remote wsdl.
Reading through I found that I need to deal with Proxy settings or jndi resources.
I decided to go with the proxy approach.
I've got a controller that has got a WebServiceTemplate configured and try to call
webServiceTemplate.marshalSendAndReceive(login);
When doing so I got an exception in the browser:
I/O error: null; nested exception is org.apache.http.client.ClientProtocolException
In the logs I cannot see any other stacktrace.
The wsdl endpoint is a https resource. So I guess something is wrong with my configuration.
I set the proxy on the HttpClient within my Config class like:
public HttpClient getHttpClient() {
return HttpClientBuilder.create().setProxy(getProxy()).build();
}
private HttpHost getProxy() {
String proxyHost = System.getProperty("http.proxyHost");
int proxyPort = Integer.parseInt(System.getProperty("http.proxyPort"));
return new HttpHost(proxyHost, proxyPort);
}
The App is available under:
https://successfactorsap1941569231tria.hanatrial.ondemand.com/SuccessfactorsAPI-0.0.1-SNAPSHOT/XXX
Maybe somebody can tell me
a) why this happens
b) where can I find the entire stacktrace
and maybe
c) how can I fix the connectivity issue.
Thanks for your help.
Detlef
PS : My Controller and Config looks like:
package ch.prospective.successfactor;
import ch.prospective.successfactor.jaxb.*;
import com.sun.org.apache.xerces.internal.dom.ElementNSImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.ws.client.core.WebServiceTemplate;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
@RestController
public class SFController {
private static final String JOB_REQUISITION_TABLE = "JobRequisition";
public static final String IS_NOT_DELETED = "NO";
public static final String ATTR_IS_DELETED = "isDeleted";
@Autowired
private WebServiceTemplate webServiceTemplate;
@RequestMapping(method = RequestMethod.GET, value = "/{customer}", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<SFObject> getRequisitions(@PathVariable("customer") String customer) throws Exception {
System.out.println("Entering call for customer " + customer);
URLConnection urlConnection = new URL("http://www.google.de").openConnection(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(System.getProperty("http.proxyHost"), Integer.parseInt(System.getProperty("http.proxyPort")))));
System.out.println("content length: " + urlConnection.getContentLength());
try {
Login login = new Login();
SFCredential credential = new SFCredential();
credential.setCompanyId(customer);
credential.setUsername("xxxx");
credential.setPassword("xxxx");
login.setCredential(credential);
System.out.println("call login");
webServiceTemplate.marshalSendAndReceive(login);
System.out.println("end login");
System.out.println("call list");
ListSFObjectsResponse response = (ListSFObjectsResponse) webServiceTemplate.marshalSendAndReceive(new ListSFObjects());
System.out.println("end list");
String jobRequisitionTable = getJobRequisitionTable(response.getName());
...
return null
}
finally {
webServiceTemplate.marshalSendAndReceive(new Logout());
}
}
...
}
Config:
package ch.prospective.successfactor;
import com.sap.core.connectivity.api.DestinationException;
import org.apache.http.HttpHost;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.ws.client.core.WebServiceTemplate;
import org.springframework.ws.transport.http.HttpComponentsMessageSender;
import javax.naming.NamingException;
/**
*
*/
@Configuration
@EnableWebMvc
public class SFConfig extends WebMvcConfigurerAdapter {
@Bean
public WebServiceTemplate createWebServiceTemplate() throws NamingException, DestinationException {
WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
webServiceTemplate.setDefaultUri("https://api012.successfactors.eu:443/sfapi/v1/soap?wsdl");
webServiceTemplate.setMarshaller(getMarshaller());
webServiceTemplate.setUnmarshaller(getMarshaller());
HttpComponentsMessageSender messageSender = new HttpComponentsMessageSender();
webServiceTemplate.setMessageSender(messageSender);
messageSender.setHttpClient(getHttpClient());
return webServiceTemplate;
}
@Bean
public Jaxb2Marshaller getMarshaller() {
Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
jaxb2Marshaller.setPackagesToScan(new String[]{"ch.prospective.successfactor"});
return jaxb2Marshaller;
}
public HttpClient getHttpClient() {
return HttpClientBuilder.create().setProxy(getProxy()).build();
}
private HttpHost getProxy() {
String proxyHost = System.getProperty("https.proxyHost");
int proxyPort = Integer.parseInt(System.getProperty("https.proxyPort"));
System.out.println("https Proxy is: " + proxyHost + ":" + proxyPort);
System.out.println("http Proxy is: " + System.getProperty("http.proxyHost") + ":" + System.getProperty("http.proxyPort"));
return new HttpHost(proxyHost, proxyPort);
}
}