Maks.Burkov
Maks.Burkov

Reputation: 626

jersey.server.model.ModelValidationException

Hello I have some problem with this code! I got this error: Please Help!

org.glassfish.jersey.server.model.ModelValidationException: Validation of the application resource model has failed during application initialization. [[FATAL] A resource model has ambiguous (sub-)resource method for HTTP method GET and input mime-types as defined by"@Consumes" and "@Produces" annotations at Java methods public java.lang.String jersey.JerseyTesting.getName() and public java.lang.String jersey.JerseyTesting.getPassword() at matching regular expression /jerseytesting. These two methods produces and consumes exactly the same mime-types and therefore their invocation as a resource methods will always fail.; source='org.glassfish.jersey.server.model.RuntimeResource@4d73a7a'] org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:555) org.glassfish.jersey.server.ApplicationHandler.access$500(ApplicationHandler.java:184) org.glassfish.jersey.server.ApplicationHandler$3.call(ApplicationHandler.java:350) org.glassfish.jersey.server.ApplicationHandler$3.call(ApplicationHandler.java:347) org.glassfish.jersey.internal.Errors.process(Errors.java:315) org.glassfish.jersey.internal.Errors.process(Errors.java:297) org.glassfish.jersey.internal.Errors.processWithException(Errors.java:255) org.glassfish.jersey.server.ApplicationHandler.(ApplicationHandler.java:347) org.glassfish.jersey.servlet.WebComponent.(WebComponent.java:392) org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:177) org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:369) javax.servlet.GenericServlet.init(GenericServlet.java:158) org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672) org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500) org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456) java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) java.lang.Thread.run(Unknown Source)

Mine Class:
@Path("/JerseyTesting")
public class JerseyTesting {
String name = "Maks";
String password = "pl000pl";
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getName() {
    return name;
}
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getPassword() {
    return password;
}
}


Mine web.xml page!
<display-name>JerseyTesting</display-name>  
    <servlet>   
    <servlet-name>JerseyTesting</servlet-name> 
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> 
    <init-param>
    <param-name>jersey.config.server.provider.packages</param-name>
    <param-value>jersey</param-value>
    </init-param>
    </servlet>
    <servlet-mapping>
    <servlet-name>JerseyTesting</servlet-name>
    <url-pattern>/RestTesting</url-pattern> 
    </servlet-mapping>

Upvotes: 4

Views: 19611

Answers (1)

Paul Samsotha
Paul Samsotha

Reputation: 209052

[[FATAL] A resource model has ambiguous (sub-)resource method for HTTP method GET and input mime-types as defined by"@Consumes" and "@Produces" annotations at Java methods public java.lang.String jersey.JerseyTesting.getName() and public java.lang.String jersey.JerseyTesting.getPassword() at matching regular expression /jerseytesting. These two methods produces and consumes exactly the same mime-types and therefore their invocation as a resource methods will always fail.;

Your resource methods are ambiguous

@GET
@Produces(MediaType.TEXT_PLAIN)
public String getName() {
    return name;
}
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getPassword() {
    return password;
}

Jersey will not know which one to pick. You will need to either change the path on one or both of them or the media type. Most likely you will want to change the path for this particular case. Something like

@GET
@Path("/name")
@Produces(MediaType.TEXT_PLAIN)
public String getName() {
    return name;
}
@GET
@Path("/password")
@Produces(MediaType.TEXT_PLAIN)
public String getPassword() {
    return password;
}

Upvotes: 11

Related Questions