2012-04-10 20 views
9

के साथ जेटी को एकीकृत करना जेटी और रीस्टेसी को एकीकृत करने के तरीके पर कोई भी लिंक? मैं जेटी के साथ एक साथ कॉन्स्टेसी कॉन्फ़िगर करने की कोशिश कर रहा हूं .... और वेब पर कोई विश्वसनीय मदद नहीं है।रीस्टेसी

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(); 
} 

मेरे web.xml सीधे से नकल है: http://docs.jboss.org/resteasy/docs/1.0.0.GA/userguide/html/Installation_Configuration.html

त्रुटि मैं वापस पाने के लिए एक HTTP 404 जब मैं अपने संसाधन फ़ाइल में एक लिंक को खोलने के लिए प्रयास करें। सब कुछ सतह पर उचित दिखता है, कोई सुझाव?

मेरे संसाधन फ़ाइल की तरह दिखता है:

2012-04-10 09: 54: 27.163: जानकारी:

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"; 
    } 
} 

यह प्रिंट कि मैं देख रहा हूँ जब जेट्टी शुरू होता है oejs.Server: जेटी-8.1.1.v20120215 2012-04-10 09: 54: 27.288: जानकारी: oejw.StandardDescriptorProcessor: के लिए कोई जेएसपी समर्थन नहीं मिला, org.apache.jasper.servlet.JspServlet 2012-04-10 09:54 नहीं मिला : 27.319: जानकारी: oejsh.ContextHandler: oejwWebAppContext शुरू किया {/, फ़ाइल:/सी:/उपयोगकर्ता/xyz/anotherproj1/src/webapp} 2012-04-10 09: 54: 27.319: जानकारी: oejsh.ContextHandler: oejw शुरू किया WebAppContext {/, फ़ाइल:/सी:/उपयोगकर्ता/xyz/anotherproj1/src/webapp} 2012-04-10 09:54: 27.381: जानकारी: oejs.Abstract कनेक्टर: प्रारंभ करें[email protected]: 8080

+0

पहले इकरंगा पर यह सही लग रहा है। आप किस जेटी संस्करण का उपयोग कर रहे हैं। क्या कोई त्रुटि संदेश है? वास्तव में आपकी समस्या क्या है? – andih

+0

@andih जब मैं अपनी संसाधन फ़ाइल में एक लिंक खोलने का प्रयास करता हूं तो त्रुटि अनिवार्य रूप से एक HTTP 404 है। – rmoh21

+0

@andih मैं जेटी 8.1.1 – rmoh21

उत्तर

6

मेरे लिए follwing काम करता है:

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> 

साथ

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; 
    }  


} 

संसाधन

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"; 
    } 
} 

और मुख्य वर्ग

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

धन्यवाद बहुत अच्छा काम करता है! बस एक चीज आपके वेब में एक टाइपो है।xml फ़ाइल - "ResteasyBootStap" को "ResteasyBootStap" से हटाकर "ResteasyBootstrap" होना चाहिए - 'r' गुम है। – rmoh21

0

क्या आप सुनिश्चित हैं कि @Path ("/ *") सही पथ है। @Path ("/") आज़माएं शायद यह एक समस्या है। जहां तक ​​मुझे पता है कि पथ अभिव्यक्ति regexps स्वीकार नहीं करती है।

संपादित

मैं गलत था, तो आप, @Path में regexps उपयोग कर सकते हैं कम से कम RESTEasy supports that

+0

कोशिश की कि यह कोई अच्छा नहीं करता है। जब मैं लोकलहोस्ट में प्रवेश करता हूं तो मुझे अपने ब्राउज़र में 404 नहीं मिलता है: 8080/ – rmoh21

0

प्राप्त करने के लिए RESTEasy और जेट्टी के बिना एक साथ काम करने के लिए एक web.xml सुनिश्चित करें कि आपके pom.xml में resteasy-सर्वलेट-प्रारंभकर्ता पर निर्भरता है।

यह मदद मिल सकती है (JBoss RESTEasy प्रलेखन): https://docs.jboss.org/resteasy/docs/3.0.4.Final/userguide/html/Installation_Configuration.html#d4e111