gwt - problem accessing servlet in inherited module - gwt

I'm trying to divide my app into modules and I'm stuck with this problem:
I have a widget MapServiceWidget in one module called "webvisualisation" that uses the RPC to get the data from MapService Rpc interface. I'm inheriting this module in another GWT module called "led" (I packed "webvis..." into jar with sources, added in module "led" deffinition). Then I try to create this widget in the second ("led") module and get message
"Problem accessing /led/mapservice reason NOT FOUND".
And sure it can't find it cause mapservice is defined in inherited "webvisualisation" module.
The question is why it's looking for this servler implementation in "led" module not in "webvisualisation" where it's defined? I checked all module definitions and web.xml files several times and consulted documentations, it seems ok.. but it's not. If my description is not clear I can post some config/source files.
This is web.xml for webvisualisation module
<!-- Servlets -->
<servlet>
<servlet-name>mapservice</servlet-name>
<servlet-class>pl.gmike.webvis.server.MapServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>mapservice</servlet-name>
<url-pattern>/webvisualisation/mapservice</url-pattern>
</servlet-mapping>
And for led it's just ordinary generated sample file
<!-- Servlets -->
<servlet>
<servlet-name>greetServlet</servlet-name>
<servlet-class>pl.led.server.GreetingServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>greetServlet</servlet-name>
<url-pattern>/led/greet</url-pattern>
</servlet-mapping>

Seems that you're bumping into a classpath problem. Maybe check that your webvisualisation.jar is in the WEB-INF/lib directory of your web application.

I got it working. I just added servlet and servlet mapping entries to "led" modules web.xml so it look like this now:
<!-- Servlets -->
<servlet>
<servlet-name>greetServlet</servlet-name>
<servlet-class>pl.led.server.GreetingServiceImpl</servlet-class>
</servlet>
<servlet>
<servlet-name>mapservice</servlet-name>
<servlet-class>pl.gmike.webvis.server.MapServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>greetServlet</servlet-name>
<url-pattern>/led/greet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>mapservice</servlet-name>
<url-pattern>/led/mapservice</url-pattern>
</servlet-mapping>
As You can see the mapservice servlet is mapped here to /led/mapservice URL where GWT seems to look for it, unlike in original "webvisualisation" module web.xml where it was mapped to /wevisualisation/mapservice .
I'm not very satisfied with this solution, it works but it requires adding a servlet mapping in WebApps web.xml for every servlet in inherited module that I want to use or that is used somewhere in this inherited module.
Still I would like to know why servlet definitions and mappings from inherited modules are not included in WebApps web.xml during compilation/linking... I think it should work without such hacks, so there's something I'm doing wrong.

Related

Vaadin 7.1.0 - DefaultWidgetSet can't be found

I am new to Vaadin and I am trying to do some Tests with this technology.
I Set up my project as a Maven Project under Eclipse with a Tomcat 7 Server.
At first I started with Vaadin 7.0.0 and everything works fine. Now I change the Version from 7.0.0 to 7.1.0 because I like to test the push functionality.
With Vaadin 7.0.0 everything works fine, but since I changed the Version I get the error:
Requested resource [/VAADIN/widgetsets/com.vaadin.DefaultWidgetSet /com.vaadin.DefaultWidgetSet.nocache.js] not found from filesystem or through class loader. Add widgetset and/or theme JAR to your classpath or add files to WebContent/VAADIN folder.
I've read that the DefaultWidget is created by Vaadin but how can I do that?
Unless you add new client-side components to a Vaadin project, you don't need to compile a WidgetSet. However, the default configuration of Vaadin assumes that you have one. To get past this error simply remove the <init-param> tag for the widgetset in your web.xml.
<servlet>
<servlet-name>Your-SERVLET-NAME</servlet-name>
<servlet-class>com.vaadin.server.VaadinServlet</servlet-class>
<init-param>
<param-name>UI</param-name>
<param-value>com.example.MyUI</param-value>
</init-param>
<init-param>
<param-name>widgetset</param-name>
<param-value>another.path</param-value>
</init-param>
</servlet>
Alternatively, you can create an .xml file in the same package (e.g. MyWSet.xml) as your UI class, and reference it in your web.xml.
MyWSet.xml in com.example package:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 1.7.0//EN" "http://google-web-toolkit.googlecode.com/svn/tags/1.7.0/distro-source/core/src/gwt-module.dtd">
<module>
<inherits name="com.vaadin.DefaultWidgetSet" />
</module>
The right web.xml:
<servlet>
<servlet-name>Your-SERVLET-NAME</servlet-name>
<servlet-class>com.vaadin.server.VaadinServlet</servlet-class>
<init-param>
<param-name>UI</param-name>
<param-value>com.example.MyUI</param-value>
</init-param>
<init-param>
<param-name>widgetset</param-name>
<param-value>com.example.MyWSet</param-value>
</init-param>
</servlet>
Remember, you don't need the .xml suffix in your web.xml. Finally, run mvn vaadin:compile to compile this widgetset.
Adding vaadin-client-compiled worked for me as mentioned in https://vaadin.com/forum/thread/2485026/2496683
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-client-compiled</artifactId>
</dependency>

404 error in gwt project- servlet is correctly defined in web.xml but still getting 404 error

I am working to create a web app using GWT+Java backend. The host page is "App.html"
The app also has a RPC, and the host page when initially loaded, makes an RPC call.
However this is the message I am getting from Javascript console in Google Chrome browser-
POST http://app.sparkcrawler.com/com.arvindikchari.auth.App/AuthenticationService 404(Not Found)
Given below are the contents of my web.xml--
<?xml version................................>
<servlet>
<servlet-name>AuthenticationService</servlet-name>
<servlet-class>com.arvindikchari.auth.server.AuthenticationServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AuthenticationService</servlet-name>
<url-pattern>/com.arvindikchari.auth.App/AuthenticationService</url-pattern>
</servlet-mapping>
What am I doing wrong here? How do I resolve this error?
The problem is with your servlet mapping.
Basically, you have two things in web.xml (regarding servlets):
the <servlet> tag, which defines the alias for the servlet, and its
fully-qualified name (In your case AuthenticationService and com.arvindikchari.auth.server.AuthenticationServiceImpl)
the <servlet-mapping> which specifies a url-pattern for a given alias
(taken from the <servlet> definitions).
It should be like
<servlet-mapping>
<servlet-name>AuthenticationService</servlet-name>
<url-pattern>/authenticationService</url-pattern>
</servlet-mapping>
I think your servlet mapping url pattern looks wrong.
normally when mapping any servlet <url-pattern> would be like this.
<`<url-pattern>/{app name}/{servlet name}</url-pattern>`
here app name would be same as registered app name which is in gwt.xml file.

jersey jackson multiple providers for same type

With Jersey, I am currently using the Gson library to convert my pojo to json back and forth.
However, I've discovered Jackson to be a lot faster so we are switching to this.
I already have a Gson custom Provider and Reader, and will now create (a modified) version for Jackson.
But during development, it would be good if I could swap them but is this possible? Since I mark the json provider with #produces and #consumes I dont think Jersey could resolve which one to use if there were two providers, each with the above annotations for the same type, in this case APPLICATION_JSON.
Is it possible to specify multiple Json providers, and then swap them in some config file (web.xml??) ?
I know if I created a Json Wrapper object I could code to an interface and using spring to swap implementations easily (jackson imp vs gson imp) but this would mean i wouldnt be doing it the Jax RS way. Also, I would be forced to return a String for all the GETs rather than let the providers convert it for me implicitly.
Any thoughts?
thanks
If you create your own subclass of ResourceConfig (or JAX-RS Application), it has a method named getClasses() - that's where you have to return set of resource and provider classes that your application uses. Now, seems you are using some of the pre-packaged ResourceConfig - Jersey has ResourceConfig that does class-path scanning (i.e. if you configure that one - or none - since this one is the default) it scans the whole class path for resource classes). There is one that is capable of package scanning - that one scans just the packages you list in your init params of Jersey servlet, etc.
Actually, the package scanning one may be best for you. Just make sure you put each of your JSON providers in a different package and then configure in web.xml which packages should be scanned for resources and providers. Here is an example of web.xml that configures Jersey to look for resources and providers in com.mycompany.resource and com.mycompany.providers.gson packages:
<web-app version="2.5" 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_2_5.xsd">
<servlet>
<servlet-name>Jersey Web Application</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.mycompany.resources,com.mycompany.providers.gson</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/webresources/*</url-pattern>
</servlet-mapping>
</web-app>
Had a problem like this with the multiple registered providers but none used. Add an init param to help determine which provider to user eg
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>

Adding an html form to an existing servlet

I have an existing servlet that has a form and takes in data and executes correctly. We've been given a new requirement to add a page that will allow the user to modify some of the values in the servlet properties file via a web form.
I've developed the package to do this. I'm looking for a way to add the page and package to the existing servlet. I would rather not create a separate servlet on Tomcat for this.
I know how to create new html pages in the existing servlet, but I'm unsure how to execute this class file without making it a standalone servlet.
Any help is appreciated.
I solved my problem. It seems I just needed to add the additional servlet to my web.xml. Resolved.
<servlet>
<description></description>
<display-name>Servlet1</display-name>
<servlet-name>Servlet1</servlet-name>
<servlet-class>com.mycompany.Servlet1</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ExporterServlet</servlet-name>
<url-pattern>/ExporterServlet</url-pattern>
</servlet-mapping>
<servlet>
<description></description>
<display-name>Servlet2</display-name>
<servlet-name>Servlet2</servlet-name>
<servlet-class>com.mycompany.Servlet2</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Servlet2</servlet-name>
<url-pattern>/Servlet2</url-pattern>
</servlet-mapping>

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