You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by gdprao <gd...@yahoo.com> on 2011/02/10 15:45:13 UTC
Mapping Complex input object in JAX-RS service
I am trying a JAX-RS web service with a complex object as input parameter
which comprises bunch of parameters to process the service. The request
parameters could vary depending upon the criteria and hence used @QueryParam
to map parameters and expect JAX-RS to populate my JAXB input object. But
somehow the mapping is not working. Appreciate your help.
Input Object:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "SearchRequestType", propOrder = {
"departmentName"
})
public class SearchRequestType {
@XmlElement(required = true)
protected String departmentName;
//with getters and setters...
}
Service Interface:
@Path("/empService")
public interface IEmployeeService {
@GET
@Path("/getEmployees")
public GetEmployeeResponseType getEmployees(
@QueryParam("departmentName") SearchRequestType request)
throws WebServiceException;
}
<jaxrs:server id="empService" address="/rest">
<jaxrs:serviceBeans>
<ref bean="empService" />
</jaxrs:serviceBeans>
</jaxrs:server>
http://localhost:8080/mycxf/rest/empService/getEmployees?departmentName=accounts
Error Log:
SEVERE: Parameter Class com.test.mycxf.empservice.types.SearchRequestType
has no constructor with single String parameter, static valueOf(String) or
fromString(String) methods
Feb 10, 2011 5:59:43 AM
org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper toResponse
WARNING: WebApplicationException has been caught : no cause is available
--
View this message in context: http://cxf.547215.n5.nabble.com/Mapping-Complex-input-object-in-JAX-RS-service-tp3379441p3379441.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: Mapping Complex input object in JAX-RS service
Posted by gdprao <gd...@yahoo.com>.
@QueryParam("") charmingly worked. Thanks a lot.
Durga
--
View this message in context: http://cxf.547215.n5.nabble.com/Mapping-Complex-input-object-in-JAX-RS-service-tp3379441p3381235.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: Mapping Complex input object in JAX-RS service
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On Thu, Feb 10, 2011 at 2:45 PM, gdprao <gd...@yahoo.com> wrote:
>
> I am trying a JAX-RS web service with a complex object as input parameter
> which comprises bunch of parameters to process the service. The request
> parameters could vary depending upon the criteria and hence used @QueryParam
> to map parameters and expect JAX-RS to populate my JAXB input object. But
> somehow the mapping is not working. Appreciate your help.
>
> Input Object:
>
> @XmlAccessorType(XmlAccessType.FIELD)
> @XmlType(name = "SearchRequestType", propOrder = {
> "departmentName"
> })
> public class SearchRequestType {
>
> @XmlElement(required = true)
> protected String departmentName;
>
> //with getters and setters...
>
> }
>
> Service Interface:
>
> @Path("/empService")
> public interface IEmployeeService {
>
> @GET
> @Path("/getEmployees")
> public GetEmployeeResponseType getEmployees(
> @QueryParam("departmentName") SearchRequestType request)
> throws WebServiceException;
>
> }
If you'd like CXF populate SearchRequestType then you need to do
"@QueryParam("") SearchRequestType request"
Otherwise you need to register a ParameterHandler<SearchRequestType>
implementation where you can create an instance of SearchRequestType
and set the departmentName property...
Cheers, Sergey
>
> <jaxrs:server id="empService" address="/rest">
> <jaxrs:serviceBeans>
> <ref bean="empService" />
> </jaxrs:serviceBeans>
> </jaxrs:server>
>
> http://localhost:8080/mycxf/rest/empService/getEmployees?departmentName=accounts
>
> Error Log:
>
> SEVERE: Parameter Class com.test.mycxf.empservice.types.SearchRequestType
> has no constructor with single String parameter, static valueOf(String) or
> fromString(String) methods
> Feb 10, 2011 5:59:43 AM
> org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper toResponse
> WARNING: WebApplicationException has been caught : no cause is available
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Mapping-Complex-input-object-in-JAX-RS-service-tp3379441p3379441.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>