Stack Exchange
HTTPPost usage error to in execution method
I am using the following code to make a http client ,i am facing problem in execute method ,its getting stuck there.
public static final HttpHost target = new HttpHost("test.xyz.com", 443, "https");

public static void test()
{
    HttpEntity responseEntity = null;
    DefaultHttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost("/xyz/test");
    System.out.println("post is " +post.getRequestLine());

        UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);
        AuthScope authScope = new AuthScope(target.getHostName(), target.getPort());
        System.out.println("auth scope is " +authScope);
        client.getCredentialsProvider().setCredentials(authScope, credentials);
        //i am passing a xml here
        post.setEntity(new StringEntity(xml, "UTF-8"));
        post.addHeader("Content-Type", "application/xml");
        post.addHeader("Accept", "application/xml");
        System.out.println("post " +post.getAllHeaders().length);
        HttpResponse response = client.execute(target, post); //getting stuck here no response at all
        System.out.println("response  " +response.getStatusLine());
        responseEntity = response.getEntity();
        System.out.println("response entity " +responseEntity);
        String responseXmlString = EntityUtils.toString(responseEntity);
        System.out.println("response" +responseXmlString);


}

i am facing problem here 
HttpResponse response = client.execute(target, post); 

what might be wrong ?
The problem is the code is getting stuck in client.execut method its not moving furthur neither i am getting any response.Do i have to set any proxy?

the problem is the code is getting stuck in client.execut method its not moving furthur neither i am getting any response.Do i hv to set any proxy?

When you run the test, do you have a target setup that can receive the post? The execute might just be busy trying to get the data delivered to a socket it cannot write to.

ya the target is set up to recieve the data.For how long the server might be busy to recieve the data,i waited for it execute atmost 5 mins

Does the server access log show that the connection is made? Does the servlet/jsp receive any data?

Probably your request is not really 'stuck' but just waiting on a TCP connection timeout, which bu default could be quite lonkg - like 5 minutes or so. There should be a way to set timeout to shorter value - take a look at javadoc for your http client or just try to wait longer.
Also you can take a thread dump while your program is stuck to see where the thread is blocked (see jps and jstack utilities in Sun's JDK)

I think you first need to eliminate the possibility of your server misbehaving. Have you tried POSTing to that URL from outside of your program. Try something like this if you are on a unix-like system or are on windows and have cygwin:
cat <yourfile.xml> | curl -X POST -H 'Content-type: text/xml' -d @- https://test.xyz.com:443/xyz/test

If the POST is successful get a thread dump of your program and post it here for us to take a look.

this is working fine ,through curl i am able to access the server,through java program i am getting stucked without getting any info
