0

也许这真的很微不足道,但不知何故,我一直无法找到为什么这不起作用!

我有一个通过 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 即。渐进式日期处理程序。如果有人能指出出了什么问题,我将不胜感激——主要是我配置不正确,因为在配置处理程序时,这似乎被宣传为开箱即用。

提前致谢!

PS:如果有人想看到它的实际效果,我有一个测试设置。

4

1 回答 1

1

看起来正确的使用ParamConverter方法也是实现ParamConverterProvider接口以及此处所示。

@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 邮件列表中所说的相同的事情 - 但你必须遵循规范!:)

这似乎摆脱了错误 - 希望这对其他人也有帮助。另外,如果我走错了路线,请随时纠正我。谢谢!

于 2013-05-02T17:35:50.963 回答