You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Bill Speirs <bi...@gmail.com> on 2012/04/12 17:03:51 UTC

ClassCastException: String cannot be cast to ProtocolVersion

Has anyone else seen this error before?

java.lang.ClassCastException: java.lang.String cannot be cast to
org.apache.http.ProtocolVersion
        at
org.apache.http.params.HttpProtocolParams.getVersion(HttpProtocolParams.java:129)
        at
org.apache.http.impl.client.RequestWrapper.getProtocolVersion(RequestWrapper.java:111)
        at
org.apache.http.impl.client.RequestWrapper.getRequestLine(RequestWrapper.java:131)
        at
org.apache.http.client.protocol.RequestDefaultHeaders.process(RequestDefaultHeaders.java:60)
        at
org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:109)
        at
org.apache.http.protocol.HttpRequestExecutor.preProcess(HttpRequestExecutor.java:176)
        at
org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:462)
        at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
        at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:776)
        at BasicHttpRequestor.request(BasicHttpRequestor.java:212)

It happens when I have ClientPNames.HANDLE_REDIRECTS = true and I hit a
server which 302s me to another URL. I'm using the following versions... so
maybe upgrading to the latest dev versions of client would help:

      <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpcore</artifactId>
        <version>4.2-beta1</version>
        <scope>compile</scope>
      </dependency>
      <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpcore-nio</artifactId>
        <version>4.2-beta1</version>
        <scope>compile</scope>
      </dependency>
      <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.1.3</version>
        <scope>compile</scope>
      </dependency>
      <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpasyncclient</artifactId>
        <version>4.0-alpha3</version>
        <scope>compile</scope>
      </dependency>

Thanks in advance...

Bill-

Re: ClassCastException: String cannot be cast to ProtocolVersion

Posted by Bill Speirs <bi...@gmail.com>.
For those playing along at home... turned out to be my fault. I was setting:

params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION,
HttpVersion.HTTP_1_1.toString());

in another part of my program and it simply wasn't being hit until the
redirect by the client.

All is well...

Bill-

On Thu, Apr 12, 2012 at 11:53 AM, Bill Speirs <bi...@gmail.com> wrote:

> Note: upgraded the client to 4.2-beta1 and still getting this casting
> exception.
>
> Bill-
>
>
> On Thu, Apr 12, 2012 at 11:03 AM, Bill Speirs <bi...@gmail.com>wrote:
>
>> Has anyone else seen this error before?
>>
>> java.lang.ClassCastException: java.lang.String cannot be cast to
>> org.apache.http.ProtocolVersion
>>         at
>> org.apache.http.params.HttpProtocolParams.getVersion(HttpProtocolParams.java:129)
>>         at
>> org.apache.http.impl.client.RequestWrapper.getProtocolVersion(RequestWrapper.java:111)
>>         at
>> org.apache.http.impl.client.RequestWrapper.getRequestLine(RequestWrapper.java:131)
>>         at
>> org.apache.http.client.protocol.RequestDefaultHeaders.process(RequestDefaultHeaders.java:60)
>>         at
>> org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:109)
>>         at
>> org.apache.http.protocol.HttpRequestExecutor.preProcess(HttpRequestExecutor.java:176)
>>         at
>> org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:462)
>>         at
>> org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
>>         at
>> org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:776)
>>         at BasicHttpRequestor.request(BasicHttpRequestor.java:212)
>>
>> It happens when I have ClientPNames.HANDLE_REDIRECTS = true and I hit a
>> server which 302s me to another URL. I'm using the following versions... so
>> maybe upgrading to the latest dev versions of client would help:
>>
>>       <dependency>
>>         <groupId>org.apache.httpcomponents</groupId>
>>         <artifactId>httpcore</artifactId>
>>         <version>4.2-beta1</version>
>>         <scope>compile</scope>
>>       </dependency>
>>       <dependency>
>>         <groupId>org.apache.httpcomponents</groupId>
>>         <artifactId>httpcore-nio</artifactId>
>>         <version>4.2-beta1</version>
>>         <scope>compile</scope>
>>       </dependency>
>>       <dependency>
>>         <groupId>org.apache.httpcomponents</groupId>
>>         <artifactId>httpclient</artifactId>
>>         <version>4.1.3</version>
>>         <scope>compile</scope>
>>       </dependency>
>>       <dependency>
>>         <groupId>org.apache.httpcomponents</groupId>
>>         <artifactId>httpasyncclient</artifactId>
>>         <version>4.0-alpha3</version>
>>         <scope>compile</scope>
>>       </dependency>
>>
>> Thanks in advance...
>>
>> Bill-
>>
>
>

Re: ClassCastException: String cannot be cast to ProtocolVersion

Posted by Bill Speirs <bi...@gmail.com>.
Note: upgraded the client to 4.2-beta1 and still getting this casting
exception.

Bill-

On Thu, Apr 12, 2012 at 11:03 AM, Bill Speirs <bi...@gmail.com> wrote:

> Has anyone else seen this error before?
>
> java.lang.ClassCastException: java.lang.String cannot be cast to
> org.apache.http.ProtocolVersion
>         at
> org.apache.http.params.HttpProtocolParams.getVersion(HttpProtocolParams.java:129)
>         at
> org.apache.http.impl.client.RequestWrapper.getProtocolVersion(RequestWrapper.java:111)
>         at
> org.apache.http.impl.client.RequestWrapper.getRequestLine(RequestWrapper.java:131)
>         at
> org.apache.http.client.protocol.RequestDefaultHeaders.process(RequestDefaultHeaders.java:60)
>         at
> org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:109)
>         at
> org.apache.http.protocol.HttpRequestExecutor.preProcess(HttpRequestExecutor.java:176)
>         at
> org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:462)
>         at
> org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
>         at
> org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:776)
>         at BasicHttpRequestor.request(BasicHttpRequestor.java:212)
>
> It happens when I have ClientPNames.HANDLE_REDIRECTS = true and I hit a
> server which 302s me to another URL. I'm using the following versions... so
> maybe upgrading to the latest dev versions of client would help:
>
>       <dependency>
>         <groupId>org.apache.httpcomponents</groupId>
>         <artifactId>httpcore</artifactId>
>         <version>4.2-beta1</version>
>         <scope>compile</scope>
>       </dependency>
>       <dependency>
>         <groupId>org.apache.httpcomponents</groupId>
>         <artifactId>httpcore-nio</artifactId>
>         <version>4.2-beta1</version>
>         <scope>compile</scope>
>       </dependency>
>       <dependency>
>         <groupId>org.apache.httpcomponents</groupId>
>         <artifactId>httpclient</artifactId>
>         <version>4.1.3</version>
>         <scope>compile</scope>
>       </dependency>
>       <dependency>
>         <groupId>org.apache.httpcomponents</groupId>
>         <artifactId>httpasyncclient</artifactId>
>         <version>4.0-alpha3</version>
>         <scope>compile</scope>
>       </dependency>
>
> Thanks in advance...
>
> Bill-
>