Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jersey Proxy Client gives NoSuchMethodException: Could not find a suitable constructor PAYARA-3934 #3944

Closed
latyaodessa opened this issue May 13, 2019 · 5 comments
Labels
Type: Bug Label issue as a bug defect

Comments

@latyaodessa
Copy link

Description


Using normal jersey rest API implementation everything working as it should be.
In fact with Payara 5.184 implementing interface everything also worked. (jersey 2.27-p13)
After upgrading to Payara 5.191 (jersey 2.27-p15) interface implementation start to throw an exception.

Expected Outcome

Application should give response from the rest call.
Exactly like it described in jersey-proxy-client 2.27 JavaDocs

Current Outcome

StandardWrapperValve[javax.ws.rs.core.Application]: Servlet.service() for servlet javax.ws.rs.core.Application threw exception
java.lang.NoSuchMethodException: Could not find a suitable constructor in com.company.application.webservice.Endpoint class.
	at org.glassfish.jersey.inject.hk2.JerseyClassAnalyzer.getConstructor(JerseyClassAnalyzer.java:192)
	at org.jvnet.hk2.internal.Utilities.getConstructor(Utilities.java:180)
	at org.jvnet.hk2.internal.Utilities.justCreate(Utilities.java:1066)
	at org.jvnet.hk2.internal.ServiceLocatorImpl.create(ServiceLocatorImpl.java:978)
	at org.jvnet.hk2.internal.ServiceLocatorImpl.createAndInitialize(ServiceLocatorImpl.java:1082)
	at org.jvnet.hk2.internal.ServiceLocatorImpl.createAndInitialize(ServiceLocatorImpl.java:1074)
	at org.glassfish.jersey.inject.hk2.AbstractHk2InjectionManager.createAndInitialize(AbstractHk2InjectionManager.java:213)
	at org.glassfish.jersey.inject.hk2.ImmediateHk2InjectionManager.createAndInitialize(ImmediateHk2InjectionManager.java:54)
	at org.glassfish.jersey.internal.inject.Injections.getOrCreate(Injections.java:130)
	at org.glassfish.jersey.server.model.MethodHandler$ClassBasedMethodHandler.getInstance(MethodHandler.java:286)
	at org.glassfish.jersey.server.internal.routing.PushMethodHandlerRouter.apply(PushMethodHandlerRouter.java:75)
	at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:110)
	at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:113)
	at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:113)
	at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:113)
	at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:113)
	at org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:93)
	at org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:62)
	at org.glassfish.jersey.process.internal.Stages.process(Stages.java:197)
	at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:269)
	at org.glassfish.jersey.internal.Errors$1.call(Errors.java:272)
	at org.glassfish.jersey.internal.Errors$1.call(Errors.java:268)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:316)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:298)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:268)
	at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:289)
	at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:256)
	at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:704)
	at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:416)
	at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:370)
	at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:389)
	at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:342)
	at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:229)
	at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1628)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:258)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
	at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:755)
	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:575)
	at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:159)
	at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:371)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:238)
	at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:520)
	at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:217)
	at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:182)
	at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:156)
	at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:218)
	at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:95)
	at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:260)
	at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:177)
	at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:109)
	at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:88)
	at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:53)
	at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:524)
	at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:89)
	at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:94)
	at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$0(WorkerThreadIOStrategy.java:90)
	at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:114)
	at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:569)
	at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:549)
	at java.lang.Thread.run(Thread.java:748)

Steps to reproduce (Only for bug reports)

Interface

@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("booking")
public interface Endpoint {

    @GET
    @Path("get/{id}")
    Response<DTO> getById(@PathParam("id") final Long id);


    @POST
    @Path("submit")
     RR<String> submit(final DTOdto);

}

Implementation

public class RestImpl implements Endpoint {

    @Override
    public Response<DTO>> getById( final Long id) {
        ....
    }

    @Override
    @Path("submit")
    public Response<String> submit(final DTO dto) {
        ....
    }

Environment

  • Payara Version: 5.191
  • JDK Version: java version "1.8.0_152"
    Java(TM) SE Runtime Environment (build 1.8.0_152-b16)
    Java HotSpot(TM) 64-Bit Server VM (build 25.152-b16, mixed mode)
    javac 1.8.0_152
  • Operating System: Centos 7
  • Database: PostGres 10
tgramblicka pushed a commit to tgramblicka/trnka-backend that referenced this issue May 13, 2019
…does not support annotations on Interfaces yet (payara/Payara#3944)

will be removed after fixed
@khasunuma
Copy link

I reproduced this issue not only 5.191 (and 5.192) but also 5.184. My environment is as follows:

  • JDK Version: Oracle JDK 1.8.0_202 (build 1.8.0_202-b08)
  • Operating System: Windows 10
  • Database: N/A

@OndroMih
Copy link
Contributor

I've reproduced it too with the following reproducer: reproducer-gh3944.zip

The reason is that Payara Server treats the EndPoint interface as a resource class and it can't find a constructor. Payara Server shouldn't validate interfaces.

A workaround is to remove EndPoint.class and all interface classes from JAX-RS application explicitly, e.g. by defining all resource classes in the output of the javax.ws.rs.core.Application.getClasses() method:

@ApplicationPath("rest")
public class ApplicationConfig extends Application {
    @Override
    public Set<Class<?>> getClasses() {
        return Collections.singleton(RestImpl.class);
    }
}

@OndroMih OndroMih changed the title Jersey Proxy Client gives NoSuchMethodException: Could not find a suitable constructor Jersey Proxy Client gives NoSuchMethodException: Could not find a suitable constructor PAYARA-3934 Jun 15, 2019
@OndroMih OndroMih added Status: Accepted Confirmed defect or accepted improvement to implement, issue has been escalated to Platform Dev Type: Bug Label issue as a bug defect and removed c:PossibleBug labels Jun 15, 2019
@smillidge
Copy link
Contributor

I am not convinced this is a bug. Section 3.6 of the JAX-RS spec states that inheritance of annotations at the class level on an interface is not supported.

@rdebusscher
Copy link

When running on Payara 5.194, following message is in the log (without stacktrace)

Component of class interface payara.rest.EndPoint cannot be instantiated and will be ignored.

When putting the JAX-RS annotations on the class itself instead of the interface, the JAX-RS annotations on the interface method are ignored. To fix that scenario, I have created CUSTCOM-113.

I close this issue since the stacktrace itself is solved and proper message is shown in the log.

@shub8968 shub8968 removed the Status: Accepted Confirmed defect or accepted improvement to implement, issue has been escalated to Platform Dev label Jan 10, 2022
@hlulani-eoh
Copy link

I am not convinced this is a bug. Section 3.6 of the JAX-RS spec states that inheritance of annotations at the class level on an interface is not supported.

Hello @smillidge, the Spec also states that:
"For consistency with other Jakarta EE specifications, it is recommended to always repeat annotations instead of relying on annotation inheritance."
https://jakarta.ee/specifications/restful-ws/3.0/jakarta-restful-ws-spec-3.0.html#annotationinheritance

But when I repeat the @Path annotation in my concrete class I get a double definition on Payara

[2022-01-10T21:34:47.932+0200] [] [SEVERE] [] [org.glassfish.jersey.internal.Errors] [tid: _ThreadID=1 _ThreadName=main] [timeMillis: 1641843287932] [levelValue: 1000] [[
  Following issues have been detected: 
WARNING: A resource model has ambiguous (sub-)resource method for HTTP method POST and input mime-types as defined by"@Consumes" and "@Produces" annotations at Java methods public abstract javax.ws.rs.core.Response com.mtn.madapi.contract.notification.api.NotificationSettingsApi.createNotificationSetting(com.mtn.madapi.contract.notification.model.NotificationSetting) and public javax.ws.rs.core.Response com.mtn.madapi.notification.resource.NotificationSettingsResource.createNotificationSetting(com.mtn.madapi.contract.notification.model.NotificationSetting) at matching regular expression /notification\-settings. These two methods produces and consumes exactly the same mime-types and therefore their invocation as a resource methods will always fail.
WARNING: 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 abstract javax.ws.rs.core.Response com.mtn.madapi.contract.notification.api.NotificationSettingsApi.listNotificationSettings(java.lang.Integer) and public javax.ws.rs.core.Response com.mtn.madapi.notification.resource.NotificationSettingsResource.listNotificationSettings(java.lang.Integer) at matching regular expression /notification\-settings. These two methods produces and consumes exactly the same mime-types and therefore their invocation as a resource methods will always fail.
WARNING: A resource model has ambiguous (sub-)resource method for HTTP method DELETE and input mime-types as defined by"@Consumes" and "@Produces" annotations at Java methods public abstract javax.ws.rs.core.Response com.mtn.madapi.contract.notification.api.NotificationSettingsApi.removeSettings(java.lang.String) and public javax.ws.rs.core.Response com.mtn.madapi.notification.resource.NotificationSettingsResource.removeSettings(java.lang.String) at matching regular expression /([^/]+). These two methods produces and consumes exactly the same mime-types and therefore their invocation as a resource methods will always fail.
WARNING: 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 abstract javax.ws.rs.core.Response com.mtn.madapi.contract.notification.api.NotificationSettingsApi.retreiveNotificationById(java.lang.String) and public javax.ws.rs.core.Response com.mtn.madapi.notification.resource.NotificationSettingsResource.retreiveNotificationById(java.lang.String) at matching regular expression /([^/]+). These two methods produces and consumes exactly the same mime-types and therefore their invocation as a resource methods will always fail.
WARNING: A resource model has ambiguous (sub-)resource method for HTTP method PUT and input mime-types as defined by"@Consumes" and "@Produces" annotations at Java methods public abstract javax.ws.rs.core.Response com.mtn.madapi.contract.notification.api.NotificationSettingsApi.updateNotification(java.lang.String,com.mtn.madapi.contract.notification.model.NotificationSetting) and public javax.ws.rs.core.Response com.mtn.madapi.notification.resource.NotificationSettingsResource.updateNotification(java.lang.String,com.mtn.madapi.contract.notification.model.NotificationSetting) at matching regular expression /([^/]+). These two methods produces and consumes exactly the same mime-types and therefore their invocation as a resource methods will always fail.
]]

In my case interfaces are generated so I have no way of modifying them

#5553

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Label issue as a bug defect
Projects
None yet
Development

No branches or pull requests

7 participants