cancel
Showing results for 
Search instead for 
Did you mean: 

java.net.ConnectException: Connection Refused in Web Service

junieboy
Champ in-the-making
Champ in-the-making
Hi,

Did some performance test using Alfresco 3.1 server using the UploadContent servlet to upload files and have encountered java.net.ConnectException: Connection . Below is the stack trace. After checking it appears that the exception occured in the construction of the URL object of the file to upload.

            url = new URL(fileUrl);

The error occurred when tried to run 40 concurrent uploads. Any idea what caused this? Is there a way to optimize this so that this does not happen in production?


20:30:38,330 639293 ERROR [com.db.dks.bpms.dms.delegate.AlfrescoUploadContent] (http-0.0.0.0-8080-119Smiley Happy ClientProtocolException!
java.net.ConnectException: Connection refused
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
        at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
        at java.net.Socket.connect(Socket.java:519)
        at java.net.Socket.connect(Socket.java:469)
        at sun.net.NetworkClient.doConnect(NetworkClient.java:163)
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:394)
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:529)
        at sun.net.www.http.HttpClient.<init>(HttpClient.java:233)
        at sun.net.www.http.HttpClient.New(HttpClient.java:306)
        at sun.net.www.http.HttpClient.New(HttpClient.java:323)
        at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:852)
        at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:793)
        at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:718)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1041)
        at java.net.URL.openStream(URL.java:1009)
        at com.db.dks.bpms.dms.delegate.AlfrescoUploadContent.uploadContent(AlfrescoUploadContent.java:329)
        at com.db.dks.bpms.dms.delegate.AlfrescoUploadContent.upload(AlfrescoUploadContent.java:122)
        at com.db.dks.bpms.dms.ScDMSUploadServiceWSImpl.upload(ScDMSUploadServiceWSImpl.java:53)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:173)
        at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:89)
        at org.apache.cxf.jaxws.JAXWSMethodInvoker.invoke(JAXWSMethodInvoker.java:60)

Here's the complete method snippet


    private String uploadContent(String dmsInstance, String fileUrl, String strFileName, HttpClient client,
            ResponseHandler<String> responseHandler) throws MalformedURLException, ClientProtocolException,
            IOException {
        log.info("start call to AlfrescoUploadContent.uploadContent");
        String strTicket = AuthenticationUtils.getTicket();
        log.info("dmsInstance for upload: " + dmsInstance);
        if (dmsInstance == null || dmsInstance.equalsIgnoreCase("")) {
            throw new IllegalStateException(
                    "No value was provided for dmsInstance. "
                            + "Target host must not be null, or set in parameters. Sample value is http://hostname:port/alfresco/upload");
        }

        StringBuffer strBuffUploadUrl = new StringBuffer(dmsInstance);
        strBuffUploadUrl.append("/").append(strFileName);
        strBuffUploadUrl.append("?ticket=");
        strBuffUploadUrl.append(strTicket);

        URL url = null;
        InputStream is = null;
        String responseBody = null;

        try {
            String strUploadUrl = strBuffUploadUrl.toString();
            log.info("strUploadUrl: " + strUploadUrl);

            HttpPut putFile = new HttpPut(strUploadUrl);

            log.debug("creating URL object from fileUrl: " + fileUrl);
            url = new URL(fileUrl);
            is = url.openStream();
            log.debug("available bytes from inputstream: " + is.available());
            InputStreamEntity ise = new InputStreamEntity(is, -1);
            putFile.setEntity(ise);
            responseBody = client.execute(putFile, responseHandler);
            log.info("responseBody: " + responseBody);

        } catch (MalformedURLException e) {
            log.error("MalformedURLException!", e);
            throw e;
        } catch (ClientProtocolException e) {
            log.error("ClientProtocolException!", e);
            throw e;
        } catch (IOException e) {
            log.error("ClientProtocolException!", e);
            throw e;
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                    log.error("", e);
                }
            }
        }

        log.info("done call to AlfrescoUploadContent.uploadContent");
        return responseBody;
    }
4 REPLIES 4

mrogers
Star Contributor
Star Contributor
You may need tune alfresco and in particular increase the number of http threads and database connections available.   

What application server are you using?

junieboy
Champ in-the-making
Champ in-the-making
You may need tune alfresco and in particular increase the number of http threads and database connections available.   

What application server are you using?

Hi,

Thanks for the response! We are using Apache Tomcat. Please share some documentation and tips on how we could do this. This has become a big concern to us and would want to make sure this does not happen in production. The upload to Alfresco web service that I have created will be a mission critical and intensive interface as many applications will invoke the said interface.

In addition, since I am using the upload servlet, will it help to use a fixed thread pool to control the number of threads concurrently uploading in Alfresco?

Regards.

mrogers
Star Contributor
Star Contributor
Look at the tomcat configuration information.   You need to increase the number of HTTP threads.

e.g. http://tomcat.apache.org/tomcat-5.5-doc/config/http.html

A rough rule of thumb is that you need 2 database connections plus a few for luck for each http thread.     I think the default is 200.

By the way 40 concurrent uploads is simulating an enormous load.    What sort of figures are you expecting for your system in real life?

junieboy
Champ in-the-making
Champ in-the-making
Look at the tomcat configuration information.   You need to increase the number of HTTP threads.

e.g. http://tomcat.apache.org/tomcat-5.5-doc/config/http.html

A rough rule of thumb is that you need 2 database connections plus a few for luck for each http thread.     I think the default is 200.

By the way 40 concurrent uploads is simulating an enormous load.    What sort of figures are you expecting for your system in real life?


Hi,

Thanks again for the response. Our system records says we have 8 concurrent users per second at peak times. But each user/thread could upload 4 files in parallel so that would mean 32 files. We use the external Alfresco web services API wrapped as a CXF web service being called by our applications.

I appreciate all your suggestions in optimizing this.

Rgds.