You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by di...@apache.org on 2002/06/29 12:30:22 UTC
cvs commit: jakarta-commons/latka/src/java/org/apache/commons/latka/xml SuiteHandler.java RequestHandler.java
dion 2002/06/29 03:30:22
Modified: latka/src/java/org/apache/commons/latka/http
SessionImpl.java Session.java RequestImpl.java
latka/src/java/org/apache/commons/latka/xml
SuiteHandler.java RequestHandler.java
Log:
Added proxy handling
Revision Changes Path
1.12 +57 -10 jakarta-commons/latka/src/java/org/apache/commons/latka/http/SessionImpl.java
Index: SessionImpl.java
===================================================================
RCS file: /home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/http/SessionImpl.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- SessionImpl.java 11 Apr 2002 13:40:47 -0000 1.11
+++ SessionImpl.java 29 Jun 2002 10:30:21 -0000 1.12
@@ -66,10 +66,13 @@
import org.apache.commons.httpclient.HttpState;
import org.apache.commons.httpclient.Cookie;
+import org.apache.commons.latka.http.Proxy;
/**
* An implementation of a Latka Session interface based on the Jakarta Commons HttpClient package.
*
+ * @todo accept proxy details on create request
+ * @todo fix interface to match proxy details
* @author <a href="mailto:dsale@us.britannica.com">Doug Sale</a>
* @author <a href="mailto:mdelagra@us.britannica.com">Morgan Delagrange</a>
* @author dIon Gillard
@@ -104,7 +107,8 @@
* @see org.apache.commons.latka.http.Request#HTTP_METHOD_POST
*/
public Request createRequest(URL url, int httpMethod) {
- return createRequest(null,url,httpMethod,true);
+ // default label to null, follow redirects to true and proxy to null
+ return createRequest(null, url, httpMethod, true, null);
}
/**
@@ -120,18 +124,61 @@
*/
public Request createRequest(String label, URL url,
int httpMethod, boolean followRedirects) {
+ // default proxy to null
+ return createRequest(label, url, httpMethod, followRedirects, null);
+ }
- RequestImpl request =
- new RequestImpl(label,url, httpMethod, _state, this, followRedirects);
+ /**
+ * Creates a request object with the specified URL and HTTP Method to be
+ * accessed via the provided proxy
+ *
+ * @param url The URL to request of the HTTP server.
+ * @param httpMethod An integer representing the HTTP method (e.g. GET, PUT)
+ * used to communicate with server.
+ * @return a new {@link Request} object representing the <code>url</code> and
+ * <code>httpMethod</code>
+ * @param proxy a proxy to use during the request
+ * @see org.apache.commons.latka.http.Request#HTTP_METHOD_GET
+ * @see org.apache.commons.latka.http.Request#HTTP_METHOD_POST
+ * @see org.apache.commons.latka.http.Proxy
+ */
+ public Request createRequest(URL url, int httpMethod, Proxy proxy) {
+ // default label to null, and follow redirects to true
+ return createRequest(null, url, httpMethod, true, proxy);
+ }
- URL referer = getReferer();
+ /** Create a request with the given label, to access the given URL via the
+ * given HTTP method, and follow redirects as specified, using the given
+ * proxy for communications
+ *
+ * @param label a name used to identify the request
+ * @param url The URL to request of the HTTP server.
+ * @param httpMethod An integer representing the HTTP method (e.g. GET, PUT)
+ * used to communicate with server.
+ * @param followRedirects whether to follow HTTP redirection responses
+ * @param proxy a proxy to use during the request
+ * @return a new {@link Request} object representing the <code>url</code> and
+ * <code>httpMethod</code>
+ * @see org.apache.commons.latka.http.Request#HTTP_METHOD_GET
+ * @see org.apache.commons.latka.http.Request#HTTP_METHOD_POST
+ * @see org.apache.commons.latka.http.Proxy
+ */
+ public Request createRequest(String label, URL url, int httpMethod,
+ boolean followRedirects, Proxy proxy) {
+
+ RequestImpl request =
+ new RequestImpl(label,url, httpMethod, _state, this, followRedirects);
+ request.setProxy(proxy);
+
+ URL referer = getReferer();
+
+ if (referer != null) {
+ request.addHeader("Referer", referer.toString());
+ }
- if (referer != null) {
- request.addHeader("Referer", referer.toString());
- }
+ return request;
- return request;
- }
+ }
/**
* Called inside the request.execute() method, setting the
1.9 +64 -16 jakarta-commons/latka/src/java/org/apache/commons/latka/http/Session.java
Index: Session.java
===================================================================
RCS file: /home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/http/Session.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Session.java 11 Apr 2002 13:40:47 -0000 1.8
+++ Session.java 29 Jun 2002 10:30:21 -0000 1.9
@@ -74,21 +74,69 @@
*/
public interface Session {
- /**
- * Creates a request object with the specified URL and HTTP Method.
- *
- * @param url The URL to request of the HTTP server.
- * @param httpMethod An integer representing the HTTP method (e.g. GET, PUT)
- * used to communicate with server.
- * @return a new {@link Request} object representing the <code>url</code> and
- * <code>httpMethod</code>
- * @see org.apache.commons.latka.http.Request#HTTP_METHOD_GET
- * @see org.apache.commons.latka.http.Request#HTTP_METHOD_POST
- */
- public Request createRequest(URL url, int httpMethod);
-
- public Request createRequest(String label, URL url, int httpMethod,
- boolean followRedirects);
+ /**
+ * Creates a request object with the specified URL and HTTP Method.
+ *
+ * @param url The URL to request of the HTTP server.
+ * @param httpMethod An integer representing the HTTP method (e.g. GET, PUT)
+ * used to communicate with server.
+ * @return a new {@link Request} object representing the <code>url</code> and
+ * <code>httpMethod</code>
+ * @see org.apache.commons.latka.http.Request#HTTP_METHOD_GET
+ * @see org.apache.commons.latka.http.Request#HTTP_METHOD_POST
+ */
+ public Request createRequest(URL url, int httpMethod);
+
+ /** Create a request with the given label, to access the given URL via the
+ * given HTTP method, and follow redirects as specified.
+ *
+ * @param label a name used to identify the request
+ * @param url The URL to request of the HTTP server.
+ * @param httpMethod An integer representing the HTTP method (e.g. GET, PUT)
+ * used to communicate with server.
+ * @param followRedirects whether to follow HTTP redirection responses
+ * @return a new {@link Request} object representing the <code>url</code> and
+ * <code>httpMethod</code>
+ * @see org.apache.commons.latka.http.Request#HTTP_METHOD_GET
+ * @see org.apache.commons.latka.http.Request#HTTP_METHOD_POST
+ */
+ public Request createRequest(String label, URL url, int httpMethod,
+ boolean followRedirects);
+
+ /**
+ * Creates a request object with the specified URL and HTTP Method to be
+ * accessed via the provided proxy
+ *
+ * @param url The URL to request of the HTTP server.
+ * @param httpMethod An integer representing the HTTP method (e.g. GET, PUT)
+ * used to communicate with server.
+ * @return a new {@link Request} object representing the <code>url</code> and
+ * <code>httpMethod</code>
+ * @param proxy a proxy to use during the request
+ * @see org.apache.commons.latka.http.Request#HTTP_METHOD_GET
+ * @see org.apache.commons.latka.http.Request#HTTP_METHOD_POST
+ * @see org.apache.commons.latka.http.Proxy
+ */
+ public Request createRequest(URL url, int httpMethod, Proxy proxy);
+
+ /** Create a request with the given label, to access the given URL via the
+ * given HTTP method, and follow redirects as specified, using the given
+ * proxy for communications
+ *
+ * @param label a name used to identify the request
+ * @param url The URL to request of the HTTP server.
+ * @param httpMethod An integer representing the HTTP method (e.g. GET, PUT)
+ * used to communicate with server.
+ * @param followRedirects whether to follow HTTP redirection responses
+ * @param proxy a proxy to use during the request
+ * @return a new {@link Request} object representing the <code>url</code> and
+ * <code>httpMethod</code>
+ * @see org.apache.commons.latka.http.Request#HTTP_METHOD_GET
+ * @see org.apache.commons.latka.http.Request#HTTP_METHOD_POST
+ * @see org.apache.commons.latka.http.Proxy
+ */
+ public Request createRequest(String label, URL url, int httpMethod,
+ boolean followRedirects, Proxy proxy);
/**
* Adds a cookie to all HTTP requests whose domain and path match (according to RFC2109).
1.21 +25 -3 jakarta-commons/latka/src/java/org/apache/commons/latka/http/RequestImpl.java
Index: RequestImpl.java
===================================================================
RCS file: /home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/http/RequestImpl.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- RequestImpl.java 13 Apr 2002 00:53:32 -0000 1.20
+++ RequestImpl.java 29 Jun 2002 10:30:21 -0000 1.21
@@ -120,6 +120,8 @@
protected boolean _followRedirects = true;
/** object used to perform the http requests */
protected HttpClient _httpClient = new HttpClient();
+ /** proxy used to perform the requests */
+ private Proxy _proxy;
/** log4j category used when logging messages */
protected static final Category _log =
Category.getInstance(RequestImpl.class);
@@ -442,8 +444,13 @@
_host = host;
_port = port;
- // start session
- _httpClient.startSession(url);
+ if (getProxy() == null) {
+ // start session
+ _httpClient.startSession(host, port, port == HTTPS_PORT);
+ } else {
+ _httpClient.startSession(host, port, getProxy().getHost(),
+ getProxy().getPort());
+ }
_log.debug("connection open");
@@ -477,4 +484,19 @@
public int getMethod() {
return _method;
}
+
+ /** Getter for property pproxy.
+ * @return Value of property proxy.
+ */
+ public Proxy getProxy() {
+ return _proxy;
+ }
+
+ /** Setter for property proxy.
+ * @param _proxy New value of property proxy.
+ */
+ public void setProxy(Proxy proxy) {
+ _proxy = proxy;
+ }
+
}
1.25 +23 -17 jakarta-commons/latka/src/java/org/apache/commons/latka/xml/SuiteHandler.java
Index: SuiteHandler.java
===================================================================
RCS file: /home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/xml/SuiteHandler.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- SuiteHandler.java 29 Apr 2002 18:20:21 -0000 1.24
+++ SuiteHandler.java 29 Jun 2002 10:30:21 -0000 1.25
@@ -121,22 +121,14 @@
if (localName.equals("suite")) {
Properties props = LatkaProperties.getProperties();
-
- String defaultHost = atts.getValue("defaultHost");
- if (defaultHost != null) {
- props.setProperty("latka.defaultHost", defaultHost);
- } else {
- // clear this property, so that its value is not
- // leaked from a previous invocation
- props.remove("latka.defaultHost");
- }
-
- String portString = atts.getValue("defaultPort");
- if (portString != null) {
- props.setProperty("latka.defaultPort", portString);
- } else {
- props.remove("latka.defaultPort");
- }
+ addPropertyFromAttribute(atts.getValue("defaultHost"),
+ "latka.defaultHost", props);
+ addPropertyFromAttribute(atts.getValue("defaultPort"),
+ "latka.defaultPort", props);
+ addPropertyFromAttribute(atts.getValue("defaultProxyHost"),
+ "latka.defaultProxyHost", props);
+ addPropertyFromAttribute(atts.getValue("proxyPort"),
+ "latka.defaultProxyPort", props);
} else if (localName.equals("reportMessage")) {
@@ -175,4 +167,18 @@
}
}
+ /**
+ * Check for a suite attribute and add as a latka property
+ * @param attributeValue the value of the suite attribute
+ * @param propertyName the latka property to set with the new value
+ * @param props the LatkaProperties to update
+ */
+ private void addPropertyFromAttribute(String attributeValue,
+ String propertyName, Properties props) {
+ if (attributeValue != null) {
+ props.setProperty(propertyName, attributeValue);
+ } else {
+ props.remove(propertyName);
+ }
+ }
}
1.23 +254 -227 jakarta-commons/latka/src/java/org/apache/commons/latka/xml/RequestHandler.java
Index: RequestHandler.java
===================================================================
RCS file: /home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/xml/RequestHandler.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- RequestHandler.java 11 Apr 2002 13:51:14 -0000 1.22
+++ RequestHandler.java 29 Jun 2002 10:30:21 -0000 1.23
@@ -76,6 +76,7 @@
import org.apache.commons.latka.http.Credentials;
import org.apache.commons.latka.http.CredentialsImpl;
+import org.apache.commons.latka.http.Proxy;
import org.apache.commons.latka.http.Request;
import org.apache.commons.latka.http.Response;
import org.apache.commons.latka.http.Session;
@@ -94,238 +95,264 @@
* @version $Id$
*/
public class RequestHandler extends LatkaHandler {
- protected LatkaEventInfo _listener = null;
+ protected LatkaEventInfo _listener = null;
- protected Session _session = null;
- protected String _defaultHost = null;
- protected int _defaultPort = -1;
-
- protected boolean _skipped = false;
-
- protected Request _request = null;
- protected Response _response = null;
- protected boolean _requestExecuted = false;
- protected Credentials _credentials = null;
-
- protected List _visitedURLs = new LinkedList();
-
- protected static final Category _log =
- Category.getInstance(RequestHandler.class);
-
- public RequestHandler(XMLReader reader, Session session,
- LatkaEventInfo listener)
- {
- super(reader);
- _session = session;
- _listener = listener;
- _skipped = false;
+ protected Session _session = null;
+ protected String _defaultHost = null;
+ protected int _defaultPort = -1;
+ private String _defaultProxyHost = null;
+ private int _defaultProxyPort = -1;
+ private Proxy _proxy;
+
+ protected boolean _skipped = false;
+
+ protected Request _request = null;
+ protected Response _response = null;
+ protected boolean _requestExecuted = false;
+ protected Credentials _credentials = null;
+
+ protected List _visitedURLs = new LinkedList();
+
+ protected static final Category _log =
+ Category.getInstance(RequestHandler.class);
+
+ public RequestHandler(XMLReader reader, Session session,
+ LatkaEventInfo listener) {
+ super(reader);
+ _session = session;
+ _listener = listener;
+ _skipped = false;
- Properties props = LatkaProperties.getProperties();
- _defaultHost = props.getProperty("latka.defaultHost");
- String portString = props.getProperty("latka.defaultPort");
- if (portString != null) {
- _defaultPort = Integer.parseInt(portString);
- }
-
- _log.debug("request handler instantiated");
- }
-
- public RequestHandler(XMLReader reader,
- Session session,
- LatkaEventInfo listener,
- boolean skip)
- {
- this(reader, session, listener);
- _skipped = skip;
- }
-
- public void startElement(String uri, String localName,
- String qName, Attributes atts)
- throws SAXException {
-
- _log.debug("received start element event");
-
- if (_listener.didRequestSucceed(_request) == false) {
- // if a test in this request has already failed,
- // do nothing
- return;
+ Properties props = LatkaProperties.getProperties();
+ _defaultHost = props.getProperty("latka.defaultHost");
+ String portString = props.getProperty("latka.defaultPort");
+ if (portString != null) {
+ _defaultPort = Integer.parseInt(portString);
+ }
+ _defaultProxyHost = props.getProperty("latka.defaultProxyHost");
+ String proxyPortString = props.getProperty("latka.defaultProxyPort");
+ if (proxyPortString != null) {
+ _defaultProxyPort = Integer.parseInt(proxyPortString);
+ }
+
+ _log.debug("request handler instantiated");
}
- if (localName.equals("request")) {
+ public RequestHandler(XMLReader reader, Session session,
+ LatkaEventInfo listener, boolean skip) {
+ this(reader, session, listener);
+ _skipped = skip;
+ }
+
+ public void startElement(String uri, String localName, String qName,
+ Attributes atts) throws SAXException {
+
+ _log.debug("received start element event");
+
+ if (_listener.didRequestSucceed(_request) == false) {
+ // if a test in this request has already failed,
+ // do nothing
+ return;
+ }
+
+ if (localName.equals("request")) {
- try {
- _request = buildRequest(atts);
- } catch (MalformedURLException e) {
- // error out completely for malformed URLs
- throw new SAXException(e);
- }
-
- if (_skipped) {
- _listener.requestSkipped(new RequestSkippedEvent(_request, null));
- _log.info("request skipped");
- }
- } else if (localName.equals("credentials")) {
- _credentials = new CredentialsImpl(atts.getValue("userName"),
- atts.getValue("password"));
- _request.setCredentials(_credentials);
- } else if (localName.equals("requestHeader")) {
- _log.info("adding request headers");
- RequestHeaderHandler headerHandler = new RequestHeaderHandler(_reader,
- _request);
- headerHandler.delegate(uri, localName, qName, atts);
- } else if (localName.equals("param")) {
- _log.info("adding parameters: params should follow");
- ParameterHandler paramHandler = new ParameterHandler(_reader,_request);
- paramHandler.delegate(uri, localName, qName, atts);
- return;
- } else if (localName.equals("validate")) {
-
- _log.info("encountered validations");
-
- if (!_skipped) {
- try {
- _response = executeRequest();
- _log.debug("request executed and response obtained");
- ValidationReflectionHandler handler =
- new ValidationReflectionHandler(_reader, _response, _listener);
- handler.delegate(uri, localName, qName, atts);
- } catch (IOException e) {
- _listener.requestError(new RequestErrorEvent(_request, _response, e));
- }
- _requestExecuted = true;
- }
-
- }
-
- }
-
- public void endElement(String namespaceURI, String localName,
- String rawName)
- throws SAXException {
- if (localName.equals("request")) {
- if (_requestExecuted == false && !_skipped) {
- try {
- executeRequest();
- _listener.requestSucceeded(new RequestSucceededEvent(_request,
- _response));
- } catch (IOException e) {
- _listener.requestError(new RequestErrorEvent(_request, _response, e));
- }
- } else if (_listener.didRequestSucceed(_request) == true) {
- // broadcast official notification of success
- _listener.requestSucceeded(new RequestSucceededEvent(_request,
- _response));
- }
-
- release();
- }
- }
-
-
- /**
- * Executes the request. In the event of a 301 or 302,
- * this method may reassign the _request variable to
- * a different value.
- */
- protected Response executeRequest() throws IOException {
- Response response = _request.execute();
-
- if (_request.followRedirects() == false) {
- return response;
- }
-
- // execute the request until either we get a non-redirect response, or
- // we visit a URL we have already visited
- while (response.getStatusCode() == 301 || response.getStatusCode() == 302) {
- // follow the redirect
- URL url = new URL(response.getHeader("location"));
+ try {
+ _request = buildRequest(atts);
+ } catch (MalformedURLException e) {
+ // error out completely for malformed URLs
+ throw new SAXException(e);
+ }
+
+ if (_skipped) {
+ _listener.requestSkipped(new RequestSkippedEvent(_request, null));
+ _log.info("request skipped");
+ }
+ } else if (localName.equals("credentials")) {
+ _credentials = new CredentialsImpl(atts.getValue("userName"),
+ atts.getValue("password"));
+ _request.setCredentials(_credentials);
+ } else if (localName.equals("requestHeader")) {
+ _log.info("adding request headers");
+ RequestHeaderHandler headerHandler = new RequestHeaderHandler(
+ _reader, _request);
+ headerHandler.delegate(uri, localName, qName, atts);
+ } else if (localName.equals("param")) {
+ _log.info("adding parameters: params should follow");
+ ParameterHandler paramHandler = new ParameterHandler(_reader,_request);
+ paramHandler.delegate(uri, localName, qName, atts);
+ return;
+ } else if (localName.equals("validate")) {
+ _log.info("encountered validations");
+
+ if (!_skipped) {
+ try {
+ _response = executeRequest();
+ _log.debug("request executed and response obtained");
+ ValidationReflectionHandler handler =
+ new ValidationReflectionHandler(_reader, _response,
+ _listener);
+ handler.delegate(uri, localName, qName, atts);
+ } catch (IOException e) {
+ _listener.requestError(new RequestErrorEvent(_request, _response, e));
+ }
+ _requestExecuted = true;
+ }
+
+ }
+
+ }
+
+ public void endElement(String namespaceURI, String localName,
+ String rawName) throws SAXException {
+ if (localName.equals("request")) {
+ if (_requestExecuted == false && !_skipped) {
+ try {
+ executeRequest();
+ _listener.requestSucceeded(new RequestSucceededEvent(
+ _request, _response));
+ } catch (IOException e) {
+ _listener.requestError(new RequestErrorEvent(_request, _response, e));
+ }
+ } else if (_listener.didRequestSucceed(_request) == true) {
+ // broadcast official notification of success
+ _listener.requestSucceeded(new RequestSucceededEvent(_request,
+ _response));
+ }
+
+ release();
+ }
+ }
+
+
+ /**
+ * Executes the request. In the event of a 301 or 302,
+ * this method may reassign the _request variable to
+ * a different value.
+ */
+ protected Response executeRequest() throws IOException {
+ Response response = _request.execute();
+
+ if (_request.followRedirects() == false) {
+ return response;
+ }
+
+ // execute the request until either we get a non-redirect response, or
+ // we visit a URL we have already visited
+ while (response.getStatusCode() == 301 || response.getStatusCode() == 302) {
+ // follow the redirect
+ URL url = new URL(response.getHeader("location"));
+
+ if (_visitedURLs.contains(url.toString())) {
+ return response;
+ }
+
+ Request request = _session.createRequest(_request.getLabel(), url,
+ _request.getMethod(), true, getProxy());
+ request.setParameters(_request.getParameters());
+ request.setHeaders(_request.getHeaders());
+ if (_credentials != null) {
+ request.setCredentials(_credentials);
+ }
+ _request = request;
+ response = _request.execute();
+ _visitedURLs.add(url.toString());
+ }
- if (_visitedURLs.contains(url.toString())) {
return response;
- }
+ }
- Request request = _session.createRequest(_request.getLabel(),
- url,
- _request.getMethod(),
- true);
- request.setParameters(_request.getParameters());
- request.setHeaders(_request.getHeaders());
- if (_credentials != null) {
- request.setCredentials(_credentials);
- }
- _request = request;
- response = _request.execute();
- _visitedURLs.add(url.toString());
- }
-
- return response;
- }
-
- protected Request buildRequest(Attributes atts)
- throws MalformedURLException {
-
- String host = atts.getValue("host");
- if (host == null) {
- host = _defaultHost;
- }
-
- String path = atts.getValue("path");
-
- boolean secure = false;
- String secureStr = atts.getValue("secure");
- if (null == secureStr) {
- secure = false;
- } else if ("true".equalsIgnoreCase(secureStr)) {
- secure = true;
- } else {
- secure = false;
- }
-
- String portString = atts.getValue("port");
- int port = _defaultPort;
- if (portString != null) {
- port = Integer.parseInt(portString);
- }
-
-
- URL url = new URL(secure ? "https" : "http", host, port, path);
-
- String methodString = atts.getValue("method");
- int method = -1;
- if (methodString == null) {
- method = Request.HTTP_METHOD_GET;
- } else if (methodString.equalsIgnoreCase("post")) {
- method = Request.HTTP_METHOD_POST;
- } else if (methodString.equalsIgnoreCase("head")) {
- method = Request.HTTP_METHOD_HEAD;
- } else {
- method = Request.HTTP_METHOD_GET;
- }
-
- String label = atts.getValue("label");
- _log.info("creating request with label:");
- _log.info(label);
-
- boolean followRedirects = true;
- String followRedirectStr = atts.getValue("followRedirects");
- if (null == followRedirectStr) {
- followRedirects = true;
- } else if ("true".equalsIgnoreCase(followRedirectStr)) {
- followRedirects = true;
- } else {
- followRedirects = false;
- }
-
-
- return _session.createRequest(label, url, method, followRedirects);
- }
-
- protected void printFailure(Request req, Exception e) {
- StringBuffer buf = new StringBuffer();
- buf.append("REQUEST FAILED for URL ");
- buf.append(_request.getURL());
- buf.append(": ");
- buf.append(e);
- System.out.println(buf.toString());
- }
+ protected Request buildRequest(Attributes atts) throws MalformedURLException {
+
+ String host = atts.getValue("host");
+ if (host == null) {
+ host = _defaultHost;
+ }
+
+ String proxyHost = atts.getValue("proxyHost");
+ if (proxyHost == null) {
+ proxyHost = _defaultProxyHost;
+ }
+
+ if (proxyHost != null) {
+ String proxyPortString = atts.getValue("proxyPort");
+ int proxyPort = _defaultProxyPort;
+ if (proxyPortString != null) {
+ proxyPort = Integer.parseInt(proxyPortString);
+ }
+
+ setProxy(new Proxy(proxyHost, proxyPort));
+ }
+
+ String path = atts.getValue("path");
+
+ boolean secure = false;
+ String secureStr = atts.getValue("secure");
+ if (null == secureStr) {
+ secure = false;
+ } else if ("true".equalsIgnoreCase(secureStr)) {
+ secure = true;
+ } else {
+ secure = false;
+ }
+
+ String portString = atts.getValue("port");
+ int port = _defaultPort;
+ if (portString != null) {
+ port = Integer.parseInt(portString);
+ }
+
+ URL url = new URL(secure ? "https" : "http", host, port, path);
+
+ String methodString = atts.getValue("method");
+ int method = -1;
+ if (methodString == null) {
+ method = Request.HTTP_METHOD_GET;
+ } else if (methodString.equalsIgnoreCase("post")) {
+ method = Request.HTTP_METHOD_POST;
+ } else if (methodString.equalsIgnoreCase("head")) {
+ method = Request.HTTP_METHOD_HEAD;
+ } else {
+ method = Request.HTTP_METHOD_GET;
+ }
+
+ String label = atts.getValue("label");
+ _log.info("creating request with label:");
+ _log.info(label);
+
+ boolean followRedirects = true;
+ String followRedirectStr = atts.getValue("followRedirects");
+ if (null == followRedirectStr) {
+ followRedirects = true;
+ } else if ("true".equalsIgnoreCase(followRedirectStr)) {
+ followRedirects = true;
+ } else {
+ followRedirects = false;
+ }
+
+ return _session.createRequest(label, url, method, followRedirects,
+ getProxy());
+ }
+
+ protected void printFailure(Request req, Exception e) {
+ StringBuffer buf = new StringBuffer();
+ buf.append("REQUEST FAILED for URL ").append(_request.getURL())
+ .append(": ").append(e);
+ System.out.println(buf.toString());
+ }
+
+ /** Getter for property proxy.
+ * @return Value of property proxy.
+ */
+ private Proxy getProxy() {
+ return _proxy;
+ }
+
+ /** Setter for property proxy.
+ * @param proxy New value of property proxy.
+ */
+ private void setProxy(Proxy proxy) {
+ _proxy = proxy;
+ }
+
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>