You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Mohammad wrk <mo...@yahoo.com> on 2007/03/16 18:21:52 UTC

Connection reset

Hi All,

I'm using the following code to send Java objects over http to the server. In most cases it works fine, but sometimes it throws 
"java.net.SocketException: Connection reset" at the line highlighted in red below and user simply gets an error message. After closing the message dialog and retrying the same function, it goes through successfully. It don't know what the pattern is for reproducing the error and this makes it hard to trace and debug.

Does anybody have any ideas what the root cause could be?

BTW, I'm using httpclient version 3.0.


            RemoteMethodCall remoteMethodCall = new RemoteMethodCall(jndiName, method.getName(), args, method.getParameterTypes());
            
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            new ObjectOutputStream(byteArrayOutputStream).writeObject(remoteMethodCall);
            byte[] remoteMethodCallAsByte = byteArrayOutputStream.toByteArray();
            
            PostMethod postMethod = new PostMethod(logonContext.getUrl());
            postMethod.setRequestEntity(new ByteArrayRequestEntity(remoteMethodCallAsByte));
            postMethod.setContentChunked(true);
            httpClient.executeMethod(postMethod);
            debugHttpMethod(postMethod);
            
            try {
                if (HttpStatus.SC_OK == postMethod.getStatusCode()) {
                    ObjectInputStream in = new ObjectInputStream(postMethod.getResponseBodyAsStream());
                    RemoteMethodCallResults results = (RemoteMethodCallResults)in.readObject();
                    Throwable resultException = results.getException();
                    
                    if ( resultException == null) {
                        return results.getRVal();
                    }
                    
                    throw resultException;
                }
                else if (requiresAuthetication(postMethod)) {
                    LogonContext lctx = (LogonContext)RootApplicationContext.getContext().getBean("logon-context");
                    ValidationResults vr = authenticate(lctx.getUserName(), lctx.getPassword());
                    if (vr.isValid())
                        return invoke(proxy, method, args);
                    throw new FrameworkException(remoteMethodCall + " failed: " + vr.getMessage());
                }
                else {
                    throw new FrameworkException(remoteMethodCall + " failed: " + postMethod.getResponseBodyAsString());
                }
            }finally {
                postMethod.releaseConnection();
            }

Thanks,

Mohammad




__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Re: Connection reset

Posted by Roland Weber <ht...@dubioso.net>.
Hello Mohammad,

this is a text-only mailing list, so your color highlighting
got lost in transit. Anyway, Connection Reset indicates that
someone - most likely the server - closed the connection. This
may happen due to high load, or because the server doesn't
like the request. But if a retry succeeds, it is more likely
a temporary problem such as server load or network congestion.

hope that helps,
  Roland


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org