A client uses Jets3t library failed connection

384 views
Skip to first unread message

mihoob

unread,
Jul 23, 2009, 1:10:56 PM7/23/09
to JetS3t Users
I have developed a client use Jets3t library to connect to S3 .. when
i try to upload, listbucks i have got hte following messsage



CONNECTED
2009-07-23 17:50:12,221 [main] INFO
org.apache.commons.httpclient.HttpMethodDirector - I/O exception
(java.net.ConnectException) caught when processing request: Connection
refused: connect
2009-07-23 17:50:12,221 [main] INFO
org.apache.commons.httpclient.HttpMethodDirector - Retrying request
2009-07-23 17:50:13,314 [main] INFO
org.apache.commons.httpclient.HttpMethodDirector - I/O exception
(java.net.ConnectException) caught when processing request: Connection
refused: connect
2009-07-23 17:50:13,314 [main] INFO
org.apache.commons.httpclient.HttpMethodDirector - Retrying request
2009-07-23 17:50:14,408 [main] INFO
org.apache.commons.httpclient.HttpMethodDirector - I/O exception
(java.net.ConnectException) caught when processing request: Connection
refused: connect
2009-07-23 17:50:14,408 [main] INFO
org.apache.commons.httpclient.HttpMethodDirector - Retrying request
2009-07-23 17:50:15,502 [main] INFO
org.apache.commons.httpclient.HttpMethodDirector - I/O exception
(java.net.ConnectException) caught when processing request: Connection
refused: connect
2009-07-23 17:50:15,502 [main] INFO
org.apache.commons.httpclient.HttpMethodDirector - Retrying request
2009-07-23 17:50:16,517 [main] INFO
org.apache.commons.httpclient.HttpMethodDirector - I/O exception
(java.net.ConnectException) caught when processing request: Connection
refused: connect
2009-07-23 17:50:16,517 [main] INFO
org.apache.commons.httpclient.HttpMethodDirector - Retrying request
2009-07-23 17:50:17,455 [main] WARN
org.jets3t.service.utils.RestUtils - Retried connection 6 times, which
exceeds the maximum retry count of 5
2009-07-23 17:50:17,455 [main] ERROR jetS3t.service.S3_service -
Service error in creating the bucket
org.jets3t.service.S3ServiceException: S3 PUT connection failed for
'/'
at
org.jets3t.service.impl.rest.httpclient.RestS3Service.performRequest
(RestS3Service.java:516)
at
org.jets3t.service.impl.rest.httpclient.RestS3Service.performRestPut
(RestS3Service.java:800)
at
org.jets3t.service.impl.rest.httpclient.RestS3Service.createObjectImpl
(RestS3Service.java:1399)
at
org.jets3t.service.impl.rest.httpclient.RestS3Service.createBucketImpl
(RestS3Service.java:1270)
at org.jets3t.service.S3Service.createBucket(S3Service.java:1558)
at org.jets3t.service.S3Service.createBucket(S3Service.java:1257)
at org.jets3t.service.S3Service.createBucket(S3Service.java:1284)
at jetS3t.service.S3_service.createBucket(S3_service.java:68)
at jetS3t.service.Client_1.main(Client_1.java:11)
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:585)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:
90)
Caused by: java.net.ConnectException: Connection refused: connect
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:516)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect
(SSLSocketImpl.java:549)
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:585)
at
org.apache.commons.httpclient.protocol.ReflectionSocketFactory.createSocket
(ReflectionSocketFactory.java:140)
at
org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory.createSocket
(SSLProtocolSocketFactory.java:130)
at org.apache.commons.httpclient.HttpConnection.open
(HttpConnection.java:707)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager
$HttpConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:
1361)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry
(HttpMethodDirector.java:387)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod
(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod
(HttpClient.java:397)
at org.apache.commons.httpclient.HttpClient.executeMethod
(HttpClient.java:323)
at
org.jets3t.service.impl.rest.httpclient.RestS3Service.performRequest
(RestS3Service.java:342)
... 13 more
2009-07-23 17:50:17,455 [main] INFO jetS3t.service.S3_service -
BEFORE UPLOAD: S3Object
[key=MyDocument.doc,bucket=<Unknown>,lastModified=null,
dataInputStream=null] Metadata={}
2009-07-23 17:50:17,455 [main] ERROR jetS3t.service.S3_service -
S3ServiceException when creating file
org.jets3t.service.S3ServiceException: The action Create Object in
bucket cannot be performed with an invalid bucket: null
at org.jets3t.service.S3Service.assertValidBucket(S3Service.java:
1135)
at org.jets3t.service.S3Service.putObject(S3Service.java:1913)
at jetS3t.service.S3_service.uploadObject(S3_service.java:100)
at jetS3t.service.Client_1.main(Client_1.java:15)
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:585)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:
90)

Process finished with exit code 0
this is the clinet code
package jetS3t.service;

import org.jets3t.service.model.S3Object;

public class Client_1
{
public static void main(String [] args)
{
S3_service s = new S3_service();
s.createBucket("second-bucket");
S3Object obj = s.createObject("MyDocument.doc");
s.uploadObject(obj);

}
}

and this S3_service
package jetS3t.service;


import java.io.File;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;

import org.apache.commons.configuration.CompositeConfiguration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.log4j.Logger;

import org.jets3t.service.S3Service;
import org.jets3t.service.S3ServiceException;
import org.jets3t.service.impl.rest.httpclient.RestS3Service;
import org.jets3t.service.model.S3Bucket;
import org.jets3t.service.model.S3Object;
import org.jets3t.service.security.AWSCredentials;

public class S3_service
{


private CompositeConfiguration config;
private Logger log;


public S3Service service;
public S3Bucket bucket;

private AWSCredentials aws = null;

private S3Object object = null;

public S3_service()
{
this.config = new CompositeConfiguration();
this.log = Logger.getLogger(S3_service.class);


try
{
config.addConfiguration(new PropertiesConfiguration
("program.properties"));
aws = new AWSCredentials(config.getString("program.key.access"),
config.getString("program.key.secret"));
this.service = new RestS3Service(aws);

System.out.println("CONNECTED");

}
catch (S3ServiceException e)
{
log.error("Service could not connect");
e.printStackTrace();
}
catch (ConfigurationException e)
{
log.error("Could not load the configuration file");
e.printStackTrace();
}


}

public void createBucket(String name)
{
try
{
bucket = service.createBucket(name);
log.info("BUCKET CREATED: " + bucket.getName());
}
catch (S3ServiceException e)
{
log.error("Service error in creating the bucket");

e.printStackTrace();
}

}

public S3Object createObject(String name)
{
object = new S3Object(name);
return object;

}

public S3Object setContent(S3Object obj, File file)
{
obj.setDataInputFile(file);
return obj;
}


public void uploadObject(S3Object object)
{
try
{
log.info("BEFORE UPLOAD: " + object);

object = service.putObject(bucket, object);
log.info("AFTER UPLOAD: " + object);

object = service.getObjectDetails(bucket, object.getKey());
log.info("DETAILS ONLY: " + object);
String etag = object.getETag();
log.info("THE TAG OF THE UPLOADED OBJECT IS " + etag);

}
catch (S3ServiceException e)
{
log.error("S3ServiceException when creating file");
e.printStackTrace();

}
}

public void deleteObject(String key)
{
try
{
service.deleteObject(bucket.getName(), key);
}
catch (S3ServiceException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}

public void downloadObjectDetails(String objName)
{

try
{
S3Object obj = service.getObjectDetails(bucket, objName);

log.info("S3OBJECT COMPLETE, " + obj);
String etag = object.getETag();
log.info("THE TAG OF THE DOWNLOADED OBJECT IS " + etag);

}
catch (S3ServiceException e)
{
log.error("Service exception in downloading object");
e.printStackTrace();
}

}


public void listBuckets()
{
try
{
S3Bucket[] myBuckets = service.listAllBuckets();
log.info("HOW MANY BUCKETS? " + myBuckets.length);
}
catch (S3ServiceException e)
{
log.error("Service exception in listing buckets");
e.printStackTrace();
}
}



}

James Murty

unread,
Jul 23, 2009, 9:34:59 PM7/23/09
to jets3t...@googlegroups.com
This problem is most likely caused by an outdated SSL certificate on your client computer because the connection problem seems specific to the secure connection negotiation (SSLSocketImpl).

You can test this theory by setting the property "s3service.https-only" to false in jets3t.properties. Your connections will most likely work using HTTP instead of HTTPS.

The best way to fix SSL problems is to update the Java installation on the client machine to get the latest security certificates.

Hope this helps,
James

mihoob

unread,
Jul 24, 2009, 7:45:55 AM7/24/09
to JetS3t Users
Hi james

thanks for your response, do you mean i have install Jkd 1.6 instead
of jkd 1.5

Thnaks
A Mihoob
> > org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory.createSocke­t
> ...
>
> read more »- Hide quoted text -
>
> - Show quoted text -

James Murty

unread,
Jul 24, 2009, 10:35:25 AM7/24/09
to jets3t...@googlegroups.com
You don't necessarily need to install JDK 1.6, you could just get a newer version of 1.5.

But before you do anything, you should confirm that using HTTP instead of HTTPS fixes the problem.

James

mihoob

unread,
Jul 27, 2009, 11:14:51 AM7/27/09
to JetS3t Users
Hey

I have installed JKD1.6 however I still have the following exception

2009-07-27 16:09:45,551 [main] INFO
org.apache.commons.httpclient.HttpMethodDirector - I/O exception
(java.net.ConnectException) caught when processing request: Connection
refused: connect
2009-07-27 16:09:45,551 [main] INFO
org.apache.commons.httpclient.HttpMethodDirector - Retrying request
2009-07-27 16:09:46,645 [main] INFO
org.apache.commons.httpclient.HttpMethodDirector - I/O exception
(java.net.ConnectException) caught when processing request: Connection
refused: connect
2009-07-27 16:09:46,645 [main] INFO
org.apache.commons.httpclient.HttpMethodDirector - Retrying request
2009-07-27 16:09:47,738 [main] INFO
org.apache.commons.httpclient.HttpMethodDirector - I/O exception
(java.net.ConnectException) caught when processing request: Connection
refused: connect
2009-07-27 16:09:47,738 [main] INFO
org.apache.commons.httpclient.HttpMethodDirector - Retrying request
2009-07-27 16:09:48,832 [main] INFO
org.apache.commons.httpclient.HttpMethodDirector - I/O exception
(java.net.ConnectException) caught when processing request: Connection
refused: connect
2009-07-27 16:09:48,832 [main] INFO
org.apache.commons.httpclient.HttpMethodDirector - Retrying request
2009-07-27 16:09:49,816 [main] INFO
org.apache.commons.httpclient.HttpMethodDirector - I/O exception
(java.net.ConnectException) caught when processing request: Connection
refused: connect
2009-07-27 16:09:49,816 [main] INFO
org.apache.commons.httpclient.HttpMethodDirector - Retrying request
2009-07-27 16:09:50,801 [main] WARN
org.jets3t.service.utils.RestUtils - Retried connection 6 times, which
exceeds the maximum retry count of 5
2009-07-27 16:09:50,801 [main] ERROR jetS3t.service.S3_service -
Service exception in listing buckets
org.jets3t.service.S3ServiceException: S3 GET connection failed for
'/'
at
org.jets3t.service.impl.rest.httpclient.RestS3Service.performRequest
(RestS3Service.java:516)
at
org.jets3t.service.impl.rest.httpclient.RestS3Service.performRestGet
(RestS3Service.java:752)
at
org.jets3t.service.impl.rest.httpclient.RestS3Service.listAllBucketsImpl
(RestS3Service.java:1041)
at org.jets3t.service.S3Service.listAllBuckets(S3Service.java:1348)
at jetS3t.service.S3_service.listBuckets(S3_service.java:157)
at jetS3t.service.Client_1.main(Client_1.java:12)
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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:
90)
Caused by: java.net.ConnectException: Connection refused: connect
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 com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect
(SSLSocketImpl.java:550)
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.commons.httpclient.protocol.ReflectionSocketFactory.createSocket
(ReflectionSocketFactory.java:140)
at
org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory.createSocket
(SSLProtocolSocketFactory.java:130)
at org.apache.commons.httpclient.HttpConnection.open
(HttpConnection.java:707)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager
$HttpConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:
1361)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry
(HttpMethodDirector.java:387)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod
(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod
(HttpClient.java:397)
at org.apache.commons.httpclient.HttpClient.executeMethod
(HttpClient.java:323)
at
org.jets3t.service.impl.rest.httpclient.RestS3Service.performRequest
(RestS3Service.java:342)
... 10 more

Process finished with exit code 0


James Murty

unread,
Jul 27, 2009, 11:37:03 PM7/27/09
to jets3t...@googlegroups.com
Have you tried disabling HTTPS to see if that makes a difference?

mihoob

unread,
Jul 31, 2009, 6:34:08 AM7/31/09
to JetS3t Users
Dear

I have wrote the following Jets3t appliction

package jetS3t.service;


import org.jets3t.service.S3Service;

import org.jets3t.service.S3ServiceException;
import org.jets3t.service.impl.rest.httpclient.RestS3Service;

import org.jets3t.service.model.S3Bucket;


// import org.jets3t.service.model.S3Object;

import org.jets3t.service.security.AWSCredentials;
// import org.apache.commons.configuration.PropertiesConfiguration;

// import org.apache.commons.configuration.ConfigurationException;

import org.apache .*;
import org.jets3t .*;

//import java.sql.Date;



public class TestS3
{





String awsAccessKey = "MY AcessKey" ; String awsSecretKey = "My Secret
Key " ;


S3Service s ;

public TestS3()
{







try

{

AWSCredentials awsCredentials = new AWSCredentials( awsAccessKey ,
awsSecretKey ); s = new RestS3Service(awsCredentials);





}
catch (S3ServiceException e)
{



e.printStackTrace();

}



}

public void listAllBuckets()
{

try

{

S3Bucket[] myBuckets = s .listAllBuckets(); System. out .println( "How
many buckets to I have in S3? " + myBuckets. length );
}

catch (S3ServiceException e)
{



e.printStackTrace();

}



}

public void listBuckets()
{

try

{

S3Bucket[] myBuckets = s .listAllBuckets(); System. out .println( "HOW
MANY BUCKETS? " + myBuckets. length );
}

catch (S3ServiceException e)
{

System. out .println( "Service exception in listing buckets" +
e.getMessage() );
e.printStackTrace();

}

}

}


and the Client


package jetS3t.service;




//import java.io.File;



//import org.jets3t.service.model.S3Object;



public class Client_1
{

public static void main(String [] args)
{

TestS3 s = new TestS3();
s.listBuckets();

}

}


and I hve add all the required libraries.
more over I have set the property "s3service.https-only" to
false in jets3t.properties. and i have set the proxy as well but I
have still got hte following exception



2009-07-31 10:41:21,303 [main] INFO
org.apache.commons.httpclient.HttpMethodDirector - I/O exception
(java.net.ConnectException) caught when processing request: Connection
refused: connect

2009-07-31 10:41:21,303 [main] INFO
org.apache.commons.httpclient.HttpMethodDirector - Retrying request

2009-07-31 10:41:22,397 [main] INFO
org.apache.commons.httpclient.HttpMethodDirector - I/O exception
(java.net.ConnectException) caught when processing request: Connection
refused: connect

2009-07-31 10:41:22,397 [main] INFO
org.apache.commons.httpclient.HttpMethodDirector - Retrying request

2009-07-31 10:41:23,491 [main] INFO
org.apache.commons.httpclient.HttpMethodDirector - I/O exception
(java.net.ConnectException) caught when processing request: Connection
refused: connect

2009-07-31 10:41:23,491 [main] INFO
org.apache.commons.httpclient.HttpMethodDirector - Retrying request

2009-07-31 10:41:24,584 [main] INFO
org.apache.commons.httpclient.HttpMethodDirector - I/O exception
(java.net.ConnectException) caught when processing request: Connection
refused: connect

2009-07-31 10:41:24,584 [main] INFO
org.apache.commons.httpclient.HttpMethodDirector - Retrying request

2009-07-31 10:41:25,678 [main] INFO
org.apache.commons.httpclient.HttpMethodDirector - I/O exception
(java.net.ConnectException) caught when processing request: Connection
refused: connect

2009-07-31 10:41:25,678 [main] INFO
org.apache.commons.httpclient.HttpMethodDirector - Retrying request

2009-07-31 10:41:26,662 [main] WARN org.jets3t.service.utils.RestUtils
- Retried connection 6 times, which exceeds the maximum retry count of
5

Service exception in listing bucketsS3 GET connection failed for '/'

org.jets3t.service.S3ServiceException : S3 GET connection failed for
'/'
at org.jets3t.service.impl.rest.httpclient.RestS3Service.performRequest
( RestS3Service.java:516 )at
org.jets3t.service.impl.rest.httpclient.RestS3Service.performRestGet(

RestS3Service.java:752 )
at
org.jets3t.service.impl.rest.httpclient.RestS3Service.listAllBucketsImpl
( RestS3Service.java:1041 )at
org.jets3t.service.S3Service.listAllBuckets(

S3Service.java:1348 )
at jetS3t.service.TestS3.listBuckets( TestS3.java:69 )at
jetS3t.service.Client_1.main(

Client_1.java:12 )
Caused by: java.net.ConnectException : Connection refused: connectat
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
com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(

SSLSocketImpl.java:550 )
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.commons.httpclient.protocol.ReflectionSocketFactory.createSocket
( ReflectionSocketFactory.java:140 )at
org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory.createSocket
(

SSLProtocolSocketFactory.java:130 )
at org.apache.commons.httpclient.HttpConnection.open
( HttpConnection.java:707 )at
org.apache.commons.httpclient.MultiThreadedHttpConnectionManager
$HttpConnectionAdapter.open(

MultiThreadedHttpConnectionManager.java:1361 )
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry
( HttpMethodDirector.java:387 )at
org.apache.commons.httpclient.HttpMethodDirector.executeMethod(

HttpMethodDirector.java:171 )
at org.apache.commons.httpclient.HttpClient.executeMethod
( HttpClient.java:397 )at
org.apache.commons.httpclient.HttpClient.executeMethod(

HttpClient.java:323 )
at org.jets3t.service.impl.rest.httpclient.RestS3Service.performRequest
( RestS3Service.java:342 )

... 5 more

thanks

On Jul 28, 4:37 am, James Murty <jamu...@gmail.com> wrote:

James Murty

unread,
Jul 31, 2009, 10:49:21 AM7/31/09
to jets3t...@googlegroups.com
Hi,

If you cannot connect to S3 using HTTP or HTTPS, it looks like there must be something about the network setup that is preventing the connection. Is there a corporate proxy of some kind that could cause this problem? JetS3t is not compatible with all NTLM proxies.

If the problem isn't caused by a proxy, the next step is to remove JetS3t from the equation entirely to see if a normal Java program can connect to web sites. Try writing a small program that just uses a URLConnection to open a public Google web page.

If the underlying cause is an unsupported proxy, or if there is no proxy but a simple URLConnection program doesn't work either, you will need to discuss the issue with someone who knows how the network is setup to find out why Java programs cannot connect to the Internet.

You may be able to get more information about the problem by enabling Log4J debugging of the content and headers sent by HttpClient with the following settings in log4j.properties:
og4j.logger.httpclient.wire.content=DEBUG
log4j.logger.httpclient.wire.header=DEBUG

James

---
http://www.jamesmurty.com
Reply all
Reply to author
Forward
0 new messages