Send xml message over HTTP POST



I require to send an HL7 message, which is parsed into an XML message to the below end point.



  • Host: iol.sandbox.ohie.org

  • Port: 5001

  • username: admin

  • password: admin

  • HTTP method: POST

  • HTTP Path: /ws/rest/v1/patients/


I am using Apache HttpClient to achieve this. Below is the code which I am using.



public void simpleHttpMessage() throws Exception{
String url = "iol.sandbox.ohie.org";
String USER_AGENT = "/ws/rest/v1/patients/";

HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(url);

// add header
post.setHeader("User-Agent", USER_AGENT);

List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
urlParameters.add(new BasicNameValuePair("username", "admin"));
urlParameters.add(new BasicNameValuePair("password", "admin"));

post.setEntity(new UrlEncodedFormEntity(urlParameters));


HttpResponse response = client.execute(post);
System.out.println("\nSending 'POST' request to URL : " + url);
System.out.println("Post parameters : " + post.getEntity());
System.out.println("Response Code : " +
response.getStatusLine().getStatusCode());

BufferedReader rd = new BufferedReader(
new InputStreamReader(response.getEntity().getContent()));

StringBuffer result = new StringBuffer();
String line = "";
while ((line = rd.readLine()) != null) {
result.append(line);
}

System.out.println(result.toString());
}


I am not sure where I should pass the actual xml message which I want to send. I am basically trying to send a HL7 message which is parsed into XML, over HTTP POST.


I would be grateful if someone who help me with what I am missing from the above code snippet.


1 comment: