users@jersey.java.net

[Jersey] Re: Jersey resource is not found on Grizzly 2.2.1

From: Pavel Bucek <pavel.bucek_at_oracle.com>
Date: Tue, 31 Jan 2012 12:00:31 +0100

Hi again,

seems like you are trying to do something which is already done.

Please take a look at
https://maven.java.net/content/repositories/snapshots/com/sun/jersey/samples/helloworld/1.12-SNAPSHOT/helloworld-1.12-20120127.183401-19-project.zip

its a helloworld sample from 1.12-SNAPSHOT, which already uses Grizzly
2.2.1 (latest 2.x afaik).

Your problem might be related in some other modules from Jersey 1.11 and
your declared grizzly dependencies might clash with jersey ones.
Additionally, there ware some minor API changes in Grizzly..

please let me know whether that works for you.

Regards,
Pavel

On 1/30/12 1:57 PM, Philipp Tarasiewicz wrote:
> Hello Pavel!
>
> My HelloWorldResource class is the one from Jersey's "Getting Started"
> example
> (http://jersey.java.net/nonav/documentation/latest/getting-started.html):
>
>
> // The Java class will be hosted at the URI path "/helloworld"
> @Path("/helloworld")
> public class HelloWorldResource {
>
> // The Java method will process HTTP GET requests
> @GET
> // The Java method will produce content identified by the MIME Media
> // type "text/plain"
> @Produces("text/plain")
> public String getClichedMessage() {
> // Return some cliched textual content
> return "Hello World";
> }
> }
>
>
> And I start Grizzly with the code that can also be found in this
> "Getting Started" example:
>
>
> public class Main {
>
> private static int getPort(int defaultPort) {
> String port = System.getProperty("jersey.test.port");
> if (null != port) {
> try {
> return Integer.parseInt(port);
> } catch (NumberFormatException e) {
> }
> }
> return defaultPort;
> }
>
> private static URI getBaseURI() {
> return
> UriBuilder.fromUri("http://localhost/").port(getPort(9998)).build();
> }
>
> public static final URI BASE_URI = getBaseURI();
>
> protected static HttpServer startServer() throws IOException {
> System.out.println("Starting grizzly...");
> ResourceConfig rc = new
> PackagesResourceConfig("com.example.rest");
> return GrizzlyServerFactory.createHttpServer(BASE_URI, rc);
> }
>
> public static void main(String[] args) throws IOException {
> HttpServer httpServer = startServer();
> System.out.println(String.format("Jersey app started with WADL
> available at "
> + "%sapplication.wadl\nTry out %shelloworld\nHit enter
> to stop it...",
> BASE_URI, BASE_URI));
> System.in.read();
> httpServer.stop();
> }
> }
>
>
> As long as I use Grizzly 2.1.2 (specified as dependency in the getting
> started example), everything works fine, such that I can access the
> resource by pointing my browser to: http://localhost:9998/helloworld
>
> But, when I update the same example to Grizzly 2.2.1 (by just
> exchanging the corresponding JARs in the class path), I get the
> "Resource Not Found" page.
>
> The Jersey version I'm working with is v1.11. Yes, the "helloworld"
> example found on
> https://maven.java.net/content/repositories/snapshots/com/sun/jersey/samples/
> is exactly the same as the one you can see above.
>
> I'm aware of the fact that one can set the content-path in the
> web.xml. But does Grizzly support a web.xml configuration? By now I've
> only dealt with web.xml configs in conjunction with full-featured Java
> application servers like Glassfish.
>
> Is there are way to set the content path programmatically?
>
> Thank you very much for your help so far! :-)
>
> Philipp
>
> 2012/1/30 Pavel Bucek <pavel.bucek_at_oracle.com
> <mailto:pavel.bucek_at_oracle.com>>
>
> Hello Philipp,
>
> can you share class com.example.rest.HelloWorldResource
> (especially used @Path annotations)? Are you sure that you are
> trying to access correct url? It should look like:
> http://host:port/content-path/resource-path where
> "host:port/content-path" is set in grizzly/web.xml and the rest is
> handled in your application.
>
> also, which version of jersey are you using? you might want to
> take a look at helloworld or helloworld-webapp samples, see
> https://maven.java.net/content/repositories/snapshots/com/sun/jersey/samples/
>
> Regards,
> Pavel
>
>
>
> On 1/29/12 9:17 PM, justphilmusic_at_googlemail.com
> <mailto:justphilmusic_at_googlemail.com> wrote:
>
> Hello everybody!
>
> I've already used older versions of Jersey (e.g. v1.8) in
> conjunction
> with Grizzly (e.g. v1.9) with great success.
>
> Now, I'm about to start a new project which makes extensive
> use of some
> WebSocket improvements that have been introduced in the 2.2.1
> release
> of Grizzly. Furthermore, I want to use Jersey with the mentioned
> Grizzly release.
>
> However, I cannot make Grizzly to find my Jersey resources.
>
> In order to exclude possible errors in my code, I've started
> to test
> the Jersey example from the "Getting Started" chapter with the new
> Grizzly 2.2.1 release. After running the server the log output
> looks
> good (see below). However, when I point my browser to
> http://localhost:9998/helloworld I get Grizzly's "Resource Not
> Found"
> page instead of the output of the Jersey resource.
>
> Are there any hints on using Jersey with Grizzly's v2.2.1 release?
>
> I appreciate all tips regarding this topic!
>
> Bye,
> Philipp
>
>
> Starting grizzly...
> 29.01.2012 20:42:36
> com.sun.jersey.api.core.PackagesResourceConfig init
> INFO: Scanning for root resource and provider classes in the
> packages:
> com.example.rest
> 29.01.2012 20:42:36 com.sun.jersey.api.core.ScanningResourceConfig
> logClasses
> INFO: Root resource classes found:
> class com.example.rest.HelloWorldResource
> 29.01.2012 20:42:36
> com.sun.jersey.api.core.ScanningResourceConfig init
> INFO: No provider classes found.
> 29.01.2012 20:42:36
> com.sun.jersey.server.impl.application.WebApplicationImpl
> _initiate
> INFO: Initiating Jersey application, version 'Jersey: 1.11
> 12/09/2011
> 10:27 AM'
> 29.01.2012 20:42:37
> org.glassfish.grizzly.http.server.NetworkListener
> start
> INFO: Started listener bound to [localhost:9998]
> 29.01.2012 20:42:37
> org.glassfish.grizzly.http.server.HttpServer start
> INFO: [HttpServer] Started.
> Jersey app started with WADL available at
> http://localhost:9998/application.wadl
> Try out http://localhost:9998/helloworld
> Hit enter to stop it...
>
>
>