You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by eanbiso <bi...@hotmail.it> on 2013/07/01 17:22:03 UTC

java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object

Hi all,
I've a class cast exception invoking a REST web method that wants a byte[]
as input parameter.
I had a SOAP endPoint and I've added all the annotations required to publish
it also with REST technology...
The web method is this:

	@POST
	@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
	@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
	@Path("/AddCluster")
	@ApiOperation(value = "Create a new cluster", notes = "Returns the newly
created cluster", response = IProxyCluster.class, produces
="application/xml,application/json")
	public IProxyCluster AddCluster( 
			@ApiParam(value = "username", required = true) @WebParam(name =
"username") @QueryParam("username") @CxfWSAuthGrain(type=authType.username)
String username ,
			@ApiParam(value = "appGardenID", required = true) @WebParam(name =
"appGardenID") @QueryParam("appGardenID") int appGardenID ,
			@ApiParam(value = "clusterLevel", required = true) @WebParam(name =
"clusterLevel") @QueryParam("clusterLevel") short clusterLevel ,  
			@ApiParam(value = "clusterType", required = true) @WebParam(name =
"clusterType") @QueryParam("clusterType") short clusterType ,  
			@ApiParam(value = "hopsize", required = true) @WebParam(name = "hopsize")
@QueryParam("hopsize") int hopsize , 
			@ApiParam(value = "clusterAddress", required = true) @WebParam(name =
"clusterAddress") @QueryParam("clusterAddress") byte[] clusterAddress ,  
			@ApiParam(value = "name", required = true) @WebParam(name = "name")
@QueryParam("name") String name ,  
			@ApiParam(value = "description", required = true) @WebParam(name =
"description") @QueryParam("description") String description ) throws
DBValidationException;
			
			
When I call the REST web method on client side this exception occurs:

    [01 lug 2013 17:03:14,728] - (TestWS-383) ERROR Exception:
java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object;
    java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object;
	    at
org.apache.cxf.jaxrs.client.AbstractClient.addMatrixQueryParamsToBuilder(AbstractClient.java:632)
	    at
org.apache.cxf.jaxrs.client.ClientProxyImpl.handleQueries(ClientProxyImpl.java:432)
	    at
org.apache.cxf.jaxrs.client.ClientProxyImpl.invoke(ClientProxyImpl.java:162)
	    at $Proxy33.AddCluster(Unknown Source)

...debugging I've found that the parameter that is the cause of the trouble
is the "byte[] clusterAddress"

How can I fix the problem?
I forgot a few annotations?
I'm using cxf_2.7.3
Thanks a lot,

Andrea



--
View this message in context: http://cxf.547215.n5.nabble.com/java-lang-ClassCastException-B-cannot-be-cast-to-Ljava-lang-Object-tp5730141.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi, FYI, primitive arrays will be supported when capturing URI 
properties too now, thanks for catching that issue. I guess if we have

?id=1&id=2

then having them mapped to "int[]" instead of "Integer[]" or 
"List<Integer>" should also work

I'm not going to worry though about List<byte[]> or List<String[]> :-)

Thanks, Sergey
On 02/07/13 15:07, Sergey Beryozkin wrote:
> Hi
> On 02/07/13 12:01, eanbiso wrote:
>> Hi Sergey,
>> I'm testing also other endPoints after their RESTization and I've found
>> another problem connected to particular input parameters...
>> I've this ws method:
>>
>>     @GET
>>     @Path("/parseGenCommandArgs")
>>     @ApiOperation(value = "Parses the given set of arguments according
>> to the
>> data model of the given command in order to prepare the XML to be sent to
>> Dory for the realization of the given generic command.",
>>                     notes = "Returns a String representing the XML to
>> be sent to Dory.",
>>                     response = String.class, produces
>> ="application/xml,application/json")
>>     public String parseGenCommandArgs(
>>             @ApiParam(value = "appGardenID", required = true)
>> @WebParam(name =
>> "appGardenID") @QueryParam("appGardenID")
>> @CxfWSAuthGrain(type=authType.appGarden) int appGardenID,
>>             @ApiParam(value = "protType", required = true)
>> @WebParam(name =
>> "protType") @QueryParam("protType")  short protType,
>>             @ApiParam(value = "profileID", required = true)
>> @WebParam(name =
>> "profileID") @QueryParam("profileID") int profileID,
>>             @ApiParam(value = "objectIDhigh", required = true)
>> @WebParam(name =
>> "objectIDhigh") @QueryParam("objectIDhigh") int objectIDhigh,
>>             @ApiParam(value = "objectIDlow", required = true)
>> @WebParam(name =
>> "objectIDlow") @QueryParam("objectIDlow") int objectIDlow,
>>             @ApiParam(value = "args", required = true) @WebParam(name
>> = "args")
>> @QueryParam("args") List<String[]> args) throws Exception;
>>
>> and when I call the method the exception:
>>
>>      java.lang.ClassCastException:
>> sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl cannot be
>> cast
>> to java.lang.Class
>>
>> occurs on server side, before arriving in the ws method implementor.
>> It is due to the serialization of the List<String[]> input parameter.
>> I've tried to remove the annotation @QueryParam("args") but in this
>> case it
>> continue to not work and a class cast exception occurs client side.
>> Any idea about this problem?
> First of all, thanks for testing the way the JAX-RS runtime maps the
> request info to various parameters. In this specific case, same as with
> the byte[] case, I'd rather see a different type of exception, as
> opposed to ClassCastException, which is a bug.
>
> On the other hand, I don't think a query parameter can be meaningfully
> represented as List<String[]>, I don't know what it means :-). As I said
> the runtime should probably throw a better exception, I need to think
> about it...
>
> IMHO, having SOAP interfaces reused to accept non-SOAP requests works
> reasonably well for simple enough interfaces. When we have complex
> signatures then it'd be better to create a simple RS wrapper which would
> accept the request via some straightforward parameters, then prepare
> parameters in a form expected by a SOAP service implementation, and then
> delegate...
>
> That said, I'll try to get to updating the runtime to behave a bit
> better in cases like this one
>
> Cheers, Sergey
>
>> Thanks,
>>
>> Andrea
>>
>> P.S.
>> For the previous problem it is solved using the Byte[] or removing the
>> @QueryParam annotation.
>>
>>
>>
>> --
>> View this message in context:
>> http://cxf.547215.n5.nabble.com/java-lang-ClassCastException-B-cannot-be-cast-to-Ljava-lang-Object-tp5730141p5730163.html
>>
>> Sent from the cxf-user mailing list archive at Nabble.com.
>>
>
>


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Re: java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 04/07/13 17:57, eanbiso wrote:
> Sorry for the trouble, I've found the simple solution :-):
>      @Produces("application/json;charset=UTF-8")
Yes, this is the right solution,

Re the providers supporting arrays - has been fixed
Thanks, Sergey
> Best regards,
>
> Andrea
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/java-lang-ClassCastException-B-cannot-be-cast-to-Ljava-lang-Object-tp5730141p5730310.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

RE: java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object

Posted by eanbiso <bi...@hotmail.it>.
Sorry for the trouble, I've found the simple solution :-):
    @Produces("application/json;charset=UTF-8")
Best regards,

Andrea



--
View this message in context: http://cxf.547215.n5.nabble.com/java-lang-ClassCastException-B-cannot-be-cast-to-Ljava-lang-Object-tp5730141p5730310.html
Sent from the cxf-user mailing list archive at Nabble.com.

RE: java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object

Posted by eanbiso <bi...@hotmail.it>.
Hi Sergey,
I'm using CXF_2.7.3.
With your help I've found the solution using this BodyReader added clientSide:

@Provider
public class StringArrayBodyReader implements MessageBodyReader<Object> {
     
        private static ObjectMapper jsonMapper = new ObjectMapper();

        @Override
        public boolean isReadable(Class<?> arg0, Type arg1, Annotation[] arg2,
                MediaType arg3) {
            return String[].class.isAssignableFrom(arg0);
        }

        @Override
        public String[] readFrom(Class<Object> arg0, Type arg1,
                Annotation[] arg2, MediaType arg3,
                MultivaluedMap<String, String> arg4, InputStream arg5)
                throws IOException, WebApplicationException {
            // get the content as a string
            String toSplit = streamToString(arg5);
            String[] splitted = null;
            if(toSplit!=null){
                // try to split the String in a String[]
                splitted = jsonMapper.readValue(toSplit, String[].class);
            }else{
                log.error("Failure splitting the content into a String[]");
            }
            return splitted;
        }
        
        private String streamToString(InputStream in) throws IOException {
            try{
                StringBuilder out = new StringBuilder();
                BufferedReader br = new BufferedReader(new InputStreamReader(in));
                for(String line = br.readLine(); line != null; line = br.readLine()) 
                    out.append(line);
                br.close();
                return out.toString();
            }catch(Exception e){
                log.error("Failure getting the String corresponding to the InputStream",e);
                return null;
            }
        }
}

Now it works good!! Thanks a lot!
I've a latest question for you:
if from the server I return a String[] with "normal" Strings, the String arrive properly formatted to the BodyReader; if from the server I return "special" Strings, like °C, in the BodyReader the String arrives modified: °C
I can add a cleaning of the Strings in the BodyReader at client side but I prefer to return always a cleaned String from the Server: do you know if I can add some encoding at the endPoints publication, or  if it is better to add an interceptor server side performing the cleaning, or something else?
Thanks,

Andrea

Date: Thu, 4 Jul 2013 06:31:24 -0700
From: ml-node+s547215n5730306h6@n5.nabble.com
To: bisomagic@hotmail.it
Subject: Re: java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object



	Hi, can you temp make that provider typed on Object, or if it is CXF 

2.7.5, set "org.apache.cxf.jaxrs.providers.ignore.typevars" to true ?


It is a bug: the runtime does not currently deal at all with 

GenericArrayType


I'll be fixing it shortly

Many thanks, Sergey


On 04/07/13 12:44, eanbiso wrote:

> Hi Sergey,

> unfortunately the StringArrayBodyReader is the only one provider I've added loading the endPoint at client side.

> If it can be useful I do a quick recap of the situation.

> - Using swagger u.i that expects a json format the response body is:

>      ["°C"]

> and no problem occurs

> - This is the reponse I see from web browser when I call the REST web method http://*****/DMConfigRest/getUnitsOfMeasure/0/12/0/10/0:
>      ["°C"]

> (there is an unexpected char: Â, but no problem occurs at the invocation)

> - Calling from java code the "No message body reader..." exception occurs client side.

> - In all the cases no exception occurs server side.

> - The annotations I've used to tag the ws interface are these:

>

> @WebService(targetNamespace = JettyConstants.DMConfigNameSpace)

> @Api(value = "/DMConfigRest", description = "Operations about DataModelConfigurator service, used from all the actors which want to edit the XML configuration file used by WSNDataModel")

> @Produces({"application/json"})

> public interface IDataModelConfig extends IPublishable { ...

>

>

>      @GET

>      @Path("/getUnitsOfMeasure/{appGardenID}/{protType}/{profileID}/{objectIDhigh}/{objectIDlow}")

>      @ApiOperation(value = "Tells you what are the units of measure for the object.",

>                      notes = "Returns the unit of measure of the current object.", response = String.class, produces="application/xml,application/json")

>      public String[] getUnitsOfMeasure(

>              @ApiParam(value = "appGardenID", required = true) @WebParam(name = "appGardenID") @PathParam("appGardenID") @CxfWSAuthGrain(type=authType.appGarden) int appGardenID,

>              @ApiParam(value = "protType", required = true) @WebParam(name = "protType") @PathParam("protType") short protType,

>              @ApiParam(value = "profileID", required = true) @WebParam(name = "profileID") @PathParam("profileID") int profileID,

>              @ApiParam(value = "objectIDhigh", required = true) @WebParam(name = "objectIDhigh") @PathParam("objectIDhigh") int objectIDhigh,

>              @ApiParam(value = "objectIDlow", required = true) @WebParam(name = "objectIDlow") @PathParam("objectIDlow") int objectIDlow) throws InstantiationException;

>

> ....

> }

>

> - Now I've added the body reader at client side but I'm not able to arrive in its readFrom method.

>

>

> Thanks,

> Andrea

>

> Date: Thu, 4 Jul 2013 03:23:44 -0700

> From: [hidden email]

> To: [hidden email]

> Subject: Re: java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object

>

>

>

> 	

> Hi Andrea,

>

>

> Re your earlier email: no problems about the questions, please keep them

>

> coming,

>

>

> Re this issue: do you have other providers registered ? Other than that,

>

> I can't think of why readFrom is not called

>

>

> Thanks, Sergey

>

>

> On 04/07/13 11:15, eanbiso wrote:

>

>> Hi Sergey,

>

>> I've tried this solution: I've add a BodyReader at clientSide to manage the

>

>> response from the server.

>

>> I've added this provider:

>

>>

>

>> @Provider

>

>> public class StringArrayBodyReader implements MessageBodyReader<String[]> {

>

>> 	

>

>> 		private static final Plat1Logger log = new

>

>> Plat1Logger(StringArrayBodyReader.class);

>

>>

>

>> 		@Override

>

>> 		public boolean isReadable(Class<?> arg0, Type arg1, Annotation[] arg2,

>

>> 				MediaType arg3) {

>

>> 			return String[].class.isAssignableFrom(arg0);

>

>> 		}

>

>>

>

>> 		@Override

>

>> 		public String[] readFrom(Class<String[]> arg0, Type arg1,

>

>> 				Annotation[] arg2, MediaType arg3,

>

>> 				MultivaluedMap<String, String> arg4, InputStream arg5)

>

>> 				throws IOException, WebApplicationException {

>

>> 			// TODO Auto-generated method stub

>

>> 			return null;

>

>> 		}

>

>> }

>

>>

>

>> at the loading of the REST endPoints:

>

>>

>

>> 		JAXRSClientFactoryBean proxyFactory = new JAXRSClientFactoryBean();

>

>> 		proxyFactory.setServiceClass(clazz);

>

>> 		proxyFactory.setAddress(address);

>

>> 		proxyFactory.setProvider(new StringArrayBodyReader());

>

>>

>

>> by the client application.

>

>> Debugging I've seen that when I call a REST web method from the client I

>

>> arrive in the isReadable method of the provider and it returns true only if

>

>> the return type is a String[].... but I' m not yet able to arrive in the

>

>> readFrom method of the provider (this even if the isReadable has returned a

>

>> true value).

>

>> Do you know why this happens?

>

>> And how can I fix it and force to call the readFrom method when isReadable

>

>> returns true?

>

>> In this way I hope to solve the problem.

>

>> Thanks a lot,

>

>>

>

>> Andrea

>

>>

>

>>

>

>>

>

>>

>

>>

>

>>

>

>> --

>

>> View this message in context: http://cxf.547215.n5.nabble.com/java-lang-ClassCastException-B-cannot-be-cast-to-Ljava-lang-Object-tp5730141p5730271.html
>> Sent from the cxf-user mailing list archive at Nabble.com.

>

>>

>

>



	
	
	
	

	

	
	
		If you reply to this email, your message will be added to the discussion below:
		http://cxf.547215.n5.nabble.com/java-lang-ClassCastException-B-cannot-be-cast-to-Ljava-lang-Object-tp5730141p5730306.html
	
	
		
		To unsubscribe from java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object, click here.

		NAML
	 		 	   		  



--
View this message in context: http://cxf.547215.n5.nabble.com/java-lang-ClassCastException-B-cannot-be-cast-to-Ljava-lang-Object-tp5730141p5730309.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi, can you temp make that provider typed on Object, or if it is CXF 
2.7.5, set "org.apache.cxf.jaxrs.providers.ignore.typevars" to true ?

It is a bug: the runtime does not currently deal at all with 
GenericArrayType

I'll be fixing it shortly
Many thanks, Sergey

On 04/07/13 12:44, eanbiso wrote:
> Hi Sergey,
> unfortunately the StringArrayBodyReader is the only one provider I've added loading the endPoint at client side.
> If it can be useful I do a quick recap of the situation.
> - Using swagger u.i that expects a json format the response body is:
>      ["°C"]
> and no problem occurs
> - This is the reponse I see from web browser when I call the REST web method http://*****/DMConfigRest/getUnitsOfMeasure/0/12/0/10/0:
>      ["°C"]
> (there is an unexpected char: Â, but no problem occurs at the invocation)
> - Calling from java code the "No message body reader..." exception occurs client side.
> - In all the cases no exception occurs server side.
> - The annotations I've used to tag the ws interface are these:
>
> @WebService(targetNamespace = JettyConstants.DMConfigNameSpace)
> @Api(value = "/DMConfigRest", description = "Operations about DataModelConfigurator service, used from all the actors which want to edit the XML configuration file used by WSNDataModel")
> @Produces({"application/json"})
> public interface IDataModelConfig extends IPublishable { ...
>
>
>      @GET
>      @Path("/getUnitsOfMeasure/{appGardenID}/{protType}/{profileID}/{objectIDhigh}/{objectIDlow}")
>      @ApiOperation(value = "Tells you what are the units of measure for the object.",
>                      notes = "Returns the unit of measure of the current object.", response = String.class, produces="application/xml,application/json")
>      public String[] getUnitsOfMeasure(
>              @ApiParam(value = "appGardenID", required = true) @WebParam(name = "appGardenID") @PathParam("appGardenID") @CxfWSAuthGrain(type=authType.appGarden) int appGardenID,
>              @ApiParam(value = "protType", required = true) @WebParam(name = "protType") @PathParam("protType") short protType,
>              @ApiParam(value = "profileID", required = true) @WebParam(name = "profileID") @PathParam("profileID") int profileID,
>              @ApiParam(value = "objectIDhigh", required = true) @WebParam(name = "objectIDhigh") @PathParam("objectIDhigh") int objectIDhigh,
>              @ApiParam(value = "objectIDlow", required = true) @WebParam(name = "objectIDlow") @PathParam("objectIDlow") int objectIDlow) throws InstantiationException;
>
> ....
> }
>
> - Now I've added the body reader at client side but I'm not able to arrive in its readFrom method.
>
>
> Thanks,
> Andrea
>
> Date: Thu, 4 Jul 2013 03:23:44 -0700
> From: ml-node+s547215n5730288h48@n5.nabble.com
> To: bisomagic@hotmail.it
> Subject: Re: java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object
>
>
>
> 	
> Hi Andrea,
>
>
> Re your earlier email: no problems about the questions, please keep them
>
> coming,
>
>
> Re this issue: do you have other providers registered ? Other than that,
>
> I can't think of why readFrom is not called
>
>
> Thanks, Sergey
>
>
> On 04/07/13 11:15, eanbiso wrote:
>
>> Hi Sergey,
>
>> I've tried this solution: I've add a BodyReader at clientSide to manage the
>
>> response from the server.
>
>> I've added this provider:
>
>>
>
>> @Provider
>
>> public class StringArrayBodyReader implements MessageBodyReader<String[]> {
>
>> 	
>
>> 		private static final Plat1Logger log = new
>
>> Plat1Logger(StringArrayBodyReader.class);
>
>>
>
>> 		@Override
>
>> 		public boolean isReadable(Class<?> arg0, Type arg1, Annotation[] arg2,
>
>> 				MediaType arg3) {
>
>> 			return String[].class.isAssignableFrom(arg0);
>
>> 		}
>
>>
>
>> 		@Override
>
>> 		public String[] readFrom(Class<String[]> arg0, Type arg1,
>
>> 				Annotation[] arg2, MediaType arg3,
>
>> 				MultivaluedMap<String, String> arg4, InputStream arg5)
>
>> 				throws IOException, WebApplicationException {
>
>> 			// TODO Auto-generated method stub
>
>> 			return null;
>
>> 		}
>
>> }
>
>>
>
>> at the loading of the REST endPoints:
>
>>
>
>> 		JAXRSClientFactoryBean proxyFactory = new JAXRSClientFactoryBean();
>
>> 		proxyFactory.setServiceClass(clazz);
>
>> 		proxyFactory.setAddress(address);
>
>> 		proxyFactory.setProvider(new StringArrayBodyReader());
>
>>
>
>> by the client application.
>
>> Debugging I've seen that when I call a REST web method from the client I
>
>> arrive in the isReadable method of the provider and it returns true only if
>
>> the return type is a String[].... but I' m not yet able to arrive in the
>
>> readFrom method of the provider (this even if the isReadable has returned a
>
>> true value).
>
>> Do you know why this happens?
>
>> And how can I fix it and force to call the readFrom method when isReadable
>
>> returns true?
>
>> In this way I hope to solve the problem.
>
>> Thanks a lot,
>
>>
>
>> Andrea
>
>>
>
>>
>
>>
>
>>
>
>>
>
>>
>
>> --
>
>> View this message in context: http://cxf.547215.n5.nabble.com/java-lang-ClassCastException-B-cannot-be-cast-to-Ljava-lang-Object-tp5730141p5730271.html
>> Sent from the cxf-user mailing list archive at Nabble.com.
>
>>
>
>


RE: java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object

Posted by eanbiso <bi...@hotmail.it>.
Hi Sergey,
unfortunately the StringArrayBodyReader is the only one provider I've added loading the endPoint at client side.
If it can be useful I do a quick recap of the situation.
- Using swagger u.i that expects a json format the response body is: 
    ["°C"]
and no problem occurs
- This is the reponse I see from web browser when I call the REST web method http://*****/DMConfigRest/getUnitsOfMeasure/0/12/0/10/0:
    ["°C"]
(there is an unexpected char: Â, but no problem occurs at the invocation)
- Calling from java code the "No message body reader..." exception occurs client side.
- In all the cases no exception occurs server side.
- The annotations I've used to tag the ws interface are these:

@WebService(targetNamespace = JettyConstants.DMConfigNameSpace)
@Api(value = "/DMConfigRest", description = "Operations about DataModelConfigurator service, used from all the actors which want to edit the XML configuration file used by WSNDataModel")
@Produces({"application/json"})
public interface IDataModelConfig extends IPublishable { ... 


    @GET
    @Path("/getUnitsOfMeasure/{appGardenID}/{protType}/{profileID}/{objectIDhigh}/{objectIDlow}")
    @ApiOperation(value = "Tells you what are the units of measure for the object.", 
                    notes = "Returns the unit of measure of the current object.", response = String.class, produces="application/xml,application/json")
    public String[] getUnitsOfMeasure(
            @ApiParam(value = "appGardenID", required = true) @WebParam(name = "appGardenID") @PathParam("appGardenID") @CxfWSAuthGrain(type=authType.appGarden) int appGardenID,
            @ApiParam(value = "protType", required = true) @WebParam(name = "protType") @PathParam("protType") short protType, 
            @ApiParam(value = "profileID", required = true) @WebParam(name = "profileID") @PathParam("profileID") int profileID, 
            @ApiParam(value = "objectIDhigh", required = true) @WebParam(name = "objectIDhigh") @PathParam("objectIDhigh") int objectIDhigh, 
            @ApiParam(value = "objectIDlow", required = true) @WebParam(name = "objectIDlow") @PathParam("objectIDlow") int objectIDlow) throws InstantiationException;

....
}

- Now I've added the body reader at client side but I'm not able to arrive in its readFrom method.


Thanks,
Andrea

Date: Thu, 4 Jul 2013 03:23:44 -0700
From: ml-node+s547215n5730288h48@n5.nabble.com
To: bisomagic@hotmail.it
Subject: Re: java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object



	
Hi Andrea,


Re your earlier email: no problems about the questions, please keep them 

coming,


Re this issue: do you have other providers registered ? Other than that, 

I can't think of why readFrom is not called


Thanks, Sergey


On 04/07/13 11:15, eanbiso wrote:

> Hi Sergey,

> I've tried this solution: I've add a BodyReader at clientSide to manage the

> response from the server.

> I've added this provider:

>

> @Provider

> public class StringArrayBodyReader implements MessageBodyReader<String[]> {

> 	

> 		private static final Plat1Logger log = new

> Plat1Logger(StringArrayBodyReader.class);

>

> 		@Override

> 		public boolean isReadable(Class<?> arg0, Type arg1, Annotation[] arg2,

> 				MediaType arg3) {

> 			return String[].class.isAssignableFrom(arg0);

> 		}

>

> 		@Override

> 		public String[] readFrom(Class<String[]> arg0, Type arg1,

> 				Annotation[] arg2, MediaType arg3,

> 				MultivaluedMap<String, String> arg4, InputStream arg5)

> 				throws IOException, WebApplicationException {

> 			// TODO Auto-generated method stub

> 			return null;

> 		}

> }

>

> at the loading of the REST endPoints:

>

> 		JAXRSClientFactoryBean proxyFactory = new JAXRSClientFactoryBean();

> 		proxyFactory.setServiceClass(clazz);

> 		proxyFactory.setAddress(address);

> 		proxyFactory.setProvider(new StringArrayBodyReader());

>

> by the client application.

> Debugging I've seen that when I call a REST web method from the client I

> arrive in the isReadable method of the provider and it returns true only if

> the return type is a String[].... but I' m not yet able to arrive in the

> readFrom method of the provider (this even if the isReadable has returned a

> true value).

> Do you know why this happens?

> And how can I fix it and force to call the readFrom method when isReadable

> returns true?

> In this way I hope to solve the problem.

> Thanks a lot,

>

> Andrea

>

>

>

>

>

>

> --

> View this message in context: http://cxf.547215.n5.nabble.com/java-lang-ClassCastException-B-cannot-be-cast-to-Ljava-lang-Object-tp5730141p5730271.html
> Sent from the cxf-user mailing list archive at Nabble.com.

>


-- 

Sergey Beryozkin


Talend Community Coders

http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com


	
	
	
	

	

	
	
		If you reply to this email, your message will be added to the discussion below:
		http://cxf.547215.n5.nabble.com/java-lang-ClassCastException-B-cannot-be-cast-to-Ljava-lang-Object-tp5730141p5730288.html
	
	
		
		To unsubscribe from java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object, click here.

		NAML
	 		 	   		  



--
View this message in context: http://cxf.547215.n5.nabble.com/java-lang-ClassCastException-B-cannot-be-cast-to-Ljava-lang-Object-tp5730141p5730291.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi Andrea,

Re your earlier email: no problems about the questions, please keep them 
coming,

Re this issue: do you have other providers registered ? Other than that, 
I can't think of why readFrom is not called

Thanks, Sergey

On 04/07/13 11:15, eanbiso wrote:
> Hi Sergey,
> I've tried this solution: I've add a BodyReader at clientSide to manage the
> response from the server.
> I've added this provider:
>
> @Provider
> public class StringArrayBodyReader implements MessageBodyReader<String[]> {
> 	
> 		private static final Plat1Logger log = new
> Plat1Logger(StringArrayBodyReader.class);
>
> 		@Override
> 		public boolean isReadable(Class<?> arg0, Type arg1, Annotation[] arg2,
> 				MediaType arg3) {
> 			return String[].class.isAssignableFrom(arg0);
> 		}
>
> 		@Override
> 		public String[] readFrom(Class<String[]> arg0, Type arg1,
> 				Annotation[] arg2, MediaType arg3,
> 				MultivaluedMap<String, String> arg4, InputStream arg5)
> 				throws IOException, WebApplicationException {
> 			// TODO Auto-generated method stub
> 			return null;
> 		}
> }
>
> at the loading of the REST endPoints:
>
> 		JAXRSClientFactoryBean proxyFactory = new JAXRSClientFactoryBean();
> 		proxyFactory.setServiceClass(clazz);
> 		proxyFactory.setAddress(address);
> 		proxyFactory.setProvider(new StringArrayBodyReader());
>
> by the client application.
> Debugging I've seen that when I call a REST web method from the client I
> arrive in the isReadable method of the provider and it returns true only if
> the return type is a String[].... but I' m not yet able to arrive in the
> readFrom method of the provider (this even if the isReadable has returned a
> true value).
> Do you know why this happens?
> And how can I fix it and force to call the readFrom method when isReadable
> returns true?
> In this way I hope to solve the problem.
> Thanks a lot,
>
> Andrea
>
>
>
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/java-lang-ClassCastException-B-cannot-be-cast-to-Ljava-lang-Object-tp5730141p5730271.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Re: java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object

Posted by eanbiso <bi...@hotmail.it>.
Hi Sergey,
I've tried this solution: I've add a BodyReader at clientSide to manage the
response from the server.
I've added this provider:

@Provider
public class StringArrayBodyReader implements MessageBodyReader<String[]> {
	 
		private static final Plat1Logger log = new
Plat1Logger(StringArrayBodyReader.class);

		@Override
		public boolean isReadable(Class<?> arg0, Type arg1, Annotation[] arg2,
				MediaType arg3) {
			return String[].class.isAssignableFrom(arg0);
		}

		@Override
		public String[] readFrom(Class<String[]> arg0, Type arg1,
				Annotation[] arg2, MediaType arg3,
				MultivaluedMap<String, String> arg4, InputStream arg5)
				throws IOException, WebApplicationException {
			// TODO Auto-generated method stub
			return null;
		}
}

at the loading of the REST endPoints:

		JAXRSClientFactoryBean proxyFactory = new JAXRSClientFactoryBean();
		proxyFactory.setServiceClass(clazz);
		proxyFactory.setAddress(address);
		proxyFactory.setProvider(new StringArrayBodyReader());

by the client application.
Debugging I've seen that when I call a REST web method from the client I
arrive in the isReadable method of the provider and it returns true only if
the return type is a String[].... but I' m not yet able to arrive in the
readFrom method of the provider (this even if the isReadable has returned a
true value).
Do you know why this happens?
And how can I fix it and force to call the readFrom method when isReadable
returns true?
In this way I hope to solve the problem.
Thanks a lot,

Andrea






--
View this message in context: http://cxf.547215.n5.nabble.com/java-lang-ClassCastException-B-cannot-be-cast-to-Ljava-lang-Object-tp5730141p5730271.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object

Posted by eanbiso <bi...@hotmail.it>.
Hi Sergey,
thanks for the help.
I've another question for you... I hope this is the last :-)
Testing my REST API I've another anomalous behavior with this method:

    @GET
   
@Path("/getUnitsOfMeasure/{appGardenID}/{protType}/{profileID}/{objectIDhigh}/{objectIDlow}")
    @ApiOperation(value = "Tells you what are the units of measure for the
object.", 
                          notes = "Returns the unit of measure of the
current object.", response = String.class,
produces="application/xml,application/json")
    public String[] getUnitsOfMeasure(
                        @ApiParam(value = "appGardenID", required = true)
@WebParam(name = "appGardenID") @PathParam("appGardenID")
@CxfWSAuthGrain(type=authType.appGarden) int appGardenID,
                        @ApiParam(value = "protType", required = true)
@WebParam(name = "protType") @PathParam("protType") short protType, 
                        @ApiParam(value = "profileID", required = true)
@WebParam(name = "profileID") @PathParam("profileID") int profileID, 
                        @ApiParam(value = "objectIDhigh", required = true)
@WebParam(name = "objectIDhigh") @PathParam("objectIDhigh") int
objectIDhigh, 
                        @ApiParam(value = "objectIDlow", required = true)
@WebParam(name = "objectIDlow") @PathParam("objectIDlow") int objectIDlow)
throws InstantiationException;

I'm not able to properly manage the return type String[].
If I do not use @Produces annotation and I invoke the web method from a web
browser I see the String[] JSON formatted, but if I call the web method from
java code the exception:

    .No message body reader has been found for class : class
[Ljava.lang.String;, ContentType : application/json.
 
occurs on client side. I see the same exception if I call the web method
from Swagger U.I. with xml format expetced (if I select json format no
problem occurs).
I've tried to use also one of these annotations:

    @Produces("multipart/form-data") / @Produces("multipart/mixed") /
@Produces("multipart/mixed;type=text/xml")...

but the situation worsens and an exception occurs server side before
arriving in the implementor.
Can you help me?
Thanks a lot,

Andrea



--
View this message in context: http://cxf.547215.n5.nabble.com/java-lang-ClassCastException-B-cannot-be-cast-to-Ljava-lang-Object-tp5730141p5730240.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 02/07/13 12:01, eanbiso wrote:
> Hi Sergey,
> I'm testing also other endPoints after their RESTization and I've found
> another problem connected to particular input parameters...
> I've this ws method:
>
> 	@GET
> 	@Path("/parseGenCommandArgs")
> 	@ApiOperation(value = "Parses the given set of arguments according to the
> data model of the given command in order to prepare the XML to be sent to
> Dory for the realization of the given generic command.",
> 					notes = "Returns a String representing the XML to be sent to Dory.",
> 					response = String.class, produces ="application/xml,application/json")
> 	public String parseGenCommandArgs(
> 			@ApiParam(value = "appGardenID", required = true) @WebParam(name =
> "appGardenID") @QueryParam("appGardenID")
> @CxfWSAuthGrain(type=authType.appGarden) int appGardenID,
> 			@ApiParam(value = "protType", required = true) @WebParam(name =
> "protType") @QueryParam("protType")  short protType,
> 			@ApiParam(value = "profileID", required = true) @WebParam(name =
> "profileID") @QueryParam("profileID") int profileID,
> 			@ApiParam(value = "objectIDhigh", required = true) @WebParam(name =
> "objectIDhigh") @QueryParam("objectIDhigh") int objectIDhigh,
> 			@ApiParam(value = "objectIDlow", required = true) @WebParam(name =
> "objectIDlow") @QueryParam("objectIDlow") int objectIDlow,
> 			@ApiParam(value = "args", required = true) @WebParam(name = "args")
> @QueryParam("args") List<String[]> args) throws Exception;
>
> and when I call the method the exception:
>
>      java.lang.ClassCastException:
> sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl cannot be cast
> to java.lang.Class
>
> occurs on server side, before arriving in the ws method implementor.
> It is due to the serialization of the List<String[]> input parameter.
> I've tried to remove the annotation @QueryParam("args") but in this case it
> continue to not work and a class cast exception occurs client side.
> Any idea about this problem?
First of all, thanks for testing the way the JAX-RS runtime maps the 
request info to various parameters. In this specific case, same as with 
the byte[] case, I'd rather see a different type of exception, as 
opposed to ClassCastException, which is a bug.

On the other hand, I don't think a query parameter can be meaningfully 
represented as List<String[]>, I don't know what it means :-). As I said 
the runtime should probably throw a better exception, I need to think 
about it...

IMHO, having SOAP interfaces reused to accept non-SOAP requests works 
reasonably well for simple enough interfaces. When we have complex 
signatures then it'd be better to create a simple RS wrapper which would 
accept the request via some straightforward parameters, then prepare 
parameters in a form expected by a SOAP service implementation, and then 
delegate...

That said, I'll try to get to updating the runtime to behave a bit 
better in cases like this one

Cheers, Sergey

> Thanks,
>
> Andrea
>
> P.S.
> For the previous problem it is solved using the Byte[] or removing the
> @QueryParam annotation.
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/java-lang-ClassCastException-B-cannot-be-cast-to-Ljava-lang-Object-tp5730141p5730163.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

RE: java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object

Posted by eanbiso <bi...@hotmail.it>.
Hi Sergey,
I'm testing also other endPoints after their RESTization and I've found
another problem connected to particular input parameters...
I've this ws method:

	@GET
	@Path("/parseGenCommandArgs")
	@ApiOperation(value = "Parses the given set of arguments according to the
data model of the given command in order to prepare the XML to be sent to
Dory for the realization of the given generic command.", 
					notes = "Returns a String representing the XML to be sent to Dory.", 
					response = String.class, produces ="application/xml,application/json")
	public String parseGenCommandArgs(
			@ApiParam(value = "appGardenID", required = true) @WebParam(name =
"appGardenID") @QueryParam("appGardenID")
@CxfWSAuthGrain(type=authType.appGarden) int appGardenID,
			@ApiParam(value = "protType", required = true) @WebParam(name =
"protType") @QueryParam("protType")  short protType, 
			@ApiParam(value = "profileID", required = true) @WebParam(name =
"profileID") @QueryParam("profileID") int profileID, 
			@ApiParam(value = "objectIDhigh", required = true) @WebParam(name =
"objectIDhigh") @QueryParam("objectIDhigh") int objectIDhigh, 
			@ApiParam(value = "objectIDlow", required = true) @WebParam(name =
"objectIDlow") @QueryParam("objectIDlow") int objectIDlow,
			@ApiParam(value = "args", required = true) @WebParam(name = "args")
@QueryParam("args") List<String[]> args) throws Exception;

and when I call the method the exception: 

    java.lang.ClassCastException:
sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl cannot be cast
to java.lang.Class

occurs on server side, before arriving in the ws method implementor.
It is due to the serialization of the List<String[]> input parameter. 
I've tried to remove the annotation @QueryParam("args") but in this case it
continue to not work and a class cast exception occurs client side. 
Any idea about this problem?
Thanks,

Andrea

P.S.
For the previous problem it is solved using the Byte[] or removing the
@QueryParam annotation. 



--
View this message in context: http://cxf.547215.n5.nabble.com/java-lang-ClassCastException-B-cannot-be-cast-to-Ljava-lang-Object-tp5730141p5730163.html
Sent from the cxf-user mailing list archive at Nabble.com.

RE: java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object

Posted by eanbiso <bi...@hotmail.it>.
Hi Sergey,
I've seen that without @QueryParam annotation the parameter is properly managed and serialized, no exception occurs and it arrives properly built to the server.
Instead if I define it as @PathParam (leaving all other parameters as @QueryParam) no exception occurs but it arrives as an empty byte[] to the server.
So the first solution (remove @QueryParam tag for the byte[]) seems to work...but there is no problem if I leave a parameter without annotations (@QueryParam or @PathParam)?
In the morning I'll try also the solution of the Byte[].
Bets regards,

Andrea

Date: Mon, 1 Jul 2013 09:14:40 -0700
From: ml-node+s547215n5730146h46@n5.nabble.com
To: bisomagic@hotmail.it
Subject: Re: java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object



	Hi


I'm not sure attempting to map a byte[] array to a query parameter will 

work, but I guess no ClassCastException should be reported but something 

more meaningful, I'll try to have to look into it.

In meantime, try Byte[]. may be that will help


Sergey

On 01/07/13 16:22, eanbiso wrote:

> Hi all,

> I've a class cast exception invoking a REST web method that wants a byte[]

> as input parameter.

> I had a SOAP endPoint and I've added all the annotations required to publish

> it also with REST technology...

> The web method is this:

>

> 	@POST

> 	@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})

> 	@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})

> 	@Path("/AddCluster")

> 	@ApiOperation(value = "Create a new cluster", notes = "Returns the newly

> created cluster", response = IProxyCluster.class, produces

> ="application/xml,application/json")

> 	public IProxyCluster AddCluster(

> 			@ApiParam(value = "username", required = true) @WebParam(name =

> "username") @QueryParam("username") @CxfWSAuthGrain(type=authType.username)

> String username ,

> 			@ApiParam(value = "appGardenID", required = true) @WebParam(name =

> "appGardenID") @QueryParam("appGardenID") int appGardenID ,

> 			@ApiParam(value = "clusterLevel", required = true) @WebParam(name =

> "clusterLevel") @QueryParam("clusterLevel") short clusterLevel ,

> 			@ApiParam(value = "clusterType", required = true) @WebParam(name =

> "clusterType") @QueryParam("clusterType") short clusterType ,

> 			@ApiParam(value = "hopsize", required = true) @WebParam(name = "hopsize")

> @QueryParam("hopsize") int hopsize ,

> 			@ApiParam(value = "clusterAddress", required = true) @WebParam(name =

> "clusterAddress") @QueryParam("clusterAddress") byte[] clusterAddress ,

> 			@ApiParam(value = "name", required = true) @WebParam(name = "name")

> @QueryParam("name") String name ,

> 			@ApiParam(value = "description", required = true) @WebParam(name =

> "description") @QueryParam("description") String description ) throws

> DBValidationException;

> 			

> 			

> When I call the REST web method on client side this exception occurs:

>

>      [01 lug 2013 17:03:14,728] - (TestWS-383) ERROR Exception:

> java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object;

>      java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object;

> 	    at

> org.apache.cxf.jaxrs.client.AbstractClient.addMatrixQueryParamsToBuilder(AbstractClient.java:632)

> 	    at

> org.apache.cxf.jaxrs.client.ClientProxyImpl.handleQueries(ClientProxyImpl.java:432)

> 	    at

> org.apache.cxf.jaxrs.client.ClientProxyImpl.invoke(ClientProxyImpl.java:162)

> 	    at $Proxy33.AddCluster(Unknown Source)

>

> ...debugging I've found that the parameter that is the cause of the trouble

> is the "byte[] clusterAddress"

>

> How can I fix the problem?

> I forgot a few annotations?

> I'm using cxf_2.7.3

> Thanks a lot,

>

> Andrea

>

>

>

> --

> View this message in context: http://cxf.547215.n5.nabble.com/java-lang-ClassCastException-B-cannot-be-cast-to-Ljava-lang-Object-tp5730141.html
> Sent from the cxf-user mailing list archive at Nabble.com.

>


-- 

Sergey Beryozkin


Talend Community Coders

http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com


	
	
	
	

	

	
	
		If you reply to this email, your message will be added to the discussion below:
		http://cxf.547215.n5.nabble.com/java-lang-ClassCastException-B-cannot-be-cast-to-Ljava-lang-Object-tp5730141p5730146.html
	
	
		
		To unsubscribe from java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object, click here.

		NAML
	 		 	   		  



--
View this message in context: http://cxf.547215.n5.nabble.com/java-lang-ClassCastException-B-cannot-be-cast-to-Ljava-lang-Object-tp5730141p5730154.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

I'm not sure attempting to map a byte[] array to a query parameter will 
work, but I guess no ClassCastException should be reported but something 
more meaningful, I'll try to have to look into it.
In meantime, try Byte[]. may be that will help

Sergey
On 01/07/13 16:22, eanbiso wrote:
> Hi all,
> I've a class cast exception invoking a REST web method that wants a byte[]
> as input parameter.
> I had a SOAP endPoint and I've added all the annotations required to publish
> it also with REST technology...
> The web method is this:
>
> 	@POST
> 	@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
> 	@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
> 	@Path("/AddCluster")
> 	@ApiOperation(value = "Create a new cluster", notes = "Returns the newly
> created cluster", response = IProxyCluster.class, produces
> ="application/xml,application/json")
> 	public IProxyCluster AddCluster(
> 			@ApiParam(value = "username", required = true) @WebParam(name =
> "username") @QueryParam("username") @CxfWSAuthGrain(type=authType.username)
> String username ,
> 			@ApiParam(value = "appGardenID", required = true) @WebParam(name =
> "appGardenID") @QueryParam("appGardenID") int appGardenID ,
> 			@ApiParam(value = "clusterLevel", required = true) @WebParam(name =
> "clusterLevel") @QueryParam("clusterLevel") short clusterLevel ,
> 			@ApiParam(value = "clusterType", required = true) @WebParam(name =
> "clusterType") @QueryParam("clusterType") short clusterType ,
> 			@ApiParam(value = "hopsize", required = true) @WebParam(name = "hopsize")
> @QueryParam("hopsize") int hopsize ,
> 			@ApiParam(value = "clusterAddress", required = true) @WebParam(name =
> "clusterAddress") @QueryParam("clusterAddress") byte[] clusterAddress ,
> 			@ApiParam(value = "name", required = true) @WebParam(name = "name")
> @QueryParam("name") String name ,
> 			@ApiParam(value = "description", required = true) @WebParam(name =
> "description") @QueryParam("description") String description ) throws
> DBValidationException;
> 			
> 			
> When I call the REST web method on client side this exception occurs:
>
>      [01 lug 2013 17:03:14,728] - (TestWS-383) ERROR Exception:
> java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object;
>      java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object;
> 	    at
> org.apache.cxf.jaxrs.client.AbstractClient.addMatrixQueryParamsToBuilder(AbstractClient.java:632)
> 	    at
> org.apache.cxf.jaxrs.client.ClientProxyImpl.handleQueries(ClientProxyImpl.java:432)
> 	    at
> org.apache.cxf.jaxrs.client.ClientProxyImpl.invoke(ClientProxyImpl.java:162)
> 	    at $Proxy33.AddCluster(Unknown Source)
>
> ...debugging I've found that the parameter that is the cause of the trouble
> is the "byte[] clusterAddress"
>
> How can I fix the problem?
> I forgot a few annotations?
> I'm using cxf_2.7.3
> Thanks a lot,
>
> Andrea
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/java-lang-ClassCastException-B-cannot-be-cast-to-Ljava-lang-Object-tp5730141.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com