2012-04-10 10 views
9

Wszelkie linki dotyczące integracji Jetty i RESTEasy? Trochę utknąłem próbując skonfigurować RESTEasy razem z Jetty .... i wydaje się, że nie ma żadnej wiarygodnej pomocy w sieci.Integrowanie pomostu z RESTEasy

public static void main(String[] args) throws Exception 
{ 
     Server server = new Server(8080); 

     WebAppContext context = new WebAppContext(); 
     context.setDescriptor("../WEB-INF/web.xml"); 
     context.setResourceBase("../src/webapp"); 
     context.setContextPath("/"); 
     context.setParentLoaderPriority(true); 

     server.setHandler(context); 

     server.start(); 
     server.join(); 
} 

Moja web.xml są kopiowane bezpośrednio z: http://docs.jboss.org/resteasy/docs/1.0.0.GA/userguide/html/Installation_Configuration.html

Błąd wrócę to HTTP 404, gdy próbuję otworzyć link w moim pliku zasobów. Wszystko wygląda rozsądnie na powierzchni, jakieś sugestie?

Mój plik zasobów wygląda następująco:

package webapp; 
import javax.ws.rs.GET; 
import javax.ws.rs.Path; 
import javax.ws.rs.PathParam; 

@Path("/*") 
public class Resource { 

    @GET 
    public String hello() { 
     return "hello"; 
    } 


    @GET 
    @Path("/books") 
    public String getBooks() { 
     return "books"; 
    } 

    @GET 
    @Path("/book/{isbn}") 
    public String getBook(@PathParam("isbn") String id) { 
     return "11123"; 
    } 
} 

to wydruki, które widzę, kiedy zaczyna się Jetty:

2012-04-10 09: 54: 27,163: INFO: oejs.Server: jetty-8.1.1.v20120215 2012-04-10 09: 54: 27.288: INFO: oejw.StandardDescriptorProcessor: NO JSP Wsparcie dla /, nie znaleziono org.apache.jasper.servlet.JspServlet 2012-04-10 09:54 : 27.319: INFO: oejsh.ContextHandler: started oejwWebAppContext {/, file:/C:/Users/xyz/Anotherproj1/src/webapp} 2012-04-10 09: 54: 27.319: INFO: oejsh.ContextHandler: started oejw WebAppContext {/, file:/C:/Users/xyz/Anotherproj1/src/webapp} 2012-04-10 09:54: 27.381: INFO: oejs.AbstractConnector: Uruchomiono [email protected]: 8080

+0

Na pierwszy glace to wygląda poprawnie. Którą wersję Jetty używasz. Czy są jakieś komunikaty o błędach? Jaki jest dokładnie twój problem? – andih

+0

@andih Błąd jest zasadniczo HTTP 404, gdy próbuję otworzyć łącze w moim pliku zasobów. – rmoh21

+0

@andih Używam Jetty 8.1.1 – rmoh21

Odpowiedz

6

follwing roboty dla mnie:

web.xml:

<web-app xmlns:javaee="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> 
    <context-param> 
     <param-name>resteasy.scan</param-name> 
     <param-value>true</param-value>  
    </context-param> 

    <context-param> 
    <param-name>resteasy.resources</param-name> 
    <param-value>webapp.Resource</param-value> 
    </context-param> 
    <context-param> 
     <param-name>javax.ws.rs.core.Application</param-name> 
     <param-value>webapp.MyApplicationConfig</param-value> 
    </context-param> 

    <!-- set this if you map the Resteasy servlet to something other than /* 
    <context-param> 
     <param-name>resteasy.servlet.mapping.prefix</param-name> 
     <param-value>/resteasy</param-value> 
    </context-param> 
    --> 
    <!-- if you are using Spring, Seam or EJB as your component model, remove the ResourceMethodSecurityInterceptor --> 
    <context-param> 
     <param-name>resteasy.resource.method-interceptors</param-name> 
     <param-value> 
     org.jboss.resteasy.core.ResourceMethodSecurityInterceptor 
     </param-value> 
    </context-param> 


    <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> 
    <load-on-startup>1</load-on-startup> 
    </servlet> 

    <servlet-mapping> 
    <servlet-name>Resteasy</servlet-name> 
    <url-pattern>/*</url-pattern> 
    </servlet-mapping> 
</web-app> 

Z

public class MyApplicationConfig extends Application { 

    private static final Set<Class<?>> CLASSES; 

    static { 
     HashSet<Class<?>> tmp = new HashSet<Class<?>>(); 
     tmp.add(Resource.class); 

     CLASSES = Collections.unmodifiableSet(tmp); 
    } 

    @Override 
    public Set<Class<?>> getClasses(){ 

     return CLASSES; 
    }  


} 

Zasobu

package webapp; 
import javax.ws.rs.GET; 
import javax.ws.rs.Path; 
import javax.ws.rs.PathParam; 
import javax.ws.rs.Produces; 

@Path("/") 
@Produces("text/plain") 
public class Resource { 

    @GET 
    public String hello() { 
     return "hello"; 
    } 


    @GET 
    @Path("/books") 
    public String getBooks() { 
     return "books"; 
    } 

    @GET 
    @Path("/book/{isbn}") 
    public String getBook(@PathParam("isbn") String id) { 
     return "11123"; 
    } 
} 

i klasy Głównego

import org.eclipse.jetty.server.Server; 
import org.eclipse.jetty.webapp.WebAppContext; 
import org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap; 

public class Main { 
    public static void main(String[] args) throws Exception 
    { 
      Server server = new Server(8080); 

      WebAppContext context = new WebAppContext(); 

      context.setDescriptor("./src/main/webapp/WEB-INF/web.xml"); 
      context.setResourceBase("./src/main/webapp"); 
      context.setContextPath("/"); 

      context.setParentLoaderPriority(true);    

      server.setHandler(context); 

      server.start(); 
      server.join(); 
    } 

} 
+1

Wielkie dzięki to zadziałało! Jedną rzeczą jest literówka w twojej sieci.plik xml - powinien to być "ResteasyBootstrap" na miejscu "ResteasyBootstap" - brakuje "r". – rmoh21

0

Czy jesteś pewien, że @ ścieżka ("/ *") jest poprawną ścieżką. Spróbuj @Path ("/") może to * jest problemem. O ile mi wiadomo, wyrażenia ścieżki nie akceptują wyrażeń regularnych.

EDIT

myliłem, można użyć wyrażeń regularnych w @Path przynajmniej RESTEasy supports that.

+0

Próbowałem, że to nie przynosi żadnego pożytku. Dostaję 404 nie znalezione w mojej przeglądarce, kiedy wpisuję localhost: 8080/ – rmoh21

Powiązane problemy