The Community is hosting an End of Summer sweepstakes! Participants must complete tasks to earn tickets that will enter them with a chance to win a free year of Constant Contact and other great prizes!*
*No Purchase Necessary. For Official Rules, visit here. Constant Contact’s End of Summer 2020 Sweepstakes ends on October, 20, 2020 at 11:50 PM EST.

API connection refused

Highlighted
Visitor

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
Highlighted
Visitor

Re: API connection refused

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

Constant Contact 2020 End of Summer Community Sweepstakes!

The Constant Contact User Community is hosting a sweepstakes. The more you participate, the more chances you have to win! Read on to learn more...

Read More
Featured