I have an application deployed to WebSphere 8.5 (the app is developed using java8/Spring 4) and every day I get many dump files, so I decided to analyze it using Eclipse Memory Analyzer and the result is:
The problem is I do not use axis for calling web service, I only use Jersy for Rest Web Services and The default jdk class SoapConnection for soap web services, here is some code examples: For Soap :
public String soapBind(List<ContextItem> dic, String serviceId, String urlWs, String applicationId) throws SOAPException, Exception {
try {
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();
SOAPMessage msg = soapCall(dic, serviceId, applicationId); // Send SOAP Message to SOAP Server
String url = urlWs;
LOGGER.info("CALLING WS ....");
SOAPMessage soapResponse = soapConnection.call(msg, url);
// print SOAP Response
//soapResponse.writeTo(System.out);
ByteArrayOutputStream out = new ByteArrayOutputStream();
soapResponse.writeTo(out);
soapConnection.close();
String strMsg = new String(out.toByteArray());
LOGGER.info("Response SOAP Message: {}",strMsg);
return strMsg;
} catch (SOAPException ex) {
throw ex;
} catch (UnsupportedOperationException ex) {
throw ex;
} catch (Exception ex) {
throw ex;
}
}
For Rest :
Client client = Client.create();
WebResource webResource = client
.resource(urlFicheClientProf);
//
ServiceContext serviceContext = this.getServiceContext();
//
ObjectMapper mapper = new ObjectMapper();
ClientResponse response = webResource
.queryParam("customerId", radical)
.queryParam("serviceContext",
URLEncoder.encode(mapper.writeValueAsString(serviceContext),
"UTF-8"))
.post(ClientResponse.class);
I am wondering why the Axis.Client Out of memory has occurred and how can I fix it. If anyone could help me figure it out I would be very grateful .
Using RestTemplate instead of SOAPConnection fixed the memory leaks :
final RestTemplate restTemplate = new RestTemplate();
final HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "text/xml");
final HttpEntity<String> request = new HttpEntity<>(message, headers);
final String result = restTemplate.postForObject(wsUrl, request, String.class);
return result;