Trying to implement a JAX-RS resource in Scala. My Java version of this has the following type signature:
@GET
@Path(value="echoold")
@Produces("application/json")
public Map<String,Object> get(
@QueryParam("param") String param,
@QueryParam("asOf") @DefaultValue(NOW) DateWrapper asOf,
@QueryParam("httpError") @DefaultValue("200") int httpError,
@QueryParam("httpErrorMessage") @DefaultValue("") String httpErrorMessage,
@QueryParam("fail") @DefaultValue("false") boolean fail) {
The Scala version is thus:
@GET
@Path(value="echo")
@Produces(Array("application/json"))
def get() = {
@QueryParam("param") param:String,
@QueryParam("asOf") @DefaultValue(NOW) asOf:DateWrapper,
@QueryParam("httpError") @DefaultValue("200") httpError:java.lang.Integer,
@QueryParam("httpErrorMessage") @DefaultValue("") httpErrorMessage:String,
@QueryParam("fail") @DefaultValue("false") fail:java.lang.Boolean):java.util.Map[String,Object] = {
When I start up my application, I get this strange error from RESTEasy (which I've formatted for readability):
org.jboss.resteasy.spi.InternalServerErrorException:
Bad arguments passed to
public java.util.Map opower.api.endpoint.echo.Echo.get(java.lang.String,
opower.api.support.DateWrapper,
java.lang.Integer,
java.lang.String,
java.lang.Boolean)
( java.lang.String someValue,
opower.api.support.DateWrapper opower.api.support.DateWrapper@28a34522,
java.lang.Integer 400,
java.lang.String This is the message,
java.lang.Boolean false )
The underlying exception is:
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.refle开发者_Python百科ct.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:140)
Now, this class is configured via Spring, so it could be some crazy proxy class and it's getting messed up, but has anyone else seen something like this?
(If you don't know what RESTEasy/JAX-RS is doing, basically the container (RESTEasy) finds methods on classes that have those annotations on them, and then calls them when certain URL endpoints are hit)
I had the same with Spring/Scala and @Transactional method annotation.
needed to change proxy-target-class in
<tx:annotation-driven transaction-manager="txManager"
mode="proxy" proxy-target-class="true"/>
Default value for proxy-target-class is false. It requires cglib in classpath.
I guess mode="acpectj" might also work (didn't try)
精彩评论