org.apache.maven.wagon.providers.webdav.HttpMethodConfiguration Maven / Gradle / Ivy
package org.apache.maven.wagon.providers.webdav;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.params.HttpMethodParams;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
*
*/
public class HttpMethodConfiguration
{
public static final int DEFAULT_CONNECTION_TIMEOUT = 60000;
private static final String COERCE_PATTERN = "%(\\w+),(.+)";
private Boolean useDefaultHeaders;
private Properties headers = new Properties();
private Properties params = new Properties();
private int connectionTimeout = DEFAULT_CONNECTION_TIMEOUT;
public boolean isUseDefaultHeaders()
{
return useDefaultHeaders == null ? true : useDefaultHeaders.booleanValue();
}
public HttpMethodConfiguration setUseDefaultHeaders( boolean useDefaultHeaders )
{
this.useDefaultHeaders = Boolean.valueOf( useDefaultHeaders );
return this;
}
public Boolean getUseDefaultHeaders()
{
return useDefaultHeaders;
}
public HttpMethodConfiguration addHeader( String header, String value )
{
headers.setProperty( header, value );
return this;
}
public Properties getHeaders()
{
return headers;
}
public HttpMethodConfiguration setHeaders( Properties headers )
{
this.headers = headers;
return this;
}
public HttpMethodConfiguration addParam( String param, String value )
{
params.setProperty( param, value );
return this;
}
public Properties getParams()
{
return params;
}
public HttpMethodConfiguration setParams( Properties params )
{
this.params = params;
return this;
}
public int getConnectionTimeout()
{
return connectionTimeout;
}
public HttpMethodConfiguration setConnectionTimeout( int connectionTimeout )
{
this.connectionTimeout = connectionTimeout;
return this;
}
public HttpMethodParams asMethodParams( HttpMethodParams defaults )
{
if ( !hasParams() )
{
return null;
}
HttpMethodParams p = new HttpMethodParams();
p.setDefaults( defaults );
fillParams( p );
return p;
}
private boolean hasParams()
{
if ( connectionTimeout < 1 && params == null )
{
return false;
}
return true;
}
private void fillParams( HttpMethodParams p )
{
if ( !hasParams() )
{
return;
}
if ( connectionTimeout > 0 )
{
p.setSoTimeout( connectionTimeout );
}
if ( params != null )
{
Pattern coercePattern = Pattern.compile( COERCE_PATTERN );
for ( Map.Entry
© 2015 - 2025 Weber Informatics LLC | Privacy Policy