How to post xml over HTTPS in java?

Vecincuncesiac

New Member
\[code\]<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"^M xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"^M xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"^M xmlns:xsd="http://www.w3.org/2001/XMLSchema"^M xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/07/secext">^M <env:Header>^M <wsse:Security>^M <wsse:UsernameToken>^M <wsse:Username>user</wsse:Username>^M <wsse:Password>pass</wsse:Password>^M </wsse:UsernameToken>^M </wsse:Security> ^M </env:Header>\[/code\]I have been told to post this xml to: https://www.abc.comI am also given the following method:\[code\]public int sendPostRequest(String url, String content, String contentType) throws Exception { PostMethod post = new PostMethod(url); post.setRequestEntity(new StringRequestEntity(content, contentType, null)); boolean success = false; String responseBody = null; int statusCode; try { getHttpClient().executeMethod(post); success = true; statusCode = post.getStatusCode(); responseBody = post.getResponseBodyAsString(); } catch (Exception ex) { log.error("Marhsalling exception : " + ex.getMessage()); throw new InvalidRequestException("Marhsalling exception :" + ex.getMessage()); } finally { post.releaseConnection(); } if ((statusCode != HttpStatus.SC_OK) && (statusCode != HttpStatus.SC_NO_CONTENT)) { String error = "Got Bad Http Status - <" + statusCode + "> Info : " + responseBody; log.error(error); throw new InvalidRequestException(error); } else { log.debug("Success - " + responseBody); } return statusCode; }private String footer = "</env:Envelope>"; private String message = "<InstallService><NewAccount></NewAccount></InstallService>"; private String payload = header + message + footer;\[/code\]header I have been told is the XML that I have posted. I am not sure about the content type, it was suggested that it could be XML. The project type should be the dynamic web project using the Tomcat server. I was also told to grab org.apache.commons.httpclient library.I have been trying to put the pieces together but I'm failing to. I get error at: getHttpClient(), saying that the method could not be resolved. It is same for log and InvalidRequestException could not be resolved. It seems that I have to extend my class to another class which would contain these three methods. Which class could it be? What jars could I be missing? A simple main method which calls the above method and passes the required arguments would work?
 
Back
Top