I am deploying a GWT application on Equinox. It runs, but when I launch an event to call server, I have an error like this:
<title>Error 500 non-HTTP request or response</title>
</head>
<body><h2>HTTP ERROR 500</h2>
<p>Problem accessing /zbapp/zbapp/app. Reason:
<pre> non-HTTP request or response</pre></p><h3>Caused by:</h3><pre>javax.servlet.ServletException: non-HTTP request or response
at javax.servlet.http.HttpServlet.service(HttpServlet.java:715)
at org.eclipse.equinox.http.registry.internal.ServletManager$ServletWrapper.service(ServletManager.java:180)
at org.eclipse.equinox.http.servlet.internal.ServletRegistration.service(ServletRegistration.java:61)
at org.eclipse.equinox.http.servlet.internal.ProxyServlet.processAlias(ProxyServlet.java:126)
at org.eclipse.equinox.http.servlet.internal.ProxyServlet.service(ProxyServlet.java:60)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.eclipse.equinox.http.jetty.internal.HttpServerManager$InternalHttpServiceServlet.service(HttpServerManager.java:318)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:390)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
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:939)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756)
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)
</pre>
<hr /><i><small>Powered by Jetty://</small></i><br/>
My web.xml is:
<servlet>
<servlet-name>greetServlet</servlet-name>
<servlet-class>main.java.com.gwt.app.server.GreetingServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>greetServlet</servlet-name>
<url-pattern>/zbapp/app</url-pattern>
</servlet-mapping>
I do not know what is the eral cause of that error. I have overriden service method from HttpServlet in the implementation of GWT Service.
Could someone help me, please?
It fails because of this reason
try {
request = (HttpServletRequest) req;
response = (HttpServletResponse) res;
} catch (ClassCastException e) {
throw new ServletException("non-HTTP request or response");
}
The Request/Response is not of HttpServletRequest/HttpServletResponse type.
Somewhere in the code you are trying to wrap request/response using a class which extends ServletRequest/ServletResponse. If the application wants to wrap a request/response, the wrapper class should ideally extend HttpServletRequestWrapper/HttpServletResponseWrapper.
Related
I'm using Resteasy 3.0.11.Final with JBoss AS 5.1.0 GA. I have a defined REST web service. The whole service is secured with BASIC authentication with a custom security domain. When I use Postman to send a request (#1) with BASIC authentication for user A, JBoss AS invokes a login module for the user, and then calls a local ejb (looked up with initial context) method with caller principal A. Immidiately after I send another request (#2) with BASIC authentication for user B, in this case JBoss AS does not invoke a login module and calls a local ejb method with caller principal A again. After some time sending a request with user B yields the desired result (local ejb method call with caller principal B). I'm not sure what causes the problem, the Resteasy service configuration / session handling or the JBoss AS security domain configuration which is responsible for login modules (subject timeout? lack of logout after method being called?)? Basically I want to configure Resteasy to force a new session with a new login module invocation for the local ejb method call for every rest request.
web.xml:
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>my-app</display-name>
<context-param>
<param-name>resteasy.providers</param-name>
<param-value>org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider,com.mycompany.infrastructure.ExceptionMapper</param-value>
</context-param>
<context-param>
<param-name>resteasy.resources</param-name>
<param-value>com.mycompany.resource.Resource</param-value>
</context-param>
<listener>
<listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener>
<servlet>
<servlet-name>my-app-resteasy-servlet</servlet-name>
<servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
<init-param>
<param-name>javax.ws.rs.core.Application</param-name>
<param-value>com.mycompany.application.Application</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>my-app-resteasy-servlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<security-constraint>
<web-resource-collection>
<web-resource-name>my-app-resteasy-servlet</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>User</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>MyRealm</realm-name>
</login-config>
<security-role>
<role-name>User</role-name>
</security-role>
</web-app>
jboss-web.xml
<jboss-web>
<context-root>/path</context-root>
<security-domain>java:/jaas/MyRealm</security-domain>
</jboss-web>
beans.xml
<beans
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
bean-discovery-mode="all">
</beans>
login-config.xml for MyRealm
<application-policy name="MyRealm">
<authentication>
<login-module code="com.mycompany.security.UsernamePasswordLoginModuleImpl"
flag="required">
<module-option name="password-stacking">useFirstPass</module-option>
</login-module>
</authentication>
</application-policy>
Resource.java
#Path("/resource")
#Stateless
public class Resource {
#POST
#Path("/execute")
#Consumes(MediaType.APPLICATION_JSON)
#Produces(MediaType.APPLICATION_JSON)
public ResponseDTO execute(RequestDTO dto) {
try {
// code
} catch (Exception exception) {
// handle
}
}
}
I found a very rough solution:
Resource.java:
#Path("/resource")
#Stateless
public class Resource {
#POST
#Path("/execute")
#Consumes(MediaType.APPLICATION_JSON)
#Produces(MediaType.APPLICATION_JSON)
public ResponseDTO execute(RequestDTO dto, #Context HttpServletRequest request) {
try {
// code
} catch (Exception exception) {
// handle
} finally {
if (request != null) {
request.getSession().invalidate();
}
}
}
}
or the same result, different implementation (without repeating the same code in every method in a resource, obviously):
SessionInvalidatorFilter.java
public class SessionInvalidatorFilter implements ContainerResponseFilter {
#Context
private HttpServletRequest request;
public void filter(ContainerRequestContext requestCtx, ContainerResponseContext responseCtx) throws IOException {
if ((request != null) && (request.getSession() != null)) {
request.getSession().invalidate();
}
}
}
web.xml
<context-param>
<param-name>resteasy.providers</param-name>
<param-value>com.mycompany.infrastructure.filter.SessionInvalidatorFilter</param-value>
</context-param>
I am experimenting with server sent event. Am following this link https://jersey.java.net/documentation/latest/user-guide.html#d0e8376. When I make request to the resource representing Server Sent Event, I get 500 Internal server error.
According to following error, I have to register the body writer for org.glassfish.jersey.media.sse.EventOutput. But, how to do it?
####<21 Nov, 2013 3:17:28 PM IST> <Error> <com.sun.jersey.spi.container.ContainerResponse> <Laptop1> <AdminServer> <[ACTIVE] ExecuteThread: '16' for queue: 'weblogic.kernel.Default (self-tuning)'> <<anonymous>> <> <> <1385027248248> <BEA-000000> <Mapped exception to response: 500 (Internal Server Error)
javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException: A message body writer for Java class org.glassfish.jersey.media.sse.EventOutput, and Java type class org.glassfish.jersey.media.sse.EventOutput, and MIME media type text/event-stream was not found
at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:285)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1479)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1391)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1381)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:538)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:716)
at weblogic.jaxrs.server.portable.servlet.ServletContainer.service(ServletContainer.java:218)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:844)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:280)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:254)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:136)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:341)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:238)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3363)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3333)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2220)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2146)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2124)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1564)
at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:254)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:295)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:254)
Caused By: com.sun.jersey.api.MessageException: A message body writer for Java class org.glassfish.jersey.media.sse.EventOutput, and Java type class org.glassfish.jersey.media.sse.EventOutput, and MIME media type text/event-stream was not found
at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:285)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1479)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1391)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1381)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:538)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:716)
at weblogic.jaxrs.server.portable.servlet.ServletContainer.service(ServletContainer.java:218)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:844)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:280)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:254)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:136)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:341)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:238)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3363)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3333)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2220)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2146)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2124)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1564)
at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:254)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:295)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:254)
Here is solution for my own question.
To register SseFeature, getSingletons method should be overridden in Application derived class, as show in below code.
#javax.ws.rs.ApplicationPath("webresources")
public class ApplicationConfig extends Application {
//....
#Override
public Set<Object> getSingletons() {
Set<Object> singletons = super.getSingletons();
if(singletons == null){
singletons=new java.util.HashSet<Object>();
}
singletons.add(new SseFeature());
return singletons;
}
//....
}
to use jersey latest version ( jersey 2.8 ) we should get rid of com.sun.jersey.api
Jersey APIs are now in org.glassfish.jersey package.
I suggest you to go through the following post and resolve the issues
check the update in question and comments
NoClassDefFoundError ProcessingException while migrating from jersey 1.x to jersey 2.x ( 2.8 )
A form submit event in GWT and GQuery is causing an IncompatibleRemoteServiceException. This project includes GQuery (GWT version of JQuery) which is used to call the form submit. Here's the code for it. The event is inserted in onmoduleload function:
$("#search_form").submit(new Function(){
public void f() {
QueryRequest query = new QueryRequest();
String keywords = $("#keyword_search_box").val();
query.setKeywords(keywords);
greetingService.search(query, new AsyncCallback<QueryResponse>() {
#Override
public void onFailure(Throwable caught) {
Window.alert(COUNLDNT_REACH_SERVER);
}
#Override
public void onSuccess(QueryResponse result) {
$("#page").add(renderResponse(result));
}
});
}
});
The exception shows up whenever the submit button is clicked. If the server call is made from outside the submit event, it works fine - otherwise public void onFailure(Throwable caught) is executed. Here's the exception:
Starting Jetty on port 8888
[WARN] greetServlet: An IncompatibleRemoteServiceException was thrown while processing this call.
com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException: This application is out of date, please click the refresh button on your browser. ( Could not locate requested method 'greetServer(com.project.shared.QueryRequest)' in interface 'com.project.client.GreetingService' )
at com.google.gwt.user.server.rpc.RPC.decodeRequest(RPC.java:310)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:206)
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:487)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
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:729)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:324)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
Most possible reason is jars version.
Check if the gwt-servlet.jar is uptodate. The gwt-user.jar and gwt-servlet.jar must have the same version.
see A discussion here on the same.
I've created axs 2 web service with rampart ws security in eclipse (here s the tutorial I follow TUTORIAL PAGE - 18-21
I've aplied the policy in service.xml by adding this code AND ENGAGED RAMPART MODULE
<wsp:Policy wsu:Id="UTOverTransport"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
<wsp:ExactlyOne>
<wsp:All>
<sp:SignedSupportingTokens
xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:UsernameToken
sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient" />
</wsp:Policy>
</sp:SignedSupportingTokens>
<ramp:RampartConfig xmlns:ramp="http://ws.apache.org/rampart/policy">
<ramp:passwordCallbackClass>axis2wstest.PWCBHandler</ramp:passwordCallbackClass>
</ramp:RampartConfig>
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
Then I create web service client - here is the code
public static void main(String[] args) throws RemoteException {
ConfigurationContext ctx;
ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem("C:/Users/Tanya/workspace/testlnclient/WebContent/WEB-INF", null);
TestlnStub stub = new TestlnStub(ctx);
Testws cl = new Testws();
cl.setX(5);
ServiceClient client = stub._getServiceClient();
client.engageModule("rampart");
//client.addHeader(omSecurityElement);
org.apache.axis2.client.Options o = client.getOptions();
o.setPassword("pass");
o.setUserName("test");
TestwsResponse resp = stub.testws(cl);
System.out.println("Response" + resp.get_return());
// TODO Auto-generated method stub
}
}
but it gives me an excetion
exception in thread "main" org.apache.axis2.AxisFault: java.lang.NullPointerException
at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:531)
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:375)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:421)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at axis2wstest.TestlnStub.testws(TestlnStub.java:191)
at axis2wstest.testlnclient.main(testlnclient.java:35)
The presence of Utils.getInboundFaultFromMessageContext in the stack trace indicates that the NullPointerException is actually coming from the service and not thrown by the client. Check the server logs to see where the NullPointerException occurs.
Started a new project from scratch, converted to JPA, my persistence provider is EclipseLink, added the necessary libraries (eclipselink.jar, eclipselink.jar, javax.persistence, mysql-connector-java-5.1). Tested the connection, ping ok. Then created a new package New > JPA > Entities from Tables > Selected all Entities and Key generator > Identity.
GestorIpca.java
GestorIpcaService.util.getInstance().getLista(new AsyncCallback<ArrayList<Docente>>() {
#Override
public void onFailure(Throwable caught) {
Window.alert("Erro na Ligacao efectuada");
caught.getStackTrace();
}
#Override
public void onSuccess(ArrayList<Docente> result) {
Window.alert("Ligacao efectuada com sucesso:" + result.size());
}
});
GestorIpcaService
#RemoteServiceRelativePath("greet")
public interface GestorIpcaService extends RemoteService {
String greetServer(String name) throws IllegalArgumentException;
public static class util{
public static GestorIpcaServiceAsync instance;
public static GestorIpcaServiceAsync getInstance(){
if(instance == null){
instance = GWT.create(GestorIpcaService.class);
}
return instance;
}
}
public ArrayList<Docente> getLista() throws IllegalArgumentException;
}
GestorIpcaServiceAsync
public interface GestorIpcaServiceAsync {
void greetServer(String input, AsyncCallback<String> callback)
throws IllegalArgumentException;
void getLista(AsyncCallback<ArrayList<Docente>> callback);
}
GestorIpcaServiceImpl
#SuppressWarnings("serial")
public class GestorIpcaServiceImpl extends RemoteServiceServlet implements
GestorIpcaService {
public ArrayList<Docente> getLista() throws IllegalArgumentException {
//Criamos um EntityManager
EntityManager em = JpaUtil.getEntityManagerFactory().createEntityManager();
//Criamos a consulta
String consulta = "SELECT r from Docente r";
//Executamos a consulta
Query q = em.createQuery(consulta);
ArrayList<Docente> lista = new ArrayList<Docente>(q.getResultList());
return lista;
}
/* public static void main(String args[]){
GestorIpcaServiceImpl serviceImpl = new GestorIpcaServiceImpl();
for (Docente docente : serviceImpl.getLista()){
System.out.println("nome: " + docente.getNome());
}
}
*/
In this file i tried to run as > Java Application and in Console showed me 2 records.
Package com.GestorIpca.factory
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
public class JpaUtil {
private static final EntityManagerFactory emf;
//Método estático
static{
//BLoco try
try
{
//Criação de EntityManagerFactory
emf = Persistence.createEntityManagerFactory("GestorIpca");
}catch (Throwable e){
//Controlar as excepções
System.err.println("A criação de SessionFactory falhou" + e);
e.printStackTrace();
throw new ExceptionInInitializerError(e);
}
}
public static EntityManagerFactory getEntityManagerFactory(){
return emf;
}
}
My persistence.xml was created automatically. Placed inside META-INF
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="GestorIpca">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>com.GestorIpca.shared.Ano</class>
<class>com.GestorIpca.shared.Categoria</class>
<class>com.GestorIpca.shared.Curso</class>
<class>com.GestorIpca.shared.Disciplina</class>
<class>com.GestorIpca.shared.Disponibilidade</class>
<class>com.GestorIpca.shared.Docente</class>
<class>com.GestorIpca.shared.Sala</class>
<class>com.GestorIpca.shared.Semestre</class>
<class>com.GestorIpca.shared.TipoCurso</class>
<class>com.GestorIpca.shared.Turma</class>
<class>com.GestorIpca.shared.User</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/timetable"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="k771u3"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
</properties>
</persistence-unit>
</persistence>
Last step > Run as > Web Application
Error > Could not connect to database and print a stack trace in Eclipse Console
[EL Info]: 2011-05-09 10:03:08.78--ServerSession(8068087)--EclipseLink, version: Eclipse Persistence Services - 2.2.0.v20110202-r8913
[EL Info]: 2011-05-09 10:03:09.297--ServerSession(8068087)--file:/C:/Users/Martinho/WorkSpace/GestorIpca/war/WEB-INF/classes/_GestorIpca login successful
Starting Jetty on port 8888
[WARN] Exception while dispatching incoming RPC call
com.google.gwt.user.client.rpc.SerializationException: java.lang.reflect.InvocationTargetException
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeWithCustomSerializer(ServerSerializationStreamWriter.java:764)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeImpl(ServerSerializationStreamWriter.java:727)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:616)
at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:126)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter$ValueWriter$8.write(ServerSerializationStreamWriter.java:152)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeValue(ServerSerializationStreamWriter.java:534)
at com.google.gwt.user.server.rpc.RPC.encodeResponse(RPC.java:616)
at com.google.gwt.user.server.rpc.RPC.encodeResponseForSuccess(RPC.java:474)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:571)
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:487)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
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:729)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:324)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
Caused by: java.lang.reflect.InvocationTargetException
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.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeWithCustomSerializer(ServerSerializationStreamWriter.java:746)
... 30 more
Caused by: com.google.gwt.user.client.rpc.SerializationException: Type 'org.eclipse.persistence.indirection.IndirectSet' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.: instance = {IndirectSet: not instantiated}
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:614)
at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:126)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter$ValueWriter$8.write(ServerSerializationStreamWriter.java:152)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeValue(ServerSerializationStreamWriter.java:534)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeClass(ServerSerializationStreamWriter.java:704)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeImpl(ServerSerializationStreamWriter.java:734)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:616)
at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:126)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter$ValueWriter$8.write(ServerSerializationStreamWriter.java:152)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeValue(ServerSerializationStreamWriter.java:534)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeClass(ServerSerializationStreamWriter.java:704)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeImpl(ServerSerializationStreamWriter.java:734)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:616)
at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:126)
at com.google.gwt.user.client.rpc.core.java.util.Collection_CustomFieldSerializerBase.serialize(Collection_CustomFieldSerializerBase.java:45)
at com.google.gwt.user.client.rpc.core.java.util.ArrayList_CustomFieldSerializer.serialize(ArrayList_CustomFieldSerializer.java:38)
... 35 more
[ERROR] 500 - POST /gestoripca/greet (127.0.0.1) 57 bytes
Request headers
Host: 127.0.0.1:8888
Connection: keep-alive
Referer: http://127.0.0.1:8888/GestorIpca.html?gwt.codesvr=127.0.0.1:9997
Content-Length: 132
Origin: http://127.0.0.1:8888
X-GWT-Module-Base: http://127.0.0.1:8888/gestoripca/
X-GWT-Permutation: HostedMode
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.30 Safari/534.30
Content-Type: text/x-gwt-rpc; charset=UTF-8
Accept: */*
Accept-Encoding: gzip,deflate,sdch
Accept-Language: pt-PT,pt;q=0.8,en-US;q=0.6,en;q=0.4
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Response headers
Content-Type: text/plain
Note: I changed in package com.GestorIpca.shared all my classes generated from tables
public class Ano implements Serializable
to
public class Ano implements IsSerializable
changed also my GestorIpca.gwt.xml and added this lines in end
<extend-configuration-property name="rpc.blacklist" value="com.google.gwt.user.client.ui.*Collection"/>
<extend-configuration-property name="rpc.blacklist" value="-.*List"/>
<extend-configuration-property name="rpc.blacklist" value="-.*Map"/>
<extend-configuration-property name="rpc.blacklist" value="-.*Collection"/>
<extend-configuration-property name="rpc.blacklist" value="+java.util.HashMap"/>
<extend-configuration-property name="rpc.blacklist" value="+java.util.LinkedHashMap"/>
<extend-configuration-property name="rpc.blacklist" value="+java.util.ArrayList"/>
What am i missing?
I depends on how your entities were defined. Maybe there are connections that GWT RPC doesn´t like. in this case i´d suggest create DTO´s or implement RequestFactory
Without knowing what your entities look like I would guess from the exception that the reason is probably how your entities get enhanced by your persistence provider:
What this means for GWT RPC is that by the time the object is ready to be transferred over the wire, it actually isn't the same object that the compiler thought was going to be transferred, so when trying to deserialize, the GWT RPC mechanism no longer knows what the type is and refuses to deserialize it.
Cited from: http://code.google.com/intl/de-DE/webtoolkit/articles/using_gwt_with_hibernate.html
That article also suggests how to create DTOs to solve this problem.
I know this is a very old question, but I ran into this exact issue tonight.
GWT Serialization doesn't seem to like java.util.Set. I almost feel like it was confusing java.util.Set with org.eclipse.persistence.indirection.IndirectSet.
Once I switched Set to ArrayList, the error went away.