package com.tibco;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.httpclient.URI;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIUtils;
import org.apache.http.cookie.Cookie;
import org.apache.http.entity.BufferedHttpEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultConnectionKeepAliveStrategy;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils;
public class WcfWrapper{
public static void callWcf(String getContents) throws Exception {
InputStream responsexml=null;
DefaultHttpClient httpclient = new DefaultHttpClient();
java.net.URI uri = URIUtils.createURI("http", "servername", -1, "/LBSRA/ServiceName.svc/RequestPOST",
"tibcourl="+URLEncoder.encode("<?xml version=\"1.0\" encoding=\"utf-8\"?><ServiceConfigurations xmlns:xsi=\"http://www.w3.org some ex pl document ",HTTP.UTF_8)+"&"
+"rawXML="+URLEncoder.encode("<?xml version=\"1.0\" encoding=\"utf-8\"?>some xml document",HTTP.UTF_8)
, null);
HttpPost httpost = new HttpPost(uri);
List <NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("rawXML", getContents));
httpclient.getParams().setParameter("http.socket.timeout", new
Integer(55000));
httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
HttpResponse response = httpclient.execute(httpost);
BufferedHttpEntity entity = new BufferedHttpEntity(response.getEntity());
System.out.println("Post Form " + response.getStatusLine());
if (entity != null) {
entity.consumeContent();
}
System.out.println(entity.getContentType());
try{
responsexml = entity.getContent();
if(response!=null){
System.out.println(entity.getContentLength());
}
byte[] fileBArrayrawxml = new byte[(int)entity.getContentLength()];
responsexml.read(fileBArrayrawxml,0,(int)entity.getContentLength());
System.out.println(new String(fileBArrayrawxml));
responsexml.close();
}catch(Exception e){}finally{
responsexml.close();
}
}
}