We all started somewhere! Share your experience on the Get Advice: Let's Get Started Sweepstakes thread and be entered to win a $100 credit on your Constant Contact account.

API connection refused

MarkK21872
Participant

API connection refused

Hello!

 

I had this code working perfectly a few days back, but when I tried it again today, it is throwing a ConnectionRefused exception. I am sure the username, password, API key are all correct since I am able to log into the api website using them.

 

I need to sort this out as soon as possible. Any help shall be appreciated.

 

	 		UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(cckey+"%"+ccuser, ccpass);
 			AuthScope authScope = new AuthScope("api.constantcontact.com", 443);
			CredentialsProvider credsProvider = new BasicCredentialsProvider();
			credsProvider.setCredentials(authScope, credentials);
			
			
			DefaultHttpClient httpClient = new DefaultHttpClient();
			httpClient.setCredentialsProvider(credsProvider);

			HttpPost httppost = new HttpPost("https://api.constantcontact.com/ws/customers/"+ccuser+"/contacts");
			StringEntity stringEntity = new StringEntity(xmlString);
			stringEntity.setContentType("application/atom+xml");
			httppost.setHeader("Content-Type","application/atom+xml");
			httppost.setEntity(stringEntity);

			int success=1;
			HttpResponse httpResponse = httpClient.execute(httppost);

 

 

This is the exception thrown in the JSP:

 

 

org.apache.http.conn.HttpHostConnectException: Connection to https://api.constantcontact.com refused
	org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:158)
	org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:149)
	org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:121)
	org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:562)
	org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:415)
	org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
	org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)
	org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732)
	org.apache.jsp.add_005fCC_005fUser_jsp._jspService(add_005fCC_005fUser_jsp.java:107)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

 

root cause

java.net.ConnectException: Connection refused
	java.net.PlainSocketImpl.socketConnect(Native Method)
	java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
	java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
	java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
	java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
	java.net.Socket.connect(Socket.java:529)
	org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:374)
	org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:148)
	org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:149)
	org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:121)
	org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:562)
	org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:415)
	org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
	org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)
	org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732)
	org.apache.jsp.add_005fCC_005fUser_jsp._jspService(add_005fCC_005fUser_jsp.java:107)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

 

 

1 REPLY 1
MarkK21872
Participant

The problem is sorted. There was some issue with the way SSL was configured on our site. Fixing that fixed this problem.

 

Thanks anyway!

Developer Portal

View API documentation, code samples, get your API key.

Visit Page