Rosa Rosa - 3 months ago 90
Java Question

Error with Rest Project running on JBoss 7.1

I created a REST project on JBoss 7.1.
I give you the required classes:

User.java

@XmlRootElement(name = "user")
public class User implements Serializable {
private static final long serialVersionUID = 1L;
private int id;
private String name;
private String profession;

public User(){}

public User(int id, String name, String profession){
this.id = id;
this.name = name;
this.profession = profession;
}

public int getId() {
return id;
}
@XmlElement
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
@XmlElement
public void setName(String name) {
this.name = name;
}
public String getProfession() {
return profession;
}
@XmlElement
public void setProfession(String profession) {
this.profession = profession;
}
}


ListBean.java

@ManagedBean
@ViewScoped
public class ListBean {
private static Client client;
private static String REST_SERVICE_URL = "http://localhost:8080/UserManagement/rest/UserService/users";
private static final String SUCCESS_RESULT="<result>success</result>";
private static final String PASS = "pass";
private static final String FAIL = "fail";
private List<User> users;
private transient DataModel<User> model;
private User user;
private int id;
private String name;
private String profession;

private void init(){
this.client = ClientBuilder.newClient();
}

@PostConstruct
public void initialize()
{
ListBean tester = new ListBean();
tester.init();
GenericType<List<User>> list = new GenericType<List<User>>() {};
users = client.target(REST_SERVICE_URL)
.request(MediaType.APPLICATION_XML)
.get(list);
String result = PASS;
if(users.isEmpty()){
result = FAIL;
}
List<User> lus = new ArrayList<User>();
for(User u : users){
lus.add(u);
}
user = new User();
}
}


UserService.java

@Path("/UserService")
public class UserService
{
UserDao userDao = new UserDao();
private static final String SUCCESS_RESULT="<result>success</result>";
private static final String FAILURE_RESULT="<result>failure</result>";

@GET
@Path("/users")
@Produces(MediaType.APPLICATION_XML)
public List<User> getUsers(){
return userDao.getAllUsers();
}
}


After running it, the exception bellow is displayed:

20:49:39,045 INFO [org.jboss.as.server] (Controller Boot Thread) JBAS018559: Deployed "sqljdbc4.jar"
20:49:39,050 INFO [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015876: Starting deployment of "UserManagement.war"
20:49:40,026 WARN [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015893: Encountered invalid class name 'com.sun.faces.vendor.Tomcat6InjectionProvider:org.apache.catalina.util.DefaultAnnotationProcessor' for service type 'com.sun.faces.spi.injectionprovider'
20:49:40,028 WARN [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015893: Encountered invalid class name 'com.sun.faces.vendor.Jetty6InjectionProvider:org.mortbay.jetty.plus.annotation.InjectionCollection' for service type 'com.sun.faces.spi.injectionprovider'
20:49:40,241 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-3) MSC00001: Failed to start service jboss.deployment.unit."UserManagement.war".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.unit."UserManagement.war".POST_MODULE: Failed to process phase POST_MODULE of deployment "UserManagement.war"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:119) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_55]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_55]
at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_55]
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS011232: Only one JAX-RS Application Class allowed. org.glassfish.jersey.server.ResourceConfig$WrappingResourceConfig org.glassfish.jersey.server.ResourceConfig$RuntimeConfig org.glassfish.jersey.server.ResourceConfig
at org.jboss.as.jaxrs.deployment.JaxrsScanningProcessor.scan(JaxrsScanningProcessor.java:209)
at org.jboss.as.jaxrs.deployment.JaxrsScanningProcessor.deploy(JaxrsScanningProcessor.java:105)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
... 5 more


This project works well with both Tomcat6 and 7, but JBoss 7.1 is having the issue.

Answer

So the relevant exception was this:

JBAS011232: Only one JAX-RS Application Class allowed

Thanks to the help of @eis and the thread Deploying a Jersey webapp on Jboss AS 7, this exception was solved.

Then, I encountered this issue:

java.lang.NoSuchMethodError: javax.ws.rs.core.MultivaluedMap.addAll(Ljava/lang/Object;[Ljava/lang/Object;)V

to solve it:

  • I made some classes implements Serializable.
  • I added the file jboss-deployment-structure.xml under META-INF:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
    <deployment>
        <exclusions>
            <!-- Exclude RestEasy conflict -->
            <module name="javaee.api" />
            <module name="javax.ws.rs.api"/>
            <module name="org.jboss.resteasy.resteasy-jaxrs" />
        </exclusions>
    </deployment>
</jboss-deployment-structure>

As result, my project works as well.

Comments