[ 
https://issues.apache.org/jira/browse/HTTPCORE-137?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12557427#action_12557427
 ] 

Ronald E Johnson commented on HTTPCORE-137:
-------------------------------------------

Actually after going through the HttpComponents core code base, it looks like 
the PUT requests are never handled.  In the file 
module-main/src/main/java/org/apache/http/impl/DefaultHttpRequestFactory.java 
the source code looks like:

    public HttpRequest newHttpRequest(final RequestLine requestline)
            throws MethodNotSupportedException {
        if (requestline == null) {
            throw new IllegalArgumentException("Request line may not be null");
        }
        String method = requestline.getMethod();
        if ("GET".equalsIgnoreCase(method)) {
            return new BasicHttpRequest(requestline); 
        } else if ("HEAD".equalsIgnoreCase(method)) {
            return new BasicHttpRequest(requestline); 
        } else if ("POST".equalsIgnoreCase(method)) {
            return new BasicHttpEntityEnclosingRequest(requestline); 
        } else { 
            throw new MethodNotSupportedException(method +  " method not 
supported");
        }
    }

Notice that "PUT" is never handled.  Which is why I've been getting a "501 
method not supported" message.  After changing the code to:

    public HttpRequest newHttpRequest(final RequestLine requestline)
            throws MethodNotSupportedException {
        if (requestline == null) {
            throw new IllegalArgumentException("Request line may not be null");
        }
        String method = requestline.getMethod();
        if ("GET".equalsIgnoreCase(method)) {
            return new BasicHttpRequest(requestline); 
        } else if ("HEAD".equalsIgnoreCase(method)) {
            return new BasicHttpRequest(requestline); 
        } else if ("PUT".equalsIgnoreCase(method)) {
            return new BasicHttpEntityEnclosingRequest(requestline); 
        } else if ("POST".equalsIgnoreCase(method)) {
            return new BasicHttpEntityEnclosingRequest(requestline); 
        } else { 
            throw new MethodNotSupportedException(method +  " method not 
supported");
        }
    }

I was able to process the PUT request...  Thanks for your patience.  I will 
update the test code and provided the modified DefaultHttpRequestFactory.java 
file.

> Problem handling HTTP PUT requests 
> -----------------------------------
>
>                 Key: HTTPCORE-137
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-137
>             Project: HttpComponents Core
>          Issue Type: Bug
>          Components: HttpCore NIO
>    Affects Versions: 4.0-rc1
>         Environment: Java JDK 1.6.0_03 on Windows XP Service Pack 2
>            Reporter: Ronald E Johnson
>
> I have a Java Swing application with an HttpServer() instance running in a 
> SwingWorker thread.  I'm able to get at the HTTP GET requests by casting the 
> request as follows:
> if (request instanceof HttpEntityEnclosingRequest)  {
>             HttpEntity entity = ((HttpEntityEnclosingRequest) 
> request).getEntity();
>             byte[] entityContent = EntityUtils.toByteArray(entity);
>             logger.info("Incoming entity content (bytes): " + 
> entityContent.length);
> }
> However this does not work for PUT requests. In fact printing out the request 
> line of a PUT request appears as: "HEAD /test.txt HTTP/1.1", and I don't see 
> PUT in the request line at all.  Attempting to cast this as an 
> HttpEntityEnclosingRequest fails, and thus I'm not able to get at the 
> HttpEntity.  Is this functionality supported?  

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to