001package org.apache.maven.wagon.providers.http; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.util.Map; 023import java.util.Properties; 024 025import org.apache.http.Header; 026import org.apache.http.message.BasicHeader; 027import org.apache.maven.wagon.Wagon; 028 029public class HttpMethodConfiguration 030{ 031 032 private Boolean useDefaultHeaders; 033 034 private Properties headers = new Properties(); 035 036 private Properties params = new Properties(); 037 038 private int connectionTimeout = Wagon.DEFAULT_CONNECTION_TIMEOUT; 039 040 private int readTimeout = 041 Integer.parseInt( System.getProperty( "maven.wagon.rto", Integer.toString( Wagon.DEFAULT_READ_TIMEOUT ) ) ); 042 043 private boolean usePreemptive = false; 044 045 public boolean isUseDefaultHeaders() 046 { 047 return useDefaultHeaders == null || useDefaultHeaders.booleanValue(); 048 } 049 050 public HttpMethodConfiguration setUseDefaultHeaders( boolean useDefaultHeaders ) 051 { 052 this.useDefaultHeaders = Boolean.valueOf( useDefaultHeaders ); 053 return this; 054 } 055 056 public Boolean getUseDefaultHeaders() 057 { 058 return useDefaultHeaders; 059 } 060 061 public HttpMethodConfiguration addHeader( String header, String value ) 062 { 063 headers.setProperty( header, value ); 064 return this; 065 } 066 067 public Properties getHeaders() 068 { 069 return headers; 070 } 071 072 public HttpMethodConfiguration setHeaders( Properties headers ) 073 { 074 this.headers = headers; 075 return this; 076 } 077 078 public HttpMethodConfiguration addParam( String param, String value ) 079 { 080 params.setProperty( param, value ); 081 return this; 082 } 083 084 public Properties getParams() 085 { 086 return params; 087 } 088 089 public HttpMethodConfiguration setParams( Properties params ) 090 { 091 this.params = params; 092 return this; 093 } 094 095 public int getConnectionTimeout() 096 { 097 return connectionTimeout; 098 } 099 100 public HttpMethodConfiguration setConnectionTimeout( int connectionTimeout ) 101 { 102 this.connectionTimeout = connectionTimeout; 103 return this; 104 } 105 106 public int getReadTimeout() 107 { 108 return readTimeout; 109 } 110 111 public HttpMethodConfiguration setReadTimeout( int readTimeout ) 112 { 113 this.readTimeout = readTimeout; 114 return this; 115 } 116 117 public boolean isUsePreemptive() 118 { 119 return usePreemptive; 120 } 121 122 public HttpMethodConfiguration setUsePreemptive( boolean usePreemptive ) 123 { 124 this.usePreemptive = usePreemptive; 125 return this; 126 } 127 128 public Header[] asRequestHeaders() 129 { 130 if ( headers == null ) 131 { 132 return new Header[0]; 133 } 134 135 Header[] result = new Header[headers.size()]; 136 137 int index = 0; 138 for ( Map.Entry entry : headers.entrySet() ) 139 { 140 String key = (String) entry.getKey(); 141 String value = (String) entry.getValue(); 142 143 Header header = new BasicHeader( key, value ); 144 result[index++] = header; 145 } 146 147 return result; 148 } 149 150 HttpMethodConfiguration copy() 151 { 152 HttpMethodConfiguration copy = new HttpMethodConfiguration(); 153 154 copy.setConnectionTimeout( getConnectionTimeout() ); 155 copy.setReadTimeout( getReadTimeout() ); 156 if ( getHeaders() != null ) 157 { 158 copy.setHeaders( getHeaders() ); 159 } 160 161 if ( getParams() != null ) 162 { 163 copy.setParams( getParams() ); 164 } 165 166 copy.setUseDefaultHeaders( isUseDefaultHeaders() ); 167 168 return copy; 169 } 170 171}