也许这真是微不足道,但不知怎的,我无法找到原因,为什么这不起作用!
我有一个通过cxf的jaxrs:server指令
公开的服务<jaxrs:server id="specialServiceRS"
address="http://localhost:8080/specialServiceRS">
<jaxrs:serviceBeans>
<ref bean="specialService" />
</jaxrs:serviceBeans>
<jaxrs:providers>
<bean id="jaxbProvider"
class="org.apache.cxf.jaxrs.provider.JAXBElementProvider">
<property name="marshallAsJaxbElement" value="true" />
<property name="unmarshallAsJaxbElement" value="true" />
</bean>
<bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider">
<property name="mapper" ref="jacksonMapper" />
</bean>
<bean class="com.kilo.ProgressiveDateHandler" />
</jaxrs:providers>
</jaxrs:server>
<bean id="jacksonMapper" class="org.codehaus.jackson.map.ObjectMapper">
<property name="serializationConfig.dateFormat">
<bean class="java.text.SimpleDateFormat">
<constructor-arg value="yyyyMMddHH:mm:ss.S" />
</bean>
</property>
<property name="deserializationConfig.dateFormat">
<bean class="java.text.SimpleDateFormat">
<constructor-arg value="yyyyMMddHH:mm:ss.S" />
</bean>
</property>
</bean>
为了能够正确处理日期,我们添加了一个日期处理程序 - ProgressiveDateHandler - 哪个ParameterHandler和ParamConverter。这通过浏览器调用似乎工作正常 - 但是当通过cxf的jaxrs:client指令配置的基于java的客户端调用时,
<jaxrs:client id="specialServiceClient" serviceClass="com.kilo.SpecialServiceImpl"
address="http://localhost:8080/specialServiceRS">
<jaxrs:providers>
<bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider">
<property name="mapper" ref="jacksonMapper" />
</bean>
<bean class="com.kilo.ProgressiveDateHandler" />
</jaxrs:providers>
</jaxrs:client>
<bean id="jacksonMapper" class="org.codehaus.jackson.map.ObjectMapper">
</bean>
我收到以下错误:
java.lang.IllegalArgumentException: Null value on 0 position
at org.apache.cxf.jaxrs.impl.UriBuilderImpl.toStringList(UriBuilderImpl.java:767)
at org.apache.cxf.jaxrs.impl.UriBuilderImpl.queryParam(UriBuilderImpl.java:660)
at org.apache.cxf.jaxrs.client.AbstractClient.addMatrixOrQueryToBuilder(AbstractClient.java:671)
at org.apache.cxf.jaxrs.client.AbstractClient.convertMatrixOrQueryToBuilder(AbstractClient.java:661)
at org.apache.cxf.jaxrs.client.AbstractClient.addMatrixQueryParamsToBuilder(AbstractClient.java:638)
at org.apache.cxf.jaxrs.client.ClientProxyImpl.handleQueries(ClientProxyImpl.java:432)
at org.apache.cxf.jaxrs.client.ClientProxyImpl.invoke(ClientProxyImpl.java:162)
at org.apache.cxf.common.util.CglibProxyHelper$1.intercept(CglibProxyHelper.java:67)
at com.kilo.SpecialServiceImpl$$EnhancerByCGLIB$$f5c4ae3f.getSomeStringsWithDateInput(<generated>)
at com.kilo.SpecialServiceJaxRSTest.testGetSomeStringsWithDateInput(SpecialServiceJaxRSTest.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:292)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
进一步调试时,看起来它正在使用org.apache.cxf.jaxrs.provider.ProviderFactory $ LegacyParamConverter而不是我的ParamConverter即。 ProgressiveDateHandler。如果有人能够指出出现了什么问题,我会非常感激 - 主要是我配置不正确的东西,因为在配置处理程序时,这似乎被宣传为开箱即用。
提前致谢!
P.S。:如果有人想看到它的实际效果,我有一个测试setup。
答案 0 :(得分:1)
使用ParamConverter
的正确方法看起来也是为了实现ParamConverterProvider
界面以及指示here。
@SuppressWarnings("unchecked")
@Override
public <T> ParamConverter<T> getConverter(Class<T> rawType,
Type genericType, Annotation[] annotations) {
if (rawType == Date.class) {
return (ParamConverter<T>) this;
}
return null;
}
没有达到两个界面的概念,这有助于实现与谢尔盖在jsr-339邮件列表上所说的相同的事情 - 但你必须遵守规范! :)
这似乎摆脱了错误 - 希望这也有助于其他人。 此外,如果我走错了路线,请随时纠正我。谢谢!