hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From srikalyan swayampakula <srikalyansswa...@gmail.com>
Subject Re: ClientProtocolException for 204 No Content as response header
Date Mon, 14 Jul 2014 00:38:23 GMT
Thanks Oleg, Seems like a faulty server issue (I am really sure :) ) but I
could pin point the issue by adding more logging to BasicLineParser in the
method hasProtocolVersion like this

{code}
public boolean hasProtocolVersion(final CharArrayBuffer buffer,
                                      final ParserCursor cursor) {
        Args.notNull(buffer, "Char array buffer");
        Args.notNull(cursor, "Parser cursor");
        int index = cursor.getPos();

        final String protoname = this.protocol.getProtocol();
        final int  protolength = protoname.length();

       if (this.log.isDebugEnabled()) {
          this.log.debug("Testing the line: " + buffer.toString() + " the
cursor is: " + cursor
                         + " the protname is: " + protoname);
       }

        if (buffer.length() < protolength+4)
         {

            return false; // not long enough for "HTTP/1.1"
        }

        if (index < 0) {
            // end of line, no tolerance for trailing whitespace
            // this works only for single-digit major and minor version
            index = buffer.length() -4 -protolength;
        } else if (index == 0) {
            // beginning of line, tolerate leading whitespace
            while ((index < buffer.length()) &&
                    HTTP.isWhitespace(buffer.charAt(index))) {
                 index++;
             }
        } // else within line, don't tolerate whitespace


        if (index + protolength + 4 > buffer.length()) {
           if (this.log.isDebugEnabled()) {
              this.log.debug("Returning false for buffer: " +
buffer.toString() + " the cursor is: " + cursor
                             + " the protname is: " + protoname +" the
index is: "+index);
           }
            return false;
        }


        // just check protocol name and slash, no need to analyse the
version
        boolean ok = true;
        for (int j=0; ok && (j<protolength); j++) {
           ok = (buffer.charAt(index+j) == protoname.charAt(j));
           if (this.log.isDebugEnabled()) {
              this.log.debug(
                 "buffer.charAt("+index+"+j) == protoname.charAt(j) : " +
buffer.charAt(index + j)
                 + " == " + protoname.charAt(j) + " ok is: " + ok);
           }
        }

       if (this.log.isDebugEnabled()) {
          this.log.debug("The value of ok after for is : " +
buffer.toString() + " the cursor is: " + cursor
                         + " the protname is: " + protoname +" the index
is: "+index + " and ok is: "+ok);
       }

        if (ok) {
            ok = (buffer.charAt(index+protolength) == '/');
        }

       if (this.log.isDebugEnabled()) {
          this.log.debug("The value of ok after last if is : " +
buffer.toString() + " the cursor is: " + cursor
                         + " the protname is: " + protoname +" the index
is: "+index + " and ok is: "+ok);
       }

        return ok;
    }
{code}

and I found the stack trace to be


Sun Jul 13 00:51:06.140 PDT 2014 | "ajp-bio-8009"-exec-2 |
org.apache.http.message.BasicLineParser | DEBUG | Testing the line:
^_<U+008B>^H^@^@^@^@^@^@^@^C^@^@^@^@^@^@^@^@^@HTTP/1.1 204 No Con
tent the cursor is: [0>0>43] the protname is: HTTP
Sun Jul 13 00:51:06.140 PDT 2014 | "ajp-bio-8009"-exec-2 |
org.apache.http.message.BasicLineParser | DEBUG | buffer.charAt(0+j) ==
protoname.charAt(j) : ^_ == H ok is: false
Sun Jul 13 00:51:06.141 PDT 2014 | "ajp-bio-8009"-exec-2 |
org.apache.http.message.BasicLineParser | DEBUG | The value of ok after for
is : ^_<U+008B>^H^@^@^@^@^@^@^@^C^@^@^@^@^@^@^@^@^@HTTP/1
.1 204 No Content the cursor is: [0>0>43] the protname is: HTTP the index
is: 0 and ok is: false
Sun Jul 13 00:51:06.141 PDT 2014 | "ajp-bio-8009"-exec-2 |
org.apache.http.message.BasicLineParser | DEBUG | The value of ok after
last if is : ^_<U+008B>^H^@^@^@^@^@^@^@^C^@^@^@^@^@^@^@^@^@HT
TP/1.1 204 No Content the cursor is: [0>0>43] the protname is: HTTP the
index is: 0 and ok is: false
Sun Jul 13 00:51:06.141 PDT 2014 | "ajp-bio-8009"-exec-2 |
org.apache.http.impl.conn.DefaultHttpResponseParser | DEBUG | Garbage in
response: ^_<U+008B>^H^@^@^@^@^@^@^@^C^@^@^@^@^@^@^@^@^@HTTP
/1.1 204 No Content


funny thing is we are not doing any weird just with the server settings we
are using apache server with a tomcat running behind.

I will dig deeper and let you know if there is an issue and really sorry if
this a false alarm.

Thank you.



On Sun, Jul 13, 2014 at 4:43 AM, Oleg Kalnichevski <olegk@apache.org> wrote:

> On Sat, 2014-07-12 at 08:18 -0700, srikalyan swayampakula wrote:
> > Hi,
> >
> > I am getting a ClientProtocolException for a delete request. The response
> > is "204 No Content" and seems to be a bug in httpclient.
> >
> > I am creating the transport like this
> >
> > transport = new ApacheHttpTransport();
> >
> >        final RequestConfig defaultRequestConfig = RequestConfig.DEFAULT;
> >
> >        final RegistryBuilder<ConnectionSocketFactory> builder =
> >                 RegistryBuilder.<ConnectionSocketFactory>create()
> >                                .register("http",
> > PlainConnectionSocketFactory.getSocketFactory());
> >
> >        // allow a customized SSLConnectionSocketFactory to be used
> >        if (this.sslConnectionSocketFactory != null) {
> >           builder.register("https", this.sslConnectionSocketFactory);
> >        } else {
> >           builder.register("https",
> > SSLConnectionSocketFactory.getSocketFactory());
> >        }
> >
> >        final Registry<ConnectionSocketFactory> registry =
> builder.build();
> >
> >        final PoolingHttpClientConnectionManager cm =
> >           new PoolingHttpClientConnectionManager(registry);
> >
> >        // Increase max total connection
> >        cm.setMaxTotal(this.maxConnections);
> >        // Increase default max connection per route
> >        cm.setDefaultMaxPerRoute(this.maxConnections);
> >        //close expired connections
> >        cm.closeExpiredConnections();
> >
> >
> >
> >        final HttpClient client = HttpClientBuilder.create()
> >
> .setConnectionManager(cm)
> >
> > .setDefaultRequestConfig(defaultRequestConfig)
> >
> > .setMaxConnPerRoute(this.maxConnections)
> >
> > .setConnectionReuseStrategy(
> >
> >  DefaultConnectionReuseStrategy.INSTANCE)
> >                                                   .build();
> >
> >        transport.setClient(client);
> >        transport.setServerUrl(serverUrl);
> >        transport.setUsername(username);
> >        transport.setPassword(password);
> >        transport.setBasicAuth(hasText(username) || hasText(password));
> >
> >        return transport;
> >
> > and calling transport.delete(httpparams) and the server it is trying to
> > call seem to be fine no stack trace and access log seems behave as
> expected.
> >
> >  I enabled some debug logging which is indicating that there might be a
> bug
> > with the library
> >
>
> Please reproduce the problem outside the servlet container and post the
> _complete_ wire / context of the session to this list
>
> http://hc.apache.org/httpcomponents-client-4.3.x/logging.html
>
> Oleg
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>


-- 

-SK.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message