function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Force.comForce.com 

How to call salesforce from Java code running on EC2 ?

Hello,

 

I have a java servlet running on EC2 server of Amazon. This servlet calls salesforce by setting up connection with EnterpriseConnection class. 

 

I ran this java servlet in java enviornment and the code was working. However when I ran the same java servlet by hosting it on EC2 server, it is throwing the following exception:

 

java.lang.NoClassDefFoundError: com/sforce/ws/ConnectionException java.lang.Class.getDeclaredConstructors0(Native Method) java.lang.Class.privateGetDeclaredConstructors(Class.java:2389) java.lang.Class.getConstructor0(Class.java:2699) java.lang.Class.newInstance0(Class.java:326) java.lang.Class.newInstance(Class.java:308) org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405) org.apache.coyote.ajp.AjpAprProcessor.process(AjpAprProcessor.java:197) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515) org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1824) java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)

 

 I have imported wsc-20.jar and enterprise.jar files in the code. Still facing this issue. 

 

Is there any other way to call salesforce from java running on EC2?

 

Please help. Any help will be highly appreciated.

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
Force.comForce.com

Hi cloudcoder, SimonF,

 

Thanks a lot.

Issue is resolved now.

Cause of this exception was: I forgot to restart Tomcat after adding jar files in its lib folder.

 

 

 

All Answers

cloudcodercloudcoder

Certainly sounds like a classpath issue. Of course, you could use the Force.com REST API, then you don't need SOAP or WSDLs. :)

 

http://developer.force.com/REST

Force.comForce.com

I have set the classpath of wsc-20 jar. Still facing this issue. At this point of time, I can not convert the complete code to support REST APIs but I will surely give it a try later.

 

Is calling Salesforce through Soap or wsdls not supported on EC2?

 

I failed to understand why I am facing this ConnectionException issue when running the code on EC2 while it is working when I am running it in java enviornment.\

 

Thanks

SuperfellSuperfell

It sounds like your runtime environment doesn't have the right classpath. (or perhaps you haven't deployed all the jars?)

Force.comForce.com

Hi SimonF,

 

Thanks for your reply.

 

All the jar files are present in the lib folder of Tomcat.

 

In Command prompt, I am writing following classpath:

 

set classpath=.;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\commons-cli-1.2.jar;C:

\Program Files\Apache Software Foundation\Tomcat 7.0\lib\commons-io-1.4.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\jodconverter-2.2.2.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\jodconverter-cli-2.2.2.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\juh-3.0.1.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\jurt-3.0.1.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\ridl-3.0.1.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\slf4j-api-1.5.6.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\slf4j-jdk14-1.5.6.jar;C:\program Files\Apache Software Foundation\Tomcat 7.0\lib\unoil-3.0.1.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\xstream-1.3.1.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\enterpriseDMG.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\xstream-1.3.1.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\servlet-api.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\xstream-1.3.1.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\wsc-20.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\itext-2.1.7.jar;
Above command has a class path of all jar files, then I compiled the code. It gets compiled successfully. Now when I run the the servlet through tomcat, ConnectionException is coming on EC2.
Thanks



Force.comForce.com

Hi cloudcoder, SimonF,

 

Thanks a lot.

Issue is resolved now.

Cause of this exception was: I forgot to restart Tomcat after adding jar files in its lib folder.

 

 

 

This was selected as the best answer