简体   繁体   中英

Registering Spring OAuth2 token endpoints in Dropwizard application

How can we register Spring OAuth2 token endpoints into the Dropwizard Application? I tried to register it explicitly but no luck. So, I debugged my code and found JerseyEnvironment.class needs @Path annotation over the class to register resources but here we don't have this annotation on TokenEndpoint.class (A Spring OAuth2 class where endpoints are defined). Is there any way to register it using Dropwizard framework?

I've tried making a resource class, with annotation @Path, that extends TokenEndpoint.class and overrides its postAccessToken method but I get the following exception on server startup,

SEVERE: Missing dependency for method public org.springframework.http.ResponseEntity com.auth.TokenEndpointResource.postAccessToken(java.security.Principal,java.util.Map) throws org.springframework.web.HttpRequestMethodNotSupportedException at parameter at index 1 [WARN ] 2017-07-17 16:03:56,695 main  unavailable 
javax.servlet.ServletException: com.sun.jersey.spi.container.servlet.ServletContainer-348d1a5e@4f311bd7==com.sun.jersey.spi.container.servlet.ServletContainer,1,false
at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:561) ~[jetty-servlet-9.0.7.v20131107.jar:9.0.7.v20131107]
at org.eclipse.jetty.servlet.ServletHolder.initialize(ServletHolder.java:349) ~[jetty-servlet-9.0.7.v20131107.jar:9.0.7.v20131107]
at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:812) ~[jetty-servlet-9.0.7.v20131107.jar:9.0.7.v20131107]
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:288) ~[jetty-servlet-9.0.7.v20131107.jar:9.0.7.v20131107]
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:732) ~[jetty-server-9.0.7.v20131107.jar:9.0.7.v20131107]
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69) [jetty-util-9.0.7.v20131107.jar:9.0.7.v20131107]
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:118) [jetty-util-9.0.7.v20131107.jar:9.0.7.v20131107]
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:100) [jetty-util-9.0.7.v20131107.jar:9.0.7.v20131107]
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:60) [jetty-server-9.0.7.v20131107.jar:9.0.7.v20131107]
at com.codahale.metrics.jetty9.InstrumentedHandler.doStart(InstrumentedHandler.java:89) [metrics-jetty9-3.0.1.jar:3.0.1]
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69) [jetty-util-9.0.7.v20131107.jar:9.0.7.v20131107]
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:118) [jetty-util-9.0.7.v20131107.jar:9.0.7.v20131107]
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:100) [jetty-util-9.0.7.v20131107.jar:9.0.7.v20131107]
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:60) [jetty-server-9.0.7.v20131107.jar:9.0.7.v20131107]
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69) [jetty-util-9.0.7.v20131107.jar:9.0.7.v20131107]
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:118) [jetty-util-9.0.7.v20131107.jar:9.0.7.v20131107]
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:100) [jetty-util-9.0.7.v20131107.jar:9.0.7.v20131107]
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:60) [jetty-server-9.0.7.v20131107.jar:9.0.7.v20131107]
at org.eclipse.jetty.server.handler.RequestLogHandler.doStart(RequestLogHandler.java:131) [jetty-server-9.0.7.v20131107.jar:9.0.7.v20131107]
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69) [jetty-util-9.0.7.v20131107.jar:9.0.7.v20131107]
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:118) [jetty-util-9.0.7.v20131107.jar:9.0.7.v20131107]
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:100) [jetty-util-9.0.7.v20131107.jar:9.0.7.v20131107]
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:60) [jetty-server-9.0.7.v20131107.jar:9.0.7.v20131107]
at org.eclipse.jetty.server.handler.StatisticsHandler.doStart(StatisticsHandler.java:233) [jetty-server-9.0.7.v20131107.jar:9.0.7.v20131107]
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69) [jetty-util-9.0.7.v20131107.jar:9.0.7.v20131107]
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:118) [jetty-util-9.0.7.v20131107.jar:9.0.7.v20131107]
at org.eclipse.jetty.server.Server.start(Server.java:342) [jetty-server-9.0.7.v20131107.jar:9.0.7.v20131107]
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:100) [jetty-util-9.0.7.v20131107.jar:9.0.7.v20131107]
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:60) [jetty-server-9.0.7.v20131107.jar:9.0.7.v20131107]
at org.eclipse.jetty.server.Server.doStart(Server.java:290) [jetty-server-9.0.7.v20131107.jar:9.0.7.v20131107]
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69) [jetty-util-9.0.7.v20131107.jar:9.0.7.v20131107]
at io.dropwizard.cli.ServerCommand.run(ServerCommand.java:43) [dropwizard-core-0.7.0.jar:0.7.0]
at io.dropwizard.cli.EnvironmentCommand.run(EnvironmentCommand.java:43) [dropwizard-core-0.7.0.jar:0.7.0]
at io.dropwizard.cli.ConfiguredCommand.run(ConfiguredCommand.java:76) [dropwizard-core-0.7.0.jar:0.7.0]
at io.dropwizard.cli.Cli.run(Cli.java:70) [dropwizard-core-0.7.0.jar:0.7.0]
at io.dropwizard.Application.run(Application.java:72) [dropwizard-core-0.7.0.jar:0.7.0]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_91]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_91]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_91]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_91]
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144) [idea_rt.jar:na]


Caused by: com.sun.jersey.spi.inject.Errors$ErrorMessagesException: null
at com.sun.jersey.spi.inject.Errors.processErrorMessages(Errors.java:170) ~[jersey-core-1.18.1.jar:1.18.1]
at com.sun.jersey.spi.inject.Errors.postProcess(Errors.java:136) ~[jersey-core-1.18.1.jar:1.18.1]
at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:199) ~[jersey-core-1.18.1.jar:1.18.1]
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:795) ~[jersey-server-1.18.1.jar:1.18.1]
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:790) ~[jersey-server-1.18.1.jar:1.18.1]
at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:491) ~[jersey-servlet-1.18.1.jar:1.18.1]
at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:321) ~[jersey-servlet-1.18.1.jar:1.18.1]
at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:605) ~[jersey-servlet-1.18.1.jar:1.18.1]
at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:207) ~[jersey-servlet-1.18.1.jar:1.18.1]
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:376) ~[jersey-servlet-1.18.1.jar:1.18.1]
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:559) ~[jersey-servlet-1.18.1.jar:1.18.1]
at javax.servlet.GenericServlet.init(GenericServlet.java:244) ~[javax.servlet-3.0.0.v201112011016.jar:na]
at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:540) ~[jetty-servlet-9.0.7.v20131107.jar:9.0.7.v20131107]

Any suggestions guys?

i think you miss to adding few jars in your project.Try adding these to your project:

jersey-multipart.jar and mimepull.jar

if You are using maven project then you can add this dependency:

<dependency>
    <groupId>com.sun.jersey.contribs</groupId>
    <artifactId>jersey-multipart</artifactId>
    <version>1.8</version>
</dependency>

and make sure that version of jersey-multipart jar should be same as the version of jersey bundle jar.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM