users@jersey.java.net

Re: [Jersey] Testing GET resources in a browser

From: Imran M Yousuf <imran_at_smartitengineering.com>
Date: Wed, 27 Aug 2008 09:20:50 +0600

On Wed, Aug 27, 2008 at 2:30 AM, richmondJava <jerryhill_at_yahoo.com> wrote:
>
> I am trying to stand up Jersey in a Weblogic Portal project and have deployed
> a simple service with a GET method:
>
> <servlet>
> <servlet-name>Jersey REST Servlet</servlet-name>
> <servlet-class>
> com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
> <init-param>
>
> <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
>
> <param-value>com.sun.jersey.api.core.PackagesResourceConfig</param-value>
> </init-param>
> <init-param>
> <param-name>com.sun.jersey.config.property.packages</param-name>
> <param-value>com.capitalone.ccl.service.rest.impl</param-value>
> </init-param>
> <load-on-startup>1</load-on-startup>
> </servlet>
> <servlet-mapping>
> <servlet-name> Jersey REST Servlet </servlet-name>
> <url-pattern>/rest/*</url-pattern>
> </servlet-mapping>
>
> The service:
>
> @Path("/helloworld")
> public class ConfirmOffersRestService extends AbstractRestService
> implements Service<ConfirmOffersRestRequest, ConfirmOffersRestResponse>{
>
> @GET
> @Produces("text/html")
> public String hello(){
> return "Hello world";
> }
>
>
>
>
> All I am trying to do is hit the service from a browser to see the response.
> I want to test it before writing a bunch of client code. I go into the
> browser and use the ".../rest/helloworld" address.
>

The log should say that it found the resource, can you please check
the log where you should see something like -

INFO: Scanning for root resource and provider classes in the packages:
  com.smartitengineering.demo.smartselection.rest.resource.provider.impl
Aug 27, 2008 9:10:53 AM com.sun.jersey.api.core.PackagesResourceConfig init
INFO: Root resource classes found:
  class com.smartitengineering.demo.smartselection.rest.resource.provider.impl.BookServiceAdapter

If you are using maven you can try to use the Jetty plugin to test
your webapp as well.

http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin

I also added a sample configuration as follows.

        <plugins>
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>maven-jetty-plugin</artifactId>
                <version>6.1.9</version>
                <configuration>
                    <stopPort>9966</stopPort>
                    <stopKey>smart-selection</stopKey>
                    <contextPath>/smart-selection-rest</contextPath>
                    <scanIntervalSeconds>10</scanIntervalSeconds>
                    <systemProperties>
                        <systemProperty>
                            <name>jetty.port</name>
                            <value>7070</value>
                        </systemProperty>
                    </systemProperties>
                </configuration>
            </plugin>
            .....
        </plugins>

> All I get is "Invalid command: [/helloworld] -- Check syntax"
>
>
> What am I missing? Is the browser not generating a GET request to the
> resource?
>
> Thanks for any help...
> jerry..
> --
> View this message in context: http://n2.nabble.com/Testing-GET-resources-in-a-browser-tp785201p785201.html
> Sent from the Jersey mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>


-- 
Imran M Yousuf
Email: imran_at_smartitengineering.com
Blog: http://imyousuf-tech.blogs.smartitengineering.com/
Mobile: +880-1711402557