cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Srinivas Nagulapalli (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CXF-5988) Provide support for a pluggable parameter conversion mechanism for JAX-RS client side proxies
Date Fri, 05 Sep 2014 16:48:28 GMT

    [ https://issues.apache.org/jira/browse/CXF-5988?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14123146#comment-14123146
] 

Srinivas Nagulapalli commented on CXF-5988:
-------------------------------------------

We tried using ParamConverter with no effect. Converter code and client side configuration
to register it are below:
Please note, this approach works for the server-side but not on the client-side.

// SomeDateConverter.java//
package com.my.util;
import java.util.Date;
import javax.ws.rs.ext.ParamConverter;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.ISODateTimeFormat;

public class SomeDateConverter implements ParamConverter<Date> {    
    @Override
    public Date fromString(String dateString) {
        if (dateString.contains("-")) {
            DateTime result = ISODateTimeFormat.dateTimeParser().withZone(DateTimeZone.UTC).parseDateTime(dateString);
            return result.toDate();
        }
        return new Date(Long.parseLong(dateString));
    }
    @Override
    public String toString(Date dateToConvert) {
        return ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC).print(dateToConvert.getTime());
    }
}
// ParamConverterProviderImpl.java//
package com.my.util;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.Map;
import javax.ws.rs.ext.ParamConverter;
import javax.ws.rs.ext.ParamConverterProvider;

public class ParamConverterProviderImpl implements ParamConverterProvider {
    private final Map<Class<?>, ? extends ParamConverter<?>> paramConverters;
    public ParamConverterProviderImpl(Map<Class<?>, ? extends ParamConverter<?>>
paramConverters) {
        this.paramConverters = paramConverters;
    }
    @Override
    public <T> ParamConverter<T> getConverter(Class<T> rawClass, Type genericType,
Annotation[] annotations) {
        return (ParamConverter<T>) paramConverters.get(rawClass);
    }
}
//////////our-config.xml /////////////////
<bean id="someDateConverter" class="com.my.util.SomeDateConverter"/>
<bean id="paramConverterProvider" class="com.my.util.ParamConverterProviderImpl">
    <constructor-arg>
        <map>
		   <entry key="java.util.Date" value-ref="someDateConverter" />
        </map>
    </constructor-arg>
</bean>

<jaxrs:client id="someService" address="http://${somehostname}:$someport}/${somesvc}" serviceClass="com.my.SomeService"
inheritHeaders="true">
    <jaxrs:providers>
        <ref bean="paramConverterProvider" />  
    </jaxrs:providers>
</jaxrs:client>


> Provide support for a pluggable parameter conversion mechanism for JAX-RS client side
proxies
> ---------------------------------------------------------------------------------------------
>
>                 Key: CXF-5988
>                 URL: https://issues.apache.org/jira/browse/CXF-5988
>             Project: CXF
>          Issue Type: Bug
>          Components: Core, JAX-RS
>    Affects Versions: 3.0.1
>         Environment: Windows 7
>            Reporter: Srinivas Nagulapalli
>              Labels: patch
>             Fix For: 3.0.1
>
>
> Server-side JAX-RS implementation allows injection of custom parameter converters using
ParamConverterProvider (http://cxf.apache.org/docs/jax-rs-basics.html#JAX-RSBasics-Parameterconverters).
> A similar mechanism (or the exact same) is required on the client side to control how
parameters are serialized (marshalled). One approach is to allow specifying param converters
when declaring jaxrs:client with Spring and/or programmatically specifying it. 
> A specific case to consider: Client side serialization of Date object (java.util.Date).

> Given the following API:
> @Path(“/someresource”)
> @GET
> void someApi(@MatrixParam(“”) SomeRequestWithDate request);
>  
> Following shows the structure of the request with Dates:
> //----------------------------------------------------
> import java.util.Date;
> public class SomeRequestWithDate {	
>     protected Date startDate;
> 	
>     public Date getStartDate() {
>         return startDate;
>     }
> }
> //----------------------------------------------------
> When API is invoked through a client proxy
> Then the following URL should be generated (where dates are serialized as ISO strings):
> /someresource/;startDate=2014-09-04T19:05:38.785Z
> Instead, currently following URL is generated:
> /someresource/;startDate.date=4;startDate.hours=15;startDate.minutes=4;startDate.month=8;startDate.seconds=34;startDate.time=1409857474660;startDate.year=114;startDate.day=4;startDate.timezoneOffset=240



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message