dion 02/04/11 06:40:48
Modified: latka/src/java/org/apache/commons/latka/http
SessionImpl.java RequestHeadersImpl.java
ParametersImpl.java Credentials.java
RequestHeaders.java RequestImpl.java
CredentialsImpl.java Response.java Session.java
Parameters.java Request.java ResponseImpl.java
Log:
Fixed license
Revision Changes Path
1.11 +12 -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.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- SessionImpl.java 2 Feb 2002 13:21:41 -0000 1.10
+++ SessionImpl.java 11 Apr 2002 13:40:47 -0000 1.11
@@ -1,9 +1,13 @@
/*
+ *
+ *
+ *
+ *
* ====================================================================
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -11,7 +15,7 @@
* are met:
*
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
@@ -19,15 +23,15 @@
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
- * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
+ * from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
@@ -53,9 +57,7 @@
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
- * [Additional notices, if required by prior licensing conditions]
- *
- */
+ */
package org.apache.commons.latka.http;
@@ -71,7 +73,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Doug Sale</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Morgan Delagrange</a>
* @author dIon Gillard
- * @version $Id: SessionImpl.java,v 1.10 2002/02/02 13:21:41 dion Exp $
+ * @version $Id: SessionImpl.java,v 1.11 2002/04/11 13:40:47 dion Exp $
*/
public class SessionImpl implements Session {
1.4 +3 -4
jakarta-commons/latka/src/java/org/apache/commons/latka/http/RequestHeadersImpl.java
Index: RequestHeadersImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/http/RequestHeadersImpl.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- RequestHeadersImpl.java 11 Apr 2002 02:34:53 -0000 1.3
+++ RequestHeadersImpl.java 11 Apr 2002 13:40:47 -0000 1.4
@@ -7,7 +7,7 @@
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -57,9 +57,8 @@
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
- * [Additional notices, if required by prior licensing conditions]
- *
*/
+
package org.apache.commons.latka.http;
import java.util.LinkedList;
@@ -71,7 +70,7 @@
*
* @author Morgran Delagrange
* @author dIon Gillard
- * @version $Id: RequestHeadersImpl.java,v 1.3 2002/04/11 02:34:53 dion Exp $
+ * @version $Id: RequestHeadersImpl.java,v 1.4 2002/04/11 13:40:47 dion Exp $
*/
public class RequestHeadersImpl implements RequestHeaders {
1.4 +3 -4
jakarta-commons/latka/src/java/org/apache/commons/latka/http/ParametersImpl.java
Index: ParametersImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/http/ParametersImpl.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ParametersImpl.java 10 Apr 2002 22:36:12 -0000 1.3
+++ ParametersImpl.java 11 Apr 2002 13:40:47 -0000 1.4
@@ -7,7 +7,7 @@
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -57,9 +57,8 @@
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
- * [Additional notices, if required by prior licensing conditions]
- *
*/
+
package org.apache.commons.latka.http;
import java.util.LinkedList;
@@ -72,7 +71,7 @@
* @see Parameters
* @author Morgan Delagrange
* @author <a href="mailto:[EMAIL PROTECTED]">dIon Gillard</a>
- * @version $Id: ParametersImpl.java,v 1.3 2002/04/10 22:36:12 dion Exp $
+ * @version $Id: ParametersImpl.java,v 1.4 2002/04/11 13:40:47 dion Exp $
*/
public class ParametersImpl implements Parameters {
1.5 +3 -4
jakarta-commons/latka/src/java/org/apache/commons/latka/http/Credentials.java
Index: Credentials.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/http/Credentials.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Credentials.java 10 Apr 2002 22:36:12 -0000 1.4
+++ Credentials.java 11 Apr 2002 13:40:47 -0000 1.5
@@ -7,7 +7,7 @@
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -57,15 +57,14 @@
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
- * [Additional notices, if required by prior licensing conditions]
- *
*/
+
package org.apache.commons.latka.http;
/**
* Used for authentication
* @author Morgan Delagrange
- * @version $Id: Credentials.java,v 1.4 2002/04/10 22:36:12 dion Exp $
+ * @version $Id: Credentials.java,v 1.5 2002/04/11 13:40:47 dion Exp $
*/
public interface Credentials {
1.4 +3 -4
jakarta-commons/latka/src/java/org/apache/commons/latka/http/RequestHeaders.java
Index: RequestHeaders.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/http/RequestHeaders.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- RequestHeaders.java 11 Apr 2002 02:34:53 -0000 1.3
+++ RequestHeaders.java 11 Apr 2002 13:40:47 -0000 1.4
@@ -7,7 +7,7 @@
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -57,9 +57,8 @@
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
- * [Additional notices, if required by prior licensing conditions]
- *
*/
+
package org.apache.commons.latka.http;
import java.util.List;
@@ -69,7 +68,7 @@
*
* @author Morgan Delagrange
* @author dIon Gillard
- * @version $Id: RequestHeaders.java,v 1.3 2002/04/11 02:34:53 dion Exp $
+ * @version $Id: RequestHeaders.java,v 1.4 2002/04/11 13:40:47 dion Exp $
*/
public interface RequestHeaders {
1.18 +371 -316
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.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- RequestImpl.java 2 Feb 2002 13:23:04 -0000 1.17
+++ RequestImpl.java 11 Apr 2002 13:40:47 -0000 1.18
@@ -1,9 +1,13 @@
/*
+ *
+ *
+ *
+ *
* ====================================================================
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -11,7 +15,7 @@
* are met:
*
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
@@ -19,15 +23,15 @@
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
- * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
+ * from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
@@ -53,9 +57,7 @@
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
- * [Additional notices, if required by prior licensing conditions]
- *
- */
+ */
package org.apache.commons.latka.http;
// java imports
@@ -76,328 +78,381 @@
import org.apache.log4j.Category;
/**
- * An implementation of a Latka Request interface based on the Jakarta Commons
HttpClient package.
+ * An implementation of a Latka Request interface based on the Jakarta Commons
+ * HttpClient package.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Doug Sale</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Morgan Delagrange</a>
* @author dIon Gillard
- * @version $Id: RequestImpl.java,v 1.17 2002/02/02 13:23:04 dion Exp $
+ * @version $Id: RequestImpl.java,v 1.18 2002/04/11 13:40:47 dion Exp $
+ * @see Request
*/
public class RequestImpl implements Request {
-
- /** Standard HTTP Port */
- public static final int HTTP_PORT = 80;
-
- /** Standard HTTPS Port */
- public static final int HTTPS_PORT = 443;
-
- protected String _host = null;
- protected int _port = -1;
- protected int _method = -1;
-
- protected SessionImpl _session = null;
- protected HttpMethod _httpMethod = null;
- protected URL _targetURL = null;
- protected String _query = null;
- protected long _requestTiming = -1;
- protected String _label = null;
-
- protected RequestHeaders _requestHeaders = new RequestHeadersImpl();
- protected Parameters _parameters = new ParametersImpl();
- protected boolean _followRedirects = true;
-
- protected HttpClient _httpClient = new HttpClient();
-
- protected static final Category _log = Category.getInstance(RequestImpl.class);
-
- protected RequestImpl(URL url,int httpMethod, HttpState state,
- SessionImpl session) {
- this(null,url,httpMethod,state,session,true);
- }
-
- /**
- * Create a RequestImpl
- *
- * @param url the url that this request embodies
- * @param httpMethod the method by which this request should be executed
- * @param session the session that the request should be executed in
- */
- protected RequestImpl(String label, URL url, int httpMethod, HttpState state,
- SessionImpl session, boolean followRedirects) {
- _followRedirects = followRedirects;
- _method = httpMethod;
- _httpClient.setState(state);
- _label = label;
- _query = url.getQuery();
-
- _session = session;
- _targetURL = url;
-
- switch (httpMethod) {
- case HTTP_METHOD_GET:
- _httpMethod = new GetMethod(url.getPath());
- ((GetMethod) _httpMethod).setUseDisk(false);
- break;
- case HTTP_METHOD_POST:
- _httpMethod = new PostMethod(url.getPath());
- ((PostMethod) _httpMethod).setUseDisk(false);
- break;
- case HTTP_METHOD_HEAD:
- _httpMethod = new HeadMethod(url.getPath());
- break;
- default:
- throw new IllegalArgumentException("Unsupported HTTP Method");
+ /** Standard HTTP Port */
+ public static final int HTTP_PORT = 80;
+
+ /** Standard HTTPS Port */
+ public static final int HTTPS_PORT = 443;
+ /** host the request is being made on */
+ protected String _host = null;
+ /** port the request is being made on */
+ protected int _port = -1;
+ /** http method being used to make the request */
+ protected int _method = -1;
+ /** http session the request is part of */
+ protected SessionImpl _session = null;
+ /** http method implementation */
+ protected HttpMethod _httpMethod = null;
+ /** URL being requested */
+ protected URL _targetURL = null;
+ /** query string portion of the URL */
+ protected String _query = null;
+ /** time taken for the request in milliseconds */
+ protected long _requestTiming = -1;
+ /** name given to the request */
+ protected String _label = null;
+ /** headers sent with this request */
+ protected RequestHeaders _requestHeaders = new RequestHeadersImpl();
+ /** parameters sent with this request */
+ protected Parameters _parameters = new ParametersImpl();
+ /** whether or not redirect responses should be followed as part of the
+ request processing*/
+ protected boolean _followRedirects = true;
+ /** object used to perform the http requests */
+ protected HttpClient _httpClient = new HttpClient();
+ /** log4j category used when logging messages */
+ protected static final Category _log =
+ Category.getInstance(RequestImpl.class);
+
+ /**
+ * Create a request for the specified URL, process using the supplied method
+ * and use the supplied state and session for persistent data
+ * @param url the URL to send the request to
+ * @param httpMethod the http method to use in sending the request, as
+ * defined in {@link Request}
+ * @param state shared information across requests
+ * @param session state shared across servers and requests
+ */
+ protected RequestImpl(URL url,int httpMethod, HttpState state,
+ SessionImpl session) {
+ this(null, url, httpMethod, state, session, true);
}
-
-
- if (_query != null) {
- _httpMethod.setQueryString(_query);
+
+ /**
+ * Create a RequestImpl
+ *
+ * @param label a name for the request
+ * @param url the url that this request embodies
+ * @param httpMethod the method by which this request should be executed
+ * @param state shared information across requests
+ * @param session the session that the request should be executed in
+ * @param followRedirects whether http redirect responses should be honoured
+ */
+ protected RequestImpl(String label, URL url, int httpMethod,
+ HttpState state, SessionImpl session, boolean followRedirects) {
+
+ _followRedirects = followRedirects;
+ _method = httpMethod;
+ _httpClient.setState(state);
+
+ _label = label;
+ _query = url.getQuery();
+
+ _session = session;
+ _targetURL = url;
+
+ switch (httpMethod) {
+ case HTTP_METHOD_GET:
+ _httpMethod = new GetMethod(url.getPath());
+ ((GetMethod) _httpMethod).setUseDisk(false);
+ break;
+ case HTTP_METHOD_POST:
+ _httpMethod = new PostMethod(url.getPath());
+ ((PostMethod) _httpMethod).setUseDisk(false);
+ break;
+ case HTTP_METHOD_HEAD:
+ _httpMethod = new HeadMethod(url.getPath());
+ break;
+ default:
+ throw new IllegalArgumentException("Unsupported HTTP Method");
+ }
+
+
+ if (_query != null) {
+ _httpMethod.setQueryString(_query);
+ }
+ _httpMethod.setFollowRedirects(followRedirects);
}
- _httpMethod.setFollowRedirects(followRedirects);
- }
-
- /**
- * Returns a constant representing the http method
- * (get, post, etc.) being used by this request. See
- * the Request interface for available constants.
- *
- * @return the underlying HttpMethod object representing the request/respose pair.
- */
- protected HttpMethod getHttpMethod() {
- return _httpMethod;
- }
-
- // defined in interface
- public RequestHeaders getHeaders() {
- return _requestHeaders;
- }
-
- // defined in interface
- public void setHeaders(RequestHeaders requestHeaders) {
- _requestHeaders = requestHeaders;
- }
-
- // defined in the interface
- public Parameters getParameters() {
- return _parameters;
- }
-
- public void setParameters(Parameters parameters) {
- _parameters = parameters;
- }
-
- ///////////////////////////////
- // Request Interface Methods //
- ///////////////////////////////
-
- // defined in the interface
- public void setCredentials(Credentials credentials) {
- // null implies that this credential is the default (vs. specifying a realm)
- _session._state.setCredentials(null, new
UsernamePasswordCredentials(credentials.getUserName(),credentials.getPassword()));
- }
-
- // defined in the interface
- public Response execute() throws IOException {
-
- // set the request headers in HTTPClient
- List headers = _requestHeaders.getHeaders();
- for (int i = 0; i < headers.size(); ++i) {
- String[] header = (String[]) headers.get(i);
- _httpMethod.addRequestHeader(header[0],header[1]);
+
+ /**
+ * Returns a constant representing the http method
+ * (get, post, etc.) being used by this request. See
+ * the Request interface for available constants.
+ *
+ * @return the underlying HttpMethod object representing the request/respose
pair.
+ */
+ protected HttpMethod getHttpMethod() {
+ return _httpMethod;
}
-
- List parameters = _parameters.getParameters();
- for (int i = 0; i < parameters.size(); ++i) {
- String[] parameter = (String[]) parameters.get(i);
- addHttpClientParameter(parameter[0],parameter[1]);
+
+ /**
+ * Defined in the implemented interface
+ * @return the headers used for this request
+ * @see Request#getHeaders()
+ */
+ public RequestHeaders getHeaders() {
+ return _requestHeaders;
}
-
- // for timing
- Date startDate = new Date();
-
- Response response = null;
- try {
- // open the connection
- openConnection();
-
- _log.debug("executing request");
-
- _httpClient.executeMethod(_httpMethod);
-
- _log.debug("request executed");
-
- response = new ResponseImpl(this);
-
- // set the referer
- // note: If followRedirects
- // is enabled, HTTPClient may return a path
- // that is different from the initial request.
- // HTTPClient will not follow redirects to another
- // host or port; in that event, it will always
- // return a 301 or 302.
- _session.setReferer(new
URL(_targetURL.getProtocol(),_host,_port,_httpMethod.getPath()));
-
- } catch (IOException e) {
- // rethrow it after closing the connection
- throw e;
- } catch (HttpException e) {
- throw new IOException(e.toString());
- } finally {
- try { closeConnection(); } catch (Exception e) { e.printStackTrace(); }
+
+ /**
+ * Defined in the implemented interface
+ * @param new value for the headers property
+ * @see Request#setHeaders(RequestHeaders)
+ */
+ public void setHeaders(RequestHeaders requestHeaders) {
+ _requestHeaders = requestHeaders;
}
-
-
- _requestTiming = ((new java.util.Date()).getTime() - startDate.getTime());
-
- if (_log.isInfoEnabled()) {
- _log.info("response obtained (response logging disabled because some
responses are binary)");
+
+ /**
+ * Defined in the implemented interface
+ * @return the parameters property
+ * @see Request#getParameters()
+ */
+ public Parameters getParameters() {
+ return _parameters;
}
-
- return response;
- }
-
- // defined in the interface
- public URL getURL() {
- return _targetURL;
- }
-
- // defined in the interface
- public String getLabel() {
- return _label;
- }
-
- // defined in the interface
- public void addParameter(String name, String value) {
- _parameters.addParameter(name,value);
- }
-
- /**
- * Associate a parameter with this request.
- *
- * @param name the lvalue of the parameter
- * @param name the rvalue of the parameter
- *
- * @throws java.lang.IllegalArgumentException if a parameter is null
- */
- protected void addHttpClientParameter(String name, String value) {
-
- _log.info("adding parameter, name:");
- _log.info(name);
- _log.info("value:");
- _log.info(value);
-
- try {
- if (_httpMethod instanceof PostMethod) {
- // addParameter adds to POST Entity, not URL
- ((PostMethod) _httpMethod).addParameter(name, value);
- } else {
- StringBuffer query = new StringBuffer();
-
- // setParameter adds to URL as query string
- if (_query == null || _query.equals("")) {
- query.append(name);
- query.append("=");
- query.append(value);
+
+ /**
+ * Defined in the implemented interface
+ * @param parameters new value for parameters property
+ * @see Request#setParameters(Parameters)
+ */
+ public void setParameters(Parameters parameters) {
+ _parameters = parameters;
+ }
+
+ /**
+ * Defined in the implemented interface
+ * @param credentials username and password to use
+ * @see Request#setCreadentials(Credentials)
+ */
+ public void setCredentials(Credentials credentials) {
+ // null implies that this credential is the default (vs. specifying a
+ // realm)
+ UsernamePasswordCredentials creds = new UsernamePasswordCredentials(
+ credentials.getUserName(), credentials.getPassword());
+ _session._state.setCredentials(null, creds);
+ }
+
+ // defined in the interface
+ public Response execute() throws IOException {
+
+ // set the request headers in HTTPClient
+ List headers = _requestHeaders.getHeaders();
+ for (int i = 0; i < headers.size(); ++i) {
+ String[] header = (String[]) headers.get(i);
+ _httpMethod.addRequestHeader(header[0],header[1]);
+ }
+
+ List parameters = _parameters.getParameters();
+ for (int i = 0; i < parameters.size(); ++i) {
+ String[] parameter = (String[]) parameters.get(i);
+ addHttpClientParameter(parameter[0],parameter[1]);
}
- else {
- query.append(_query);
- query.append("&");
- query.append(name);
- query.append("=");
- query.append(value);
+
+ // for timing
+ long startDate = System.currentTimeMillis();
+
+ Response response = null;
+ try {
+ // open the connection
+ openConnection();
+
+ _log.debug("executing request");
+
+ _httpClient.executeMethod(_httpMethod);
+
+ _log.debug("request executed");
+
+ response = new ResponseImpl(this);
+
+ // set the referer
+ // note: If followRedirects
+ // is enabled, HTTPClient may return a path
+ // that is different from the initial request.
+ // HTTPClient will not follow redirects to another
+ // host or port; in that event, it will always
+ // return a 301 or 302.
+ _session.setReferer(new URL(_targetURL.getProtocol(), _host, _port,
+ _httpMethod.getPath()));
+
+ } catch (IOException e) {
+ // rethrow it after closing the connection
+ throw e;
+ } catch (HttpException e) {
+ throw new IOException(e.toString());
+ } finally {
+ try {
+ closeConnection();
+ // FIXME: Shouldn't use Exception here.
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
- _query = query.toString();
- ((HttpMethod) _httpMethod).setQueryString(_query);
- }
- } catch (NullPointerException nullX) {
- throw new IllegalArgumentException(nullX.toString());
+
+
+ _requestTiming = System.currentTimeMillis() - startDate;
+
+ if (_log.isInfoEnabled()) {
+ _log.info("response obtained (response logging disabled because "+
+ "some responses are binary)");
+ }
+
+ return response;
}
- }
-
- /**
- * Set a header in the request
- *
- * @param headerName name of any HTTP request header
- * @param headerValue value of that header
- */
- public void addHeader(String headerName, String headerValue) {
- _requestHeaders.addHeader(headerName,headerValue);
- }
-
- /**
- * Retrieve the session associated with this request.
- *
- * @return a <code>Session</code> object
- */
- public Session getSession() {
- return _session;
- }
-
- /**
- * @return the amount of time it took to execute this request (in milliseconds),
- * or -1 if the request has not yet been executed
- */
- public int getRequestTiming() {
- return(int) _requestTiming;
- }
-
- /**
- * opens an HTTP connection. This method is called
- * before executing the method.
- *
- * @param request Request containing the HttpClient object that will
- * open the connection
- * @exception IOException
- * if the server could not be contacted
- */
- protected void openConnection() throws IOException {
- _log.debug("Opening connection");
-
- URL url = getURL();
- String protocol = url.getProtocol();
- String host = url.getHost();
- int port = url.getPort();
-
- // explicitly set port if not in url,
- // just for storing away and comparison
- if (port == -1) {
- if (protocol.equals("http")) {
- port = HTTP_PORT;
- }
- else if (protocol.equals("https")) {
- port = HTTPS_PORT;
- }
- else {
- throw new IllegalArgumentException("Unsupported Protocol");
- }
+
+ // defined in the interface
+ public URL getURL() {
+ return _targetURL;
}
-
- // save session values
- _host = host;
- _port = port;
-
- // start session
- _httpClient.startSession(url);
-
- _log.debug("connection open");
-
- }
-
- protected void closeConnection() throws IOException {
- _log.debug("closing connection");
- _httpClient.endSession();
- _log.debug("connection closed");
- }
-
- // defined in the interface
- public boolean followRedirects() {
- return _followRedirects;
- }
-
- // defined in interface
- public int getMethod() {
- return _method;
- }
-
+
+ // defined in the interface
+ public String getLabel() {
+ return _label;
+ }
+
+ // defined in the interface
+ public void addParameter(String name, String value) {
+ _parameters.addParameter(name,value);
+ }
+
+ /**
+ * Associate a parameter with this request.
+ *
+ * @param name the lvalue of the parameter
+ * @param name the rvalue of the parameter
+ *
+ * @throws java.lang.IllegalArgumentException if a parameter is null
+ */
+ protected void addHttpClientParameter(String name, String value) {
+
+ _log.info("adding parameter, name:");
+ _log.info(name);
+ _log.info("value:");
+ _log.info(value);
+
+ try {
+ if (_httpMethod instanceof PostMethod) {
+ // addParameter adds to POST Entity, not URL
+ ((PostMethod) _httpMethod).addParameter(name, value);
+ } else {
+ StringBuffer query = new StringBuffer();
+
+ // setParameter adds to URL as query string
+ if (_query == null || _query.equals("")) {
+ query.append(name);
+ query.append("=");
+ query.append(value);
+ }
+ else {
+ query.append(_query);
+ query.append("&");
+ query.append(name);
+ query.append("=");
+ query.append(value);
+ }
+ _query = query.toString();
+ ((HttpMethod) _httpMethod).setQueryString(_query);
+ }
+ } catch (NullPointerException nullX) {
+ throw new IllegalArgumentException(nullX.toString());
+ }
+ }
+
+ /**
+ * Set a header in the request
+ *
+ * @param headerName name of any HTTP request header
+ * @param headerValue value of that header
+ */
+ public void addHeader(String headerName, String headerValue) {
+ _requestHeaders.addHeader(headerName,headerValue);
+ }
+
+ /**
+ * Retrieve the session associated with this request.
+ *
+ * @return a <code>Session</code> object
+ */
+ public Session getSession() {
+ return _session;
+ }
+
+ /**
+ * @return the amount of time it took to execute this request (in milliseconds),
+ * or -1 if the request has not yet been executed
+ */
+ public int getRequestTiming() {
+ return(int) _requestTiming;
+ }
+
+ /**
+ * opens an HTTP connection. This method is called
+ * before executing the method.
+ *
+ * @param request Request containing the HttpClient object that will
+ * open the connection
+ * @exception IOException
+ * if the server could not be contacted
+ */
+ protected void openConnection() throws IOException {
+ _log.debug("Opening connection");
+
+ URL url = getURL();
+ String protocol = url.getProtocol();
+ String host = url.getHost();
+ int port = url.getPort();
+
+ // explicitly set port if not in url,
+ // just for storing away and comparison
+ if (port == -1) {
+ if (protocol.equals("http")) {
+ port = HTTP_PORT;
+ }
+ else if (protocol.equals("https")) {
+ port = HTTPS_PORT;
+ }
+ else {
+ throw new IllegalArgumentException("Unsupported Protocol");
+ }
+ }
+
+ // save session values
+ _host = host;
+ _port = port;
+
+ // start session
+ _httpClient.startSession(url);
+
+ _log.debug("connection open");
+
+ }
+
+ protected void closeConnection() throws IOException {
+ _log.debug("closing connection");
+ _httpClient.endSession();
+ _log.debug("connection closed");
+ }
+
+ // defined in the interface
+ public boolean followRedirects() {
+ return _followRedirects;
+ }
+
+ // defined in interface
+ public int getMethod() {
+ return _method;
+ }
+
}
1.5 +3 -4
jakarta-commons/latka/src/java/org/apache/commons/latka/http/CredentialsImpl.java
Index: CredentialsImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/http/CredentialsImpl.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- CredentialsImpl.java 10 Apr 2002 22:36:12 -0000 1.4
+++ CredentialsImpl.java 11 Apr 2002 13:40:47 -0000 1.5
@@ -7,7 +7,7 @@
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -57,9 +57,8 @@
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
- * [Additional notices, if required by prior licensing conditions]
- *
*/
+
package org.apache.commons.latka.http;
/** Concrete Implementation of
@@ -67,7 +66,7 @@
*
* @author Morgan Delagrange
* @author <a href="mailto:[EMAIL PROTECTED]">dIon Gillard</a>
- * @version $Id: CredentialsImpl.java,v 1.4 2002/04/10 22:36:12 dion Exp $
+ * @version $Id: CredentialsImpl.java,v 1.5 2002/04/11 13:40:47 dion Exp $
* @see org.apache.commons.latka.http.Credentials
*/
public class CredentialsImpl implements Credentials {
1.8 +11 -9
jakarta-commons/latka/src/java/org/apache/commons/latka/http/Response.java
Index: Response.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/http/Response.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Response.java 9 Sep 2001 04:33:18 -0000 1.7
+++ Response.java 11 Apr 2002 13:40:47 -0000 1.8
@@ -1,9 +1,13 @@
/*
+ *
+ *
+ *
+ *
* ====================================================================
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -11,7 +15,7 @@
* are met:
*
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
@@ -19,15 +23,15 @@
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
- * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
+ * from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
@@ -53,9 +57,7 @@
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
- * [Additional notices, if required by prior licensing conditions]
- *
- */
+ */
package org.apache.commons.latka.http;
1.8 +19 -13
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.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Session.java 2 Feb 2002 13:22:10 -0000 1.7
+++ Session.java 11 Apr 2002 13:40:47 -0000 1.8
@@ -1,9 +1,13 @@
/*
+ *
+ *
+ *
+ *
* ====================================================================
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -11,7 +15,7 @@
* are met:
*
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
@@ -19,15 +23,15 @@
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
- * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
+ * from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
@@ -53,9 +57,7 @@
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
- * [Additional notices, if required by prior licensing conditions]
- *
- */
+ */
package org.apache.commons.latka.http;
@@ -68,7 +70,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Doug Sale</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Morgan Delagrange</a>
* @author dIon Gillard
- * @version $Id: Session.java,v 1.7 2002/02/02 13:22:10 dion Exp $
+ * @version $Id: Session.java,v 1.8 2002/04/11 13:40:47 dion Exp $
*/
public interface Session {
@@ -76,13 +78,17 @@
* 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 <code>Request</code> object representing the <code>url</code>
and <code>httpMethod</code>
+ * @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);
+
+ public Request createRequest(String label, URL url, int httpMethod,
+ boolean followRedirects);
/**
* Adds a cookie to all HTTP requests whose domain and path match (according to
RFC2109).
1.4 +3 -4
jakarta-commons/latka/src/java/org/apache/commons/latka/http/Parameters.java
Index: Parameters.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/http/Parameters.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Parameters.java 10 Apr 2002 22:36:12 -0000 1.3
+++ Parameters.java 11 Apr 2002 13:40:47 -0000 1.4
@@ -7,7 +7,7 @@
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -57,9 +57,8 @@
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
- * [Additional notices, if required by prior licensing conditions]
- *
*/
+
package org.apache.commons.latka.http;
import java.util.List;
@@ -69,7 +68,7 @@
*
* @author Morgan Delagrange
* @author <a href=mailto:[EMAIL PROTECTED]">dIon Gillard</a>
- * @version $Id: Parameters.java,v 1.3 2002/04/10 22:36:12 dion Exp $
+ * @version $Id: Parameters.java,v 1.4 2002/04/11 13:40:47 dion Exp $
*/
public interface Parameters {
1.13 +1 -3
jakarta-commons/latka/src/java/org/apache/commons/latka/http/Request.java
Index: Request.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/http/Request.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- Request.java 11 Apr 2002 02:34:53 -0000 1.12
+++ Request.java 11 Apr 2002 13:40:47 -0000 1.13
@@ -7,7 +7,7 @@
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -56,8 +56,6 @@
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
- *
- * [Additional notices, if required by prior licensing conditions]
*
*/
1.13 +12 -10
jakarta-commons/latka/src/java/org/apache/commons/latka/http/ResponseImpl.java
Index: ResponseImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/http/ResponseImpl.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- ResponseImpl.java 2 Feb 2002 13:22:33 -0000 1.12
+++ ResponseImpl.java 11 Apr 2002 13:40:47 -0000 1.13
@@ -1,9 +1,13 @@
/*
+ *
+ *
+ *
+ *
* ====================================================================
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -11,7 +15,7 @@
* are met:
*
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
@@ -19,15 +23,15 @@
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
- * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
+ * from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
@@ -53,9 +57,7 @@
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
- * [Additional notices, if required by prior licensing conditions]
- *
- */
+ */
package org.apache.commons.latka.http;
@@ -71,7 +73,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Doug Sale</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Morgan Delagrange</a>
* @author dIon Gillard
- * @version $Id: ResponseImpl.java,v 1.12 2002/02/02 13:22:33 dion Exp $
+ * @version $Id: ResponseImpl.java,v 1.13 2002/04/11 13:40:47 dion Exp $
*/
public class ResponseImpl implements Response {
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>