NetBeans saved my day. I wanted to test Jersey (with Eclipse Indigo) and GF 3.1.2 simply didn't see them when deployed my webapp, the browser didn't see any response from sever for my "/alfa" URL.
I had a resource class:
package com.test.jersey;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
@Path("alfa")
public class MyResource {
public MyResource() {
}
@Produces("text/plain")
@GET
public String sayHello() {
return "hello again";
}
}
So tried the example in the java6 tutorial (helloworldapplication) with Netbeans 7.1, right-cliked and chosen "Test RESTFfull Webservices " (as the tutorial says) and in NetBeans it worked perfectly this way (it launches a super web interface for testing all the class's resource methods...impressing) and also when deployed and testing it from a browser.So, what was the difference between my webapp ant this one?
And i saw that netbeans generated a class
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.netbeans.rest.application.config;
/**
* This class is generated by the Netbeans IDE,
* and registers all REST root resources created in the project.
* Please, DO NOT EDIT this class !
*/
@javax.ws.rs.ApplicationPath("resources")
public class ApplicationConfig extends javax.ws.rs.core.Application {
}
...and i copied it in my source files in Eclipse and there you go, it worked after a redeploy....So When using JAX-RS, include this @ApplicationPath annotated class
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.test.jersey;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
/**
* This class is generated by the Netbeans IDE, and registers all REST root
* resources created in the project. Please, DO NOT EDIT this class !
*/
@ApplicationPath("")
public class ApplicationConfig extends Application {
}
I replaced "resources" by "", to be able to use URLs like /alfa and not /resources/alfa, to hit my class.
No comments:
Post a Comment