JBoss AS 7 Restful Webservices does not automatically deploy

I am trying to use the built-in Restful WebServices with JBoss AS 7. My web.xml is ..

<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> </web-app> 

My application class ...

 package com.robert; import javax.ws.rs.ApplicationPath; import javax.ws.rs.core.Application; import java.util.HashSet; import java.util.Set; @ApplicationPath("/services") public class HelloWorld extends Application { private Set<Object> singletons = new HashSet<Object>(); public HelloWorld() { singletons.add(new Library()); } @Override public Set<Class<?>> getClasses() { Set<Class<?>> classes = new HashSet<Class<?>>(); classes.add(Library.class); return classes; //To change body of overridden methods use File | Settings | File Templates. } @Override public Set<Object> getSingletons() { return singletons; } 

}

and my class

 import javax.ws.rs.*; @Path("/library") public class Library { @GET @Path("/books") public String getBooks() { return "this is all your books"; } @GET @Path("/book/{isbn}") public String getBook(@PathParam("isbn") String id) { // search my database and get a string representation and return it return "Its a good book; I read it"; } @PUT @Path("/book/{isbn}") public void addBook(@PathParam("isbn") String id, @QueryParam("name") String name) { System.out.println("Adding book "+name); } @DELETE @Path("/book/{id}") public void removeBook(@PathParam("id") String id ){ System.out.println("Removing book "+id); } 

}

However, when I start JBoss AS7, the WebService never starts. I do not see it on the JBoss control page, and I do not see it in

 http://foobar:8080/MyWar/services/library/books 
+2
source share
3 answers

Ok, I found a problem. Following the instructions of RestEasy, I installed the latest version of RestEasy in the JBoss module. When I get back to the default installation, it works. Note that web.xml SHOULD NOT contain references to Restful servlets, as the JBoss deployer automatically deploys RestEasy when it sees the @ApplicationPath annotation for the class. Web.xml must be empty.

+3
source

You need to add a REST servlet mapping

in web.xml you need to add a servlet mapping to a REST Servlet, something like this

 <servlet-mapping> <servlet-name>javax.ws.rs.core.Application</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> 

where the URL pattern should correspond to what should be processed as RESTFUL (or use / * - this will cause your Servlet Rest to process all requests to this application)

I don’t know why, but I have never had any of my Restful web services in the web services section of the JBoss management console, but I see that my SOAP-based WSDL network is on this list.

However, I see Restful projects in the Deployment Management section of the management console

+1
source

To fix your application:

You can also use helloworld-rs quickstart accompanying jbossas-7 as a starting point for JavaEE 6 RESTful webapp.

0
source

Source: https://habr.com/ru/post/1445959/


All Articles