camel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Christian Mueller (JIRA)" <j...@apache.org>
Subject [jira] Commented: (CAMEL-1530) Upgrade camel-http to use httpclient 4.0
Date Mon, 21 Dec 2009 22:17:54 GMT

    [ https://issues.apache.org/activemq/browse/CAMEL-1530?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=56587#action_56587
] 

Christian Mueller commented on CAMEL-1530:
------------------------------------------

My "solution" is the following:

{code}
public class HttpParamsBuilder {
    
    private Map<String, Object> clientHttpParams;
    
    public HttpParamsBuilder(Map<String, Object> clientHttpParams) {
        this.clientHttpParams = clientHttpParams;
    }

    /**
     * Build the HttpParams with the provided http parameter
     *
     * @param client the client
     */
    public HttpParams toHttpParams() {
        HttpParams httpParams = new BasicHttpParams();
        Object value = null;
        
        if (clientHttpParams == null || clientHttpParams.isEmpty()) {
            return httpParams;
        }
        
        if (null != (value = clientHttpParams.remove(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE)))
{
            httpParams.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(Integer.parseInt((String)
value)));
        }
        
        if (null != (value = clientHttpParams.remove(ConnManagerPNames.MAX_TOTAL_CONNECTIONS)))
{
            httpParams.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, Integer.parseInt((String)
value));
        }
        
        if (null != (value = clientHttpParams.remove(ConnManagerPNames.TIMEOUT))) {
            httpParams.setParameter(ConnManagerPNames.TIMEOUT, Long.parseLong((String) value));
        }
        
        if (null != (value = clientHttpParams.remove(CoreConnectionPNames.SO_TIMEOUT))) {
            httpParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, Integer.parseInt((String)
value));
        }
        
        if (null != (value = clientHttpParams.remove(CoreConnectionPNames.TCP_NODELAY))) {
            httpParams.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, Boolean.parseBoolean((String)
value));
        }
        
        if (null != (value = clientHttpParams.remove(CoreConnectionPNames.SOCKET_BUFFER_SIZE)))
{
            httpParams.setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, Integer.parseInt((String)
value));
        }
        
        if (null != (value = clientHttpParams.remove(CoreConnectionPNames.SO_LINGER))) {
            httpParams.setIntParameter(CoreConnectionPNames.SO_LINGER, Integer.parseInt((String)
value));
        }
        
        if (null != (value = clientHttpParams.remove(CoreConnectionPNames.CONNECTION_TIMEOUT)))
{
            httpParams.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, Integer.parseInt((String)
value));
        }
        
        if (null != (value = clientHttpParams.remove(CoreConnectionPNames.STALE_CONNECTION_CHECK)))
{
            httpParams.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, Boolean.parseBoolean((String)
value));
        }
        
        if (null != (value = clientHttpParams.remove(CoreConnectionPNames.MAX_LINE_LENGTH)))
{
            httpParams.setIntParameter(CoreConnectionPNames.MAX_LINE_LENGTH, Integer.parseInt((String)
value));
        }
        
        if (null != (value = clientHttpParams.remove(CoreConnectionPNames.MAX_HEADER_COUNT)))
{
            httpParams.setIntParameter(CoreConnectionPNames.MAX_HEADER_COUNT, Integer.parseInt((String)
value));
        }
        
        if (null != (value = clientHttpParams.remove(CoreProtocolPNames.PROTOCOL_VERSION)))
{
            if ("0.9".equals(value)) {
                httpParams.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_0_9);
            } else if ("1.0".equals(value)) {
                httpParams.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_0);
            } else if ("1.0".equals(value)) {
                httpParams.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
            } else {
                throw new IllegalArgumentException("'" + value + "' is not a valid value for
property '" + CoreProtocolPNames.PROTOCOL_VERSION + "'");
            }
        }
        
        if (null != (value = clientHttpParams.remove(CoreProtocolPNames.HTTP_ELEMENT_CHARSET)))
{
            httpParams.setParameter(CoreProtocolPNames.HTTP_ELEMENT_CHARSET, (String) value);
        }
        
        if (null != (value = clientHttpParams.remove(CoreProtocolPNames.HTTP_CONTENT_CHARSET)))
{
            httpParams.setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, (String) value);
        }
        
        if (null != (value = clientHttpParams.remove(CoreProtocolPNames.USER_AGENT))) {
            httpParams.setParameter(CoreProtocolPNames.USER_AGENT, (String) value);
        }
        
        if (null != (value = clientHttpParams.remove(CoreProtocolPNames.ORIGIN_SERVER))) {
            httpParams.setParameter(CoreProtocolPNames.ORIGIN_SERVER, (String) value);
        }
        
        if (null != (value = clientHttpParams.remove(CoreProtocolPNames.STRICT_TRANSFER_ENCODING)))
{
            httpParams.setBooleanParameter(CoreProtocolPNames.STRICT_TRANSFER_ENCODING, Boolean.parseBoolean((String)
value));
        }
        
        if (null != (value = clientHttpParams.remove(CoreProtocolPNames.USE_EXPECT_CONTINUE)))
{
            httpParams.setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, Boolean.parseBoolean((String)
value));
        }
        
        if (null != (value = clientHttpParams.remove(CoreProtocolPNames.WAIT_FOR_CONTINUE)))
{
            httpParams.setIntParameter(CoreProtocolPNames.WAIT_FOR_CONTINUE, Integer.parseInt((String)
value));
        }
        
        // TODO: configure ClientPNames, AuthPNames, CookieSpecPNames, ConnConnectionPNames,
ConnRoutePNames
        
        
        if (!clientHttpParams.isEmpty()) {
            throw new IllegalArgumentException("Unknown parameters=[" + clientHttpParams +
"]");
        }
        
        return httpParams;
    }
}
{code}

I'm not really happy with that, but I didn't have a better idea... :-(

Christian

> Upgrade camel-http to use httpclient 4.0
> ----------------------------------------
>
>                 Key: CAMEL-1530
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-1530
>             Project: Apache Camel
>          Issue Type: Improvement
>          Components: camel-http
>    Affects Versions: 2.0-M1
>            Reporter: Claus Ibsen
>            Assignee: Christian Mueller
>             Fix For: 2.2.0
>
>
> Upgrading httpclient from 3.1 to 4.0 requires changes in the camel-http code as the API
has change quite a lot.

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


Mime
View raw message