Google data (gdata) in eclipse with app engine, java - java

Ive had a similar question as this one before, and when that solved this came. So here we go again.
The content of doGet pretty much works but when I try it as a part of a servlet that eclipse created for me I get errors. Its looks a bit like I don't have the appropriate files referenced in the library, but I think I do.
The java code looks like this:
package picasatest;
import java.io.IOException;
import java.net.URL;
import javax.servlet.http.*;
import com.google.gdata.client.photos.PicasawebService;
import com.google.gdata.data.photos.AlbumEntry;
import com.google.gdata.data.photos.UserFeed;
#SuppressWarnings("serial")
public class PicasaTestServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
resp.setContentType("text/plain");
try {
PicasawebService service = new PicasawebService("Picasa test");
service.setUserCredentials("username#gmail.com", "password");
URL feedURL = new URL("http://picasaweb.google.com/data/feed/api/user/username?kind=album");
UserFeed feed = service.getFeed(feedURL, UserFeed.class);
for (AlbumEntry entry : feed.getAlbumEntries()) {
System.out.println(entry.getTitle().getPlainText());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
I have referenced to google-collect-1.0-rc2.jar, mail.jar, activation.jar, servlet-api.jar, gdata-client.jar, gdata-client-meta.jar, gdata-core.jar, gdata-media.jar, gdata-photos-2.0.jar and gdata-photos-meta-2.0.jar according to instruction from google. Is there anything else I have to do for it to work?
And I get this error to the console:
java.lang.NoClassDefFoundError: com/google/gdata/client/photos/PicasawebService
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2357)
at java.lang.Class.getConstructor0(Class.java:2671)
at java.lang.Class.newInstance0(Class.java:321)
at java.lang.Class.newInstance(Class.java:303)
at org.mortbay.jetty.servlet.Holder.newInstance(Holder.java:153)
at org.mortbay.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:339)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:463)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1093)
at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:124)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:712)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:54)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:313)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
at org.mortbay.jetty.Server.handle(Server.java:313)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:506)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:830)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:514)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:381)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:396)
at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:442)
Any idea on what I have missed?

Thanks to Jason Parekh from the Google group "Google App Engine for Java"
Where is your GData client JAR located? It should be in the war/WEB-INF/lib
directory for it to be included in the packaged war file.
jason
So your not supposed to put the whole gdata folder in war/WEB-INF like i did...
Problem solved

Related

Using MailGun on AppEngine Java

I'm trying to get the libraries needed to send mail on AppEngine.
The docs (https://cloud.google.com/appengine/docs/standard/java/mail/mailgun) state that these need to be added if using Maven:
jersey-core
1.19.4
jersey-client
1.19.4
jersey-multipart
1.19.4
Adding them however, results in an error message in Eclipse.
The type javax.ws.rs.ext.RuntimeDelegate$HeaderDelegate cannot be
resolved. It is indirectly referenced from required .class files
That can be resolved by adding javax.ws.rs-api-2.0.1, but using that jar seems problematic.
Appengine is throwing an error:
Caused by: java.lang.ExceptionInInitializerError
... 44 more
Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: org.glassfish.jersey.internal.RuntimeDelegateImpl
at com.sun.jersey.core.header.MediaTypes.<clinit>(MediaTypes.java:65)
... 62 more
Caused by: java.lang.ClassNotFoundException: org.glassfish.jersey.internal.RuntimeDelegateImpl
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at com.google.apphosting.runtime.ApplicationClassLoader.findClass(ApplicationClassLoader.java:45)
In a thread here though that error org.glassfish.jersey.internal.RuntimeDelegateImpl NOT FOUND is said to be solvable by removing javax.ws.rs-api-2.0
Other suggestions include using jersey2, but that requires additional configuration I believe and the AppEngine docs don't show how to do that.
How can I send mail on Appengine using Mailgun???
I solved it by using Jersey 2.27 (JAX-RS 2.1 / Jersey 2.26+) available as a download from https://jersey.github.io/download.html
I needed the following jars:
hk2-api-2.5.0-b32.jar
hk2-locator-2.5.0-b42.jar
hk2-utils-2.5.0-b32.jar
javax.inject-1.jar
javax.inject-2.5.0-b42.jar
jersey-client.jar
jersey-common.jar
jersey-guava-2.26-b03.jar (from Jersey 2.25.1)
jersey-media-jaxb.jar
javax.ws.rs-api-2.1.jar
And modified the AppEngine sample to use Jersey 2.26+ as below:
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Form;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
public static void sendSimpleMessage(String recipient) {
Client clientMail = ClientBuilder.newBuilder().build();
clientMail.register(HttpAuthenticationFeature.basic("api", MAILGUN_API_KEY));
WebTarget targetMail = clientMail.target("https://api.mailgun.net/v3/" + MAILGUN_DOMAIN_NAME + "/messages");
Form formData = new Form();
formData.param("from", "Mailgun Sandbox <"+DOMAIN_MAIL_ADDRESS+">");
formData.param("to", recipient);
formData.param("subject", "Simple Mailgun Example");
formData.param("text", "Plaintext content");
Response response = targetMail.request().post(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED_TYPE));
System.out.println("Mail sent : " + response);
}
The MAILGUN_API_KEY is available from MailGun. MAILGUN_DOMAIN_NAME is my custom domain and DOMAIN_MAIL_ADDRESS is the address I wish to send from.
Note: I have guava-gwt and gauva on my classpath too, so perhaps it was the addition of jersey-guava that did the trick. Actually, jersey-gauva was only in jaxrs-ri-2.25.1 and not in jaxrs-ri-2.27 (JAX-RS 2.1 / Jersey 2.26+). It was definitely needed though.

Google App Engine Java Can't Run Application HTTP 500

I have a simple servlet which looks like like below. Ite uses the Google's User Service. When I don't use it I don't get any errors. Also I get an entire list of error as below. I turn out that this was an Eclipse Known Issue but I can't find the solution.
import java.io.IOException;
import javax.servlet.http.*;
import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
#SuppressWarnings("serial")
public class GuestbookServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
if (user != null) {
resp.setContentType("text/plain");
resp.getWriter().println("Hello, " + user.getNickname());
} else {
resp.sendRedirect(userService.createLoginURL(req.getRequestURI()));
}
}
}
These are the first errors:
HTTP ERROR 500
Problem accessing /guestbook. Reason:
Expecting a stackmap frame at branch target 117 in method guestbook.GuestbookServlet.doGet(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V at offset 34
Caused by:
java.lang.VerifyError: Expecting a stackmap frame at branch target 117 in method guestbook.GuestbookServlet.doGet(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V at offset 34
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at org.mortbay.jetty.servlet.Holder.newInstance(Holder.java:153)
at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:428)
at org.mortbay.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:339)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
Is the problem from the Java version? I am running Eclipse Indigo and Java 7. What should I do
This seems to be a known eclipse issue with JDK7. Please check this link for workaround/solution.

App Engine URLFetch service called from Clojure gives AccessControlException

I'm trying to build a simple web widget in Clojure which should fetch a Picasa feed, retrieve the thumbnail URLs from there, and return HTML which will be inserted into a page (using JQuery AJAX call). The Picasa feed has a https://... url.
Everything works when I run it in a local Jetty instance using mvn jetty:run ; however when I try to run in a local GAE instance (mvn gae:run) it fails with an AccessControlException.
I've read the GAE documentation, but this states that for URLFetch from Java one should just use the normal Java URLConnection class where Google will provide their own implementation. As far as I can see I'm following their example to the letter, only using Clojure/Java interop.
Google example code looks like this:
import java.net.URL;
// (other imports omitted)
try {
URL url = new URL("http://www.example.com/atom.xml");
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
String line;
while ((line = reader.readLine()) != null) {
// ...
}
Interestingly this is calling openStream directly on the URL although elsewhere the documentation mentions to use UrlConnection. I've tried both, but the result is the same.
My corresponding Clojure code, using openConnection:
(if (.startsWith str-url "https://picasaweb.google.com")
(let [feed-url (java.net.URL. str-url)
connection (.openConnection feed-url)
xmltags (xml-seq (parse (.openStream connection)))]
; ...
When I run this in GAE I get the following stack trace (truncated)
java.lang.ExceptionInInitializerError
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at org.mortbay.jetty.servlet.Holder.newInstance(Holder.java:153)
at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:428)
at org.mortbay.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:339)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:35)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:60)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:122)
And finally at the bottom:
Caused by: java.security.AccessControlException: access denied (java.security.SecurityPermission getProperty.ssl.KeyManagerFactory.algorithm)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:374)
at java.security.AccessController.checkPermission(AccessController.java:546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at com.google.appengine.tools.development.DevAppServerFactory$CustomSecurityManager.checkPermission(DevAppServerFactory.java:252)
at java.security.Security.getProperty(Security.java:725)
at org.eclipse.jetty.util.ssl.SslContextFactory.<clinit>(SslContextFactory.java:92)
... 74 more
I have been Googling to see if there is any setting I should add in appengine-web.xml or somewhere else, but I see nothing. Everything I read tells me this should "just work", but it doesn't.
Any advice is most welcome; I can post full source or a full stacktrace if desired, although I think the above is pretty much the pertinent bits.
openStream() is shorthand for openConnection().getInputStream(), where openConnection() returns URLConnection.

how to run actual java in the backend of gwt web application

For a specific requirement in my project, I want to retrieve JSON response from a web service api.
I am tried a java code in a simple Java project which is running fine.
String message = null;
HttpClient httpclient = new DefaultHttpClient();
JSONParser parser = new JSONParser();
String url = "working - url";
HttpResponse response = null;
response = httpclient.execute(new HttpGet(url));
JSONObject json_data = null;
json_data = (JSONObject)parser.parse(EntityUtils.toString(response.getEntity()));
JSONArray results = (JSONArray)json_data.get("result");
for (Object queid : results) {
message = message.concat((String) ((JSONObject)queid).get("id"));
message = message.concat("\t");
message = message.concat((String) ((JSONObject)queid).get("owner"));
message = message.concat("\n");
}
If I try to run this code in a GWT application servlet, I am getting several errors om compilation.
[ERROR] Line 16: No source code is available for type org.apache.http.client.ClientProtocolException; did you forget to inherit a required module?
[ERROR] Line 16: No source code is available for type org.apache.http.ParseException; did you forget to inherit a required module?
[ERROR] Line 16: No source code is available for type org.json.simple.parser.ParseException; did you forget to inherit a required module?
I have added the required jars using the project build path ->add external jars.
But still I am facing the same problem.
I have tried attaching the source to the jars but still the problem is same.
What possibly could be done in this case?
Can I run actual java in the backend of my GWT application
Edit #1:
This code is written in my GWT servlet. I have tried using adding throws clause to the method in my servlet and applying try/catch block as well. But I am still getting these errors.
Edit #2:
I have got following errors in my console log after applying try/catch block.
Mar 10, 2012 1:16:28 PM com.google.appengine.tools.development.ApiProxyLocalImpl log
SEVERE: javax.servlet.ServletContext log: Exception while dispatching incoming RPC call
com.google.gwt.user.server.rpc.UnexpectedException: Service method 'public abstract java.lang.String com.google.detracker.client.DeService.getJSONRespnse()' threw an unexpected exception: java.lang.NoClassDefFoundError: javax.net.ssl.KeyManagerFactory is a restricted class. Please see the Google App Engine developer's guide for more details.
at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:385)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:588)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:35)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:58)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:122)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.BackendServersFilter.doFilter(BackendServersFilter.java:97)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:70)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:351)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:938)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Caused by: java.lang.NoClassDefFoundError: javax.net.ssl.KeyManagerFactory is a restricted class. Please see the Google App Engine developer's guide for more details.
at com.google.appengine.tools.development.agent.runtime.Runtime.reject(Runtime.java:51)
at org.apache.http.conn.ssl.SSLSocketFactory.createSSLContext(SSLSocketFactory.java:184)
at org.apache.http.conn.ssl.SSLSocketFactory.createDefaultSSLContext(SSLSocketFactory.java:209)
at org.apache.http.conn.ssl.SSLSocketFactory.<init>(SSLSocketFactory.java:333)
at org.apache.http.conn.ssl.SSLSocketFactory.getSocketFactory(SSLSocketFactory.java:165)
at org.apache.http.impl.conn.SchemeRegistryFactory.createDefault(SchemeRegistryFactory.java:45)
at org.apache.http.impl.client.AbstractHttpClient.createClientConnectionManager(AbstractHttpClient.java:294)
at org.apache.http.impl.client.AbstractHttpClient.getConnectionManager(AbstractHttpClient.java:445)
at org.apache.http.impl.client.AbstractHttpClient.createHttpContext(AbstractHttpClient.java:274)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:797)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732)
at com.google.detracker.server.DeServiceImpl.getJSONRespnse(DeServiceImpl.java:32)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:100)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:569)
... 34 more
Mar 10, 2012 1:16:28 PM com.google.appengine.tools.development.LocalResourceFileServlet doGet
If you pay attention, The error is about an Exception class. This means your code is returning an exception which you are not handling. type org.apache.http.client.ClientProtocolException
Try surronding your code with try catch block and see what you get in the dev console.
Try {
String message = null;
HttpClient httpclient = new DefaultHttpClient();
JSONParser parser = new JSONParser();
String url = "working - url";
HttpResponse response = null;
response = httpclient.execute(new HttpGet(url));
JSONObject json_data = null;
json_data = (JSONObject)parser.parse(EntityUtils.toString(response.getEntity()));
JSONArray results = (JSONArray)json_data.get("result");
for (Object queid : results) {
message = message.concat((String) ((JSONObject)queid).get("id"));
message = message.concat("\t");
message = message.concat((String) ((JSONObject)queid).get("owner"));
message = message.concat("\n");
}
} catch (Exception e) {
e.printStack();
}
Explanation:
Some more explanation for all those who want it. In your code, you do not handle the exceptions with try catch blocks. Thus, when an exception is raised, the server will send it back to the client but most of the exceptions are NOT serializable, so they cannot be transported back to the client and this is why you get the mentioned error.
use RequestBuilder
http://code.google.com/webtoolkit/doc/latest/tutorial/JSON.html
Yes you can, but the error message suggest you have somewhere in your client side code imported a class that uses those server side external jars.
Edit: Based the answer of Adel Boutros I guess you have added throws to your GWT service interfaces for the classes that generate these errors? You can only throw exceptions that are also available to the client, so catch them on the server and rethrow a new exception that is available in the client.
If those librabries can actually be used in GWT, you have to add lines in your application.gwt.xml file to inherit the modules.
Example with library smartgwt:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User'/>
<!-- Other module inherits -->
<inherits name="com.smartgwt.SmartGwt"/>
<!-- Specify the app entry point class. -->
<entry-point class='blablabla'/>
<!-- Specify the paths for translatable code -->
<source path='client'/>
<source path='shared'/>

Integrate openid4java to GWT Project

I created an GWT project in eclipse. Now I tried to implement openId with using the openid4java library.
I imported the .jar files via properties-->java build path:
openid4java-0.9.5.jar
lib/*.jar
In addition I copied the .jar files into the war/WEB-INF/lib directory.
The problem at hand comes up when I call the authenticate() method.
Then I get a:
HTTP ERROR 500
Problem accessing /openid/openid. Reason:
access denied (java.lang.RuntimePermission modifyThreadGroup)Caused by:java.security.AccessControlException: access denied (java.lang.RuntimePermission modifyThreadGroup)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at com.google.appengine.tools.development.DevAppServerFactory$CustomSecurityManager.checkPermission(DevAppServerFactory.java:166)
at com.google.appengine.tools.development.DevAppServerFactory$CustomSecurityManager.checkAccess(DevAppServerFactory.java:191)
at java.lang.ThreadGroup.checkAccess(Unknown Source)
at java.lang.Thread.init(Unknown Source)
at java.lang.Thread.<init>(Unknown Source)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$ReferenceQueueThread.<init>(MultiThreadedHttpConnectionManager.java:1039)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager.storeReferenceToConnection(MultiThreadedHttpConnectionManager.java:164)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager.access$900(MultiThreadedHttpConnectionManager.java:64)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$ConnectionPool.createConnection(MultiThreadedHttpConnectionManager.java:750)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager.doGetConnection(MultiThreadedHttpConnectionManager.java:469)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager.getConnectionWithTimeout(MultiThreadedHttpConnectionManager.java:394)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:152)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)
at org.openid4java.util.HttpCache.head(HttpCache.java:296)
at org.openid4java.discovery.yadis.YadisResolver.retrieveXrdsLocation(YadisResolver.java:360)
at org.openid4java.discovery.yadis.YadisResolver.discover(YadisResolver.java:229)
at org.openid4java.discovery.yadis.YadisResolver.discover(YadisResolver.java:221)
at org.openid4java.discovery.yadis.YadisResolver.discover(YadisResolver.java:179)
at org.openid4java.discovery.Discovery.discover(Discovery.java:134)
at org.openid4java.discovery.Discovery.discover(Discovery.java:114)
at org.openid4java.consumer.ConsumerManager.discover(ConsumerManager.java:527)
at auth.openid.server.OpenIDServlet.authenticate(OpenIDServlet.java:138)
at auth.openid.server.OpenIDServlet.doGet(OpenIDServlet.java:101)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:693)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:51)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:122)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:70)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:349)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Here my servlet source:
import com.google.gwt.user.client.rpc.RemoteService;
import org.openid4java.OpenIDException;
import org.openid4java.consumer.ConsumerException;
import org.openid4java.consumer.ConsumerManager;
import org.openid4java.consumer.VerificationResult;
import org.openid4java.discovery.DiscoveryInformation;
import org.openid4java.discovery.Identifier;
import org.openid4java.message.AuthRequest;
import org.openid4java.message.ParameterList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.List;
public final class OpenIDServlet extends HttpServlet implements RemoteService {
private final ConsumerManager manager;
public OpenIDServlet() {
try {
manager = new ConsumerManager();
} catch (ConsumerException e) {
throw new RuntimeException("Error creating consumer manager", e);
}
}
...
private void authenticate(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
final String loginString = request.getParameter(nameParameter);
try {
// perform discovery on the user-supplied identifier
List discoveries = manager.discover(loginString);
// attempt to associate with the OpenID provider
// and retrieve one service endpoint for authentication
DiscoveryInformation discovered = manager.associate(discoveries);
// obtain a AuthRequest message to be sent to the OpenID provider
AuthRequest authReq = manager.authenticate(discovered, "openid", null);
// redirect to OpenID for authentication
response.sendRedirect(authReq.getDestinationUrl(true));
}
catch (OpenIDException e) {
throw new ServletException("Login string probably caused an error. loginString = " + loginString, e);
}
}
My question now is:
What could be my fault? Did I make any mistakes in importing the openid4java library? (which?)
All other methods in the servlet which do not use the openid4java implementation work fine.
Thanks,
Andreas
You are using Google App Engine. GAE restricts the libraries that can be used in an application. In particular, creating threads or accessing the network are prohibited.
The stack trace you pasted shows openid creating a java, and GAE blocking it.
If you don't care about GAE, just disable it in eclipse settings. Once you do that, you should be able to use the library.
If you also want to use GAE, then you will have to find an alternative to OpenId4Java. Somebody else may have an alternative to that.
Due to the restrictions of GAE you can't use openid4java directly.
You can try this modified version: http://github.com/WdWeaver/openid4java-gae-hacks
I think you're missing the servlet entry in web.xml
<servlet>
<servlet-name>OpenIdServlet</servlet-name>
<servlet-class>path.to.your.servlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>OpenIdServlet</servlet-name>
<url-pattern>/openid/openid</url-pattern>
</servlet-mapping>

Categories