1 10 11 package org.mule.providers.http; 12 13 import org.mule.config.i18n.Message; 14 import org.mule.config.i18n.Messages; 15 import org.mule.providers.tcp.TcpConnector; 16 import org.mule.umo.UMOComponent; 17 import org.mule.umo.endpoint.UMOEndpoint; 18 import org.mule.umo.provider.UMOConnector; 19 import org.mule.umo.provider.UMOMessageReceiver; 20 21 import java.util.HashMap ; 22 import java.util.Iterator ; 23 import java.util.Map ; 24 25 44 45 public class HttpConnector extends TcpConnector 46 { 47 48 51 public static final String HTTP_STATUS_PROPERTY = "http.status"; 52 public static final String HTTP_VERSION_PROPERTY = "http.version"; 53 public static final String HTTP_CUSTOM_HEADERS_MAP_PROPERTY = "http.custom.headers"; 54 public static final String HTTP_METHOD_PROPERTY = "http.method"; 55 public static final String HTTP_REQUEST_PROPERTY = "http.request"; 56 public static final String HTTP_PARAMS = "http.params"; 57 public static final String HTTP_GET_BODY_PARAM_PROPERTY = "http.get.body.param"; 58 public static final String DEFAULT_HTTP_GET_BODY_PARAM_PROPERTY = "body"; 59 public static final String HTTP_POST_BODY_PARAM_PROPERTY = "http.post.body.param"; 60 61 public static final String HTTP_COOKIE_SPEC_PROPERTY = "cookieSpec"; 62 public static final String HTTP_COOKIES_PROPERTY = "cookies"; 63 public static final String HTTP_ENABLE_COOKIES_PROPERTY = "enableCookies"; 64 65 public static final String COOKIE_SPEC_NETSCAPE = "netscape"; 66 public static final String COOKIE_SPEC_RFC2109 = "rcf2109"; 67 68 private String proxyHostname = null; 69 70 private int proxyPort = HttpConstants.DEFAULT_HTTP_PORT; 71 72 private String proxyUsername = null; 73 74 private String proxyPassword = null; 75 76 private String cookieSpec; 77 78 private boolean enableCookies = false; 79 80 83 public UMOMessageReceiver registerListener(UMOComponent component, UMOEndpoint endpoint) throws Exception 84 { 85 if (endpoint != null) 86 { 87 Map endpointProperties = endpoint.getProperties(); 88 if (endpointProperties != null) 89 { 90 Map newProperties = new HashMap (endpointProperties.size()); 92 for (Iterator entries = endpointProperties.entrySet().iterator(); entries.hasNext();) 93 { 94 Map.Entry entry = (Map.Entry )entries.next(); 95 Object key = entry.getKey(); 96 Object normalizedKey = HttpConstants.ALL_HEADER_NAMES.get(key); 97 if (normalizedKey != null) 98 { 99 key = normalizedKey; 101 } 102 newProperties.put(key, entry.getValue()); 103 } 104 endpoint.setProperties(newProperties); 106 } 107 } 108 return super.registerListener(component, endpoint); 110 } 111 112 119 protected Object getReceiverKey(UMOComponent component, UMOEndpoint endpoint) 120 { 121 String key = endpoint.getEndpointURI().toString(); 122 int i = key.indexOf('?'); 123 if (i > -1) 124 { 125 key = key.substring(0, i); 126 } 127 return key; 128 } 129 130 133 public String getProtocol() 134 { 135 return "http"; 136 } 137 138 141 public String getProxyHostname() 142 { 143 return proxyHostname; 144 } 145 146 149 public String getProxyPassword() 150 { 151 return proxyPassword; 152 } 153 154 157 public int getProxyPort() 158 { 159 return proxyPort; 160 } 161 162 165 public String getProxyUsername() 166 { 167 return proxyUsername; 168 } 169 170 173 public void setProxyHostname(String host) 174 { 175 proxyHostname = host; 176 } 177 178 181 public void setProxyPassword(String string) 182 { 183 proxyPassword = string; 184 } 185 186 189 public void setProxyPort(int port) 190 { 191 proxyPort = port; 192 } 193 194 197 public void setProxyUsername(String string) 198 { 199 proxyUsername = string; 200 } 201 202 public Map getReceivers() 203 { 204 return this.receivers; 205 } 206 207 public String getCookieSpec() 208 { 209 return cookieSpec; 210 } 211 212 public void setCookieSpec(String cookieSpec) 213 { 214 if (!(cookieSpec.equalsIgnoreCase(COOKIE_SPEC_NETSCAPE) && cookieSpec.equalsIgnoreCase(COOKIE_SPEC_RFC2109))) 215 { 216 throw new IllegalArgumentException (new Message(Messages.PROPERTY_X_HAS_INVALID_VALUE_X, 217 "cookieSpec", cookieSpec).toString()); 218 } 219 this.cookieSpec = cookieSpec; 220 } 221 222 public boolean isEnableCookies() 223 { 224 return enableCookies; 225 } 226 227 public void setEnableCookies(boolean enableCookies) 228 { 229 this.enableCookies = enableCookies; 230 } 231 } 232 | Popular Tags |