Jetty and GWT (Google Web Toolkit) - gwt

As I understand it, GWT uses an embedded Jetty server. Can
anyone please tell me where I can find the Jetty .xml configuration files
used by GWT? I have a webapp which makes uses of Jetty's
ContinuationFilter and ProxyServlet. The app works fine under GWT but
fails when run in a separate Jetty instance outside of GWT. If I can
replicate the GWT Jetty config then I think I'll be okay.
Edit for more info:
My webapp's web.xml reads as follows:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<filter>
<filter-name>JettyContinuationFilter</filter-name>
<filter-class>org.eclipse.jetty.continuation.ContinuationFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>JettyContinuationFilter</filter-name>
<url-pattern>/bugzilla/*</url-pattern>
</filter-mapping>
<!-- Servlets -->
<servlet>
<servlet-name>greetServlet</servlet-name>
<servlet-class>com.searchsystem.gwt.server.GreetingServiceImpl</servlet-class>
</servlet>
<servlet>
<servlet-name>jetty-proxy-servlet</servlet-name>
<servlet-class>org.eclipse.jetty.servlets.ProxyServlet$Transparent</servlet-class>
<init-param>
<param-name>ProxyTo</param-name>
<param-value>http://localhost/</param-value>
</init-param>
<init-param>
<param-name>Prefix</param-name>
<param-value>/</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>greetServlet</servlet-name>
<url-pattern>/dashboard/greet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>jetty-proxy-servlet</servlet-name>
<url-pattern>/bugzilla/*</url-pattern>
</servlet-mapping>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>Dashboard.html</welcome-file>
</welcome-file-list>
</web-app>
and the link to my Bugzilla installation is in this form:
com.google.gwt.user.client.ui.Frame bugFrame = new Frame("/bugzilla/");
Running under Jetty 6.1.26, I get this output:
Request Attributes
Attribute: Value:
javax.servlet.forward.request_uri /bugzilla/
org.mortbay.jetty.error_page /jspsnoop/ERROR/404
javax.servlet.forward.servlet_path /bugzilla/
testFilter 1
javax.servlet.error.message NOT_FOUND
requestInitialized ''
javax.servlet.forward.context_path
javax.servlet.error.status_code 404
javax.servlet.error.servlet_name default
org.mortbay.jetty.newSessionId 47deq3eo5kblxfrvtc5rljrg
javax.servlet.error.request_uri /bugzi
lla/

there is no jetty.xml. GWT sets up the Server programmatically.
You can find the setup in
com.google.gwt.dev.shell.jetty.JettyLauncher
contained in the gwt-dev.jar

See: Serving a GWT Application with an Embedded Jetty Server by Brandon Tilley (code extract shown below). He seems to have achieved it quite seamlessly, a process which I will be confirming myself tomorrow.
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.eclipse.jetty.webapp.WebAppContext;
public class EmbeddedGwt {
public static void main(String[] args) throws Throwable {
// Create an embedded Jetty server on port 8080
Server server = new Server(8080);
// Create a handler for processing our GWT app
WebAppContext handler = new WebAppContext();
handler.setContextPath("/");
handler.setWar("./apps/GwtApplication.war");
// If your app isn't packaged into a WAR, you can do this instead
WebAppContext altHandler = new WebAppContext();
altHandler.setResourceBase("./apps/GwtApplication");
altHandler.setDescriptor("./apps/GwtApplication/WEB-INF/web.xml");
altHandler.setContextPath("/");
altHandler.setParentLoaderPriority(true);
// Add it to the server
server.setHandler(handler);
// Other misc. options
server.setThreadPool(new QueuedThreadPool(20));
// And start it up
server.start();
server.join();
}
}

Related

adding RichFaces breaks my JSF project

I have a simple JSF project which works just fine; after adding RichFaces to it, it stops working properly
Environment: Eclipse IDE, JSF 2.1 (Apache MyFaces 2.1.5), Tomcat v7.0 Server (Location: workspace metadata, Server Locations: Use Tomcat installation); http://localhost:8181/ gives me the admin console, so the server is running ok
The application: a Dynamic Web Project (version 3.0) named jsf1;
under WebContent, i have a page named main.xhtml (For brevity, i won't paste the content, because things work well so far; Its a simple hello world page);
the faces-config.xml is left unchanged;
the web.xml contains:
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
In Project Explorer, i right click on the project > Run As > Run on Server, and the application is accessible in a web browser at the url http://localhost:8181/jsf1/faces/main.xhtml
Adding RichFaces: i followed the instructions given at https://docs.jboss.org/richfaces/latest_3_3_X/en/devguide/html/GettingStarted.html
under WEB-INF/lib i have added all the required jars
i have appended to web.xml the following content:
<!-- Plugging the "Blue Sky" skin into the project -->
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>blueSky</param-value>
</context-param>
<!-- Making the RichFaces skin spread to standard HTML controls -->
<context-param>
<param-name>org.richfaces.CONTROL_SKINNING</param-name>
<param-value>enable</param-value>
</context-param>
<!-- Defining and mapping the RichFaces filter -->
<filter>
<display-name>RichFaces Filter</display-name>
<filter-name>richfaces</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
<filter-mapping>
<filter-name>richfaces</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
Now, when i run the project on server, in the console i get:
SEVERE: Exception starting filter richfaces
java.lang.ClassNotFoundException: org.ajax4jsf.Filter
I added the richfaces-impl-3.3.3.Final.jar, which contains the org.ajax4jsf.Filter class.
Now, when i run the project on server,the console contains no errors, however, the link http://localhost:8181/jsf1/faces/main.xhtml displays a blank page.
How is it possible to create a functional RichFaces application?

Jersey REST Web Service, Tomcat, Eclipse and 404's

I've read through a number of posts, but just can't seem to solve my problem. You'll also see tons of posts very similar to this one, even the same tutorial. Even following them, I can't seem to get to the answer.
Essentially, I'm trying to follow the simple tutorial at: http://www.vogella.com/articles/REST/
I've made a few changes to make it compatible with Jersey 2.x
I'm using:
Eclipse
Tomcat 6 (Deployed/Run as within Eclipse)
jaxrs-ri-2.0
I've enabled the JAX-RS Facet in Eclipse
Everything builds fine
Tomcat starts fine within Eclipse
I can get to a static page content via:
http://localhost:8080/RestTEST2/index.html
However, when I try to access my service via:
http://localhost:8080/RestTEST2/jaxrs/hello
I receive a 404 with "message not found" and "The requested resource (Not Found) is not available."
Here is my web.xml which is located at /WebContent/WEB-INF/web.xml
<?xml version="1.0" encoding="UTF-8"?>
<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>TestREST2</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<description>JAX-RS Tools Generated - Do not modify</description>
<servlet-name>JAX-RS Servlet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>TestREST</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>JAX-RS Servlet</servlet-name>
<url-pattern>/jaxrs/*</url-pattern>
</servlet-mapping>
</web-app>
Here is my Java class:
package TestREST;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
// Plain old Java Object it does not extend as class or implements
// an interface
// The class registers its methods for the HTTP GET request using the #GET annotation.
// Using the #Produces annotation, it defines that it can deliver several MIME types,
// text, XML and HTML.
// The browser requests per default the HTML MIME type.
//Sets the path to base URL + /hello
#Path("/hello")
public class Hello {
// This method is called if TEXT_PLAIN is request
#GET
#Produces(MediaType.TEXT_PLAIN)
public String sayPlainTextHello() {
return "Hello Jersey";
}
// This method is called if XML is request
#GET
#Produces(MediaType.TEXT_XML)
public String sayXMLHello() {
return "<?xml version=\"1.0\"?>" + "<hello> Hello Jersey" + "</hello>";
}
// This method is called if HTML is request
#GET
#Produces(MediaType.TEXT_HTML)
public String sayHtmlHello() {
return "<html> " + "<title>" + "Hello Jersey" + "</title>"
+ "<body><h1>" + "Hello Jersey" + "</body></h1>" + "</html> ";
}
}
I also have a JAX-RS User Library configured and referenced that includes all the JAX-RS jars.
Thoughts on what would cause the web service to not be found?
Jersey 2.0 does not recognize init-param with name com.sun.jersey.config.property.packages (web.xml). Try to change it to jersey.config.server.provider.packages as described in ServerProperties.PROVIDER_PACKAGES.
UPDATE (2020): try this link for current apidocs ServerProperties.PROVIDER_PACKAGES:
Thanks a lot.. i've been fighting for it as well.
This combination worked for me:
Tomcat 7.0.55
Eclipse Luna
Java 1.6
Jersey 1.7
web.xml:
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.trgr.cobalt.cmdb.jersey.resource;com.trgr.cobalt.cmdb.jersey.beans;com.trgr.cobalt.cmdb.elasticity</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
I would like to add one answer in this post.I was struggling with same problem for two days and couldn't find the solution.
I tried all the possible solutions provided here but later on I realized that server was giving error of
org.glassfish.jersey.servlet.ServletContainer ClassNotFoundException
This link answers gives the solution if somebody is stuck like me..
org.glassfish.jersey.servlet.ServletContainer ClassNotFoundException
Actually first answer given in this post suggest the solution which is for jersey 2.x bundle and if you are using jersey 1.x then it will keep on giving error.
Kindly refer to link given in answer for further reference
Simply by modifying the configuration of Apache Tomcat v7.0 while creating Dynamic Web Project, to include REST, I solved my problem. It is not enabled by default.
Recently I found myself stuck in this problem. I have got it resolved by following these two points as the solution:
By making the src/main/java as the source directory, and keeping the Project Structure as shown below:
Changing com.sun.jersey.config.property.packages to jersey.config.server.provider.packages in the web.xml

Injection of an EJB into a web java class under JBoss 7.1.1

I am trying to build a website using JBoss 7.1.1 and RESTeasy. I have managed to constructed and deploy and EAR with a both a WAR and an EJB-JAR contained within:
voyager-app.ear
META-INF/MANIFEST.MF
META-INF/application.xml
META-INF/jboss-app.xml
lib/voyager-lib.jar
voyager-adm.war
voyager-ejb.jar
voyager-web.war
So far things are very simple. voyager-adm.war & voyager-lib.jar are empty (just the manifest file) but I know that I'm going to have code for them shortly. There is just one Stateful EJB - HarbourMasterBean (with just a local interface) and a few Database Entity Beans in the EJB jar file:
voyager-ejb.jar
META-INF/MANIFEST.MF
META-INF/persistence.xml
com/nutrastat/voyager/db/HarbourMasterBean.class
com/nutrastat/voyager/db/HarbourMasterLocal.class
com/nutrastat/voyager/db/PortEntity.class
com/nutrastat/voyager/db/ShipEntity.class
As far as I can tell the EJBs deploy correctly because the database units are created and the log shows that the publication of some HarbourMaster references:
java:global/voyager-app/voyager-ejb/harbour-master!com.nutrastat.voyager.db.HarbourMasterLocal
java:app/voyager-ejb/harbour-master!com.nutrastat.voyager.db.HarbourMasterLocal
java:module/harbour-master!com.nutrastat.voyager.db.HarbourMasterLocal
java:global/voyager-app/voyager-ejb/harbour-master
java:app/voyager-ejb/harbour-master
java:module/harbour-master
The problem lies in getting the HarbourMaster EJB injected into my web bean. The reference to it is alway NULL no matter what I try.
voyager-web.war
META-INF/MANIFEST.MF
WEB-INF/web.xml
WEB-INF/classes/com/nutrastat/voyager/web/
WEB-INF/classes/com/nutrastat/voyager/web/Ships.class
WEB-INF/classes/com/nutrastat/voyager/web/VoyagerApplication.class
Ships.java:
#Path("fleet")
public class Ships {
protected transient final Logger log;
#EJB
private HarbourMasterLocal harbourMaster;
public Ships() {
log = LoggerFactory.getLogger(getClass());
}
#GET
#Path("ships")
#Produces({"text/plain"})
public String listShips() {
if (log.isDebugEnabled())
log.debug("Harbour master value: " + harbourMaster);
return "Harbour Master: " + harbourMaster;
}
}
<web-app
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0" >
<display-name>Voyager Web Application</display-name>
<listener>
<listener-class>
org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
</listener-class>
</listener>
<servlet>
<servlet-name>Resteasy</servlet-name>
<servlet-class>
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
</servlet-class>
<init-param>
<param-name>
javax.ws.rs.Application
</param-name>
<param-value>
com.nutrastat.voyager.web.VoyagerApplication
</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Resteasy</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
I have been searching the web for an answer and read a number of places, both on StackOverflow and elsewhere that suggests is can be done, and that the problems lies with configuration. But they post only snippets and I'm never sure if I'm doing things correctly.
Many thanks for any help you can provide.
Dobbo
What happens if you do:
#Path("fleet")
#Singleton
public class Ships {

how to deploy GWT app to tomcat

I searched this site for answer to this question and couldn't find a solution.
what i did is that i simply compress the war directory in my eclipse GWT app project then rename it to .war then drop it to tomcat webapps folder.
when i run the web app, the first screen is successfully shown but when i call a servlet within my src code it gives me resource not found by tomcat server.
i'm sure i have added entry for servlet in web.xml file and the app worked well when i run it in eclipse gwt dev mode. something prevent my servlets (standard servlets not GWT RPC servlets) to be found and executed by tomcat. what could be the reason?
UPDATE
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<!-- Servlets -->
<servlet>
<servlet-name>OAuth</servlet-name>
<servlet-class>org.goauth.server.OAuthServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>OAuth</servlet-name>
<url-pattern>/goauth/oauth</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>OAuthCallback</servlet-name>
<servlet-class>org.goauth.server.OAuthCallbackServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>OAuthCallback</servlet-name>
<url-pattern>/goauth/callback</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>service</servlet-name>
<servlet-class>org.goauth.server.OAuthServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>service</servlet-name>
<url-pattern>/goauth/service</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>OAuthConfirm</servlet-name>
<servlet-class>org.goauth.server.OAuthConfirmServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>OAuthConfirm</servlet-name>
<url-pattern>/goauth/confirm</url-pattern>
</servlet-mapping>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>GOAuth.html</welcome-file>
</welcome-file-list>
</web-app>
Error
nothing in tomcate logs files
the only error in browser is :
HTTP Status 404 - /goauth/oauth
type Status report
message /goauth/oauth
description The requested resource (/goauth/oauth) is not available.
Apache Tomcat/6.0.20
I found the problem :
for invoking my servlet i was calling a url of the format : "/goauth/OAuth"
this worked with eclipse gwt plugin in dev mode but not when i deploy war to tomcat server.
the solution is that my url pointing to my servlet should be of the form :
String href = GWT.getHostPageBaseURL()+"goauth/OAuth";
so we need to tell tomcat the full url by prefixing servlet url with GWT.getHostPageBaseURL().
Take a look at how to create a GWT .war in eclipse: http://blog.elitecoderz.net/gwt-and-tomcat-create-war-using-eclipse-to-deploy-war-on-tomcat/2009/12/
In your mapping, try changing
/goauth/oauth
to /OAuth

Bare minimum necessary for a single Jersey GET resource?

I am missing something obvious, but I'm not sure what. I have a single "HelloWorld.java" that has a single #GET method that returns some text.
My web.xml was taken from this doc (described as "An even simpler approach is to let Jersey choose the PackagesResourceConfig implementation automatically...."):
<web-app>
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.hello.rest</param-value>
</init-param>
</servlet>
</web-app>
Here's my class (mostly taken from here):
package com.hello.rest;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import javax.ws.rs.Path;
#Path("/helloworld")
public class HelloWorld {
#GET
#Produces("text/json")
public String getHelloWorld() {
return "{\"hello\":\"World\"}";
}
}
I use ant to build a war file, and deploy it to tomcat. The war appears correct because tomcat unzips it and I can access my static index.html that I put in it for testing. But accessing localhost:8080/helloworld gives me a 404. There must be some other piece I need in order to get Jersey working. What did I miss?
Thank you Bozho, I was missing the <servlet-mapping> section. Actually it appears I don't want a "/" as url-pattern, because that prevents serving static content (I can't get my index.html page any more!) so here's my new web.xml (I put my resource in the "/data/" path):
<web-app>
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.hello.rest</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/data/*</url-pattern>
</servlet-mapping>
</web-app>
Now I can access my index.html page as http://localhost:8080/hello/index.html, and my resource at http://localhost:8080/hello/data/helloworld.
You have to map your servlet with <servlet-mapping>, with a / as url-pattern