You are currently browsing the tag archive for the ‘google app engine’ tag.
This is primarily an extension of the Force.com for Google App Engine Java Setup Guide which addresses problems specific to getting things running on Os X. There are also a couple of other problems you might have that I will also attempt to address.
First, get the two files you will need. (1) the latest version of the wsc-gae jar, at the moment wsc-gae-16_0.jar (available at the codeshare) (2) the partner library jar (also available at the codeshare).
Additionally, you can generate second jar for yourself from the partner wsdl or the enterprise wsdl. Since we want to refer to all of our custom Sobjects explicitly, we will use the enterprise wsdl (which can be downloaded from Setup->Develop->API in your Salesforce account).
To generate the enterprise library you need a recent version of Java (1.6) with the JVM. If you aren’t sure type “java -version” in the terminal. Here’s what we get:
Now all you need to do is run the following:
java -classpath wsc-gae-16_0.jar:JAVA_HOME/Classes/classes.jar com.sforce.ws.tools.wsdlc enterprise.wsdl.xml ./myProject_enterprise_lib.jar
Note the several differences from the example at the wiki article:
(1) A colon (‘:’) instead of a semi-colon (‘;’)
(2) Classes.jar instead of tools.jar (which is also located in a different directory)
(3) You must specify a directory for the generated jar
Fail to do any of these three and things will go horribly wrong.
Here is the full statement on our system:
java -classpath wsc-gae-16_0.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Classes/classes.jar com.sforce.ws.tools.wsdlc enterprise.wsdl.xml ./myProject_enterprise_lib.jar
The rest of this is straight from the wiki article with a couple notes:
(1) Install Eclipse and the Google Eclipse Plugin. NOTE: You will probably also want to register an application name so you can deploy to the Google App Engine later.
(2) Create a New Web Application Project
(3) Now, add the jar files we downloaded and generated above to your application’s WEB-INF/lib folder. NOTE: if you accidentally use what you think is a more recent version (for instance the wsc-17_0.jar) you will likely get strange errors like Java.net.Proxy, java.lang.UnsupportedOperationException, 500 Server Error, etc. Moreover, even if you remove the jar file the errors may not go away and you may have to restart with a whole new project.
(4) Add the example servlet class. NOTE: Make sure you append your security token to your password. This example also depends on having the partner library as your jar. If you want to use the Enterprise WSDL use the following:
package com.joeldietz.chatterwave;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.*;
import java.util.logging.*;
import com.sforce.ws.*;
import com.sforce.soap.enterprise.*;
import com.sforce.soap.enterprise.sobject.Account;
@SuppressWarnings("serial")
public class HelloWorldEnterpriseServlet extends HttpServlet {
private static final Logger log = Logger.getLogger(HelloWorldEnterpriseServlet.class.getName());
private String username = " ";
private String password = " "; // <-- password plus security token here
private EnterpriseConnection connection;
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
resp.setContentType("text/html");
resp.getWriter().println("Hello, world. this is a test 35");
PrintWriter t = resp.getWriter();
getConnection( t, req);
if ( connection == null ) { return; }
QueryResult result = null;
try {
result = connection.query( "select id, name, phone from Account order by LastModifiedDate desc limit 10 ");
} catch (ConnectionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for (int i=0;i<result.getRecords().length;i++) {
Account a = (Account)result.getRecords()[i];
String name = a.getName();
t.println("<li>"+ name + "</li>");
}
}
void getConnection(PrintWriter out, HttpServletRequest req) {
try {
// build up a ConnectorConfig from a sid
String sessionid = req.getParameter("sid");
String serverurl = req.getParameter("srv");
if ( connection == null ) {
out.println("<p>new connection needed</p>");
// login to the Force.com Platform
ConnectorConfig config = new ConnectorConfig();
if ( sessionid != null && serverurl != null) {
config.setServiceEndpoint(serverurl);
config.setSessionId(sessionid);
config.setManualLogin(false);
out.println("using session from query string");
} else {
config.setUsername(username);
config.setPassword(password);
}
connection = Connector.newConnection(config);
out.println( connection.getConfig().getSessionId() );
out.println( connection.getConfig().getServiceEndpoint() );
} else {
out.println("<p> reuse existing connection");
out.println( connection.getConfig().getSessionId() );
}
log.warning("Connection SID " +connection.getConfig().getSessionId());
} catch ( ConnectionException ce) {
log.warning("ConnectionException " +ce.getMessage());
out.println( ce.getMessage() + " s " + ce.getClass() );
}
}
}
Now we can try this out by running the servlet as a web application (Run -> Run As -> Web Application). You may also want to go into the run configurations and change the server port on the server tab if you are running other Google App Engine enabled web applications. If you registered your application before at Google App Engine, you can also try right clicking on your project then Google -> Deploy to App Engine. Presto, your application should be live and ready at applicationname.appspot.com.
When you run it you should get a message like this:
Next up: Google Wave Robot API v.2 + Enterprise WSDL + Salesforce Chatter


