You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by mo...@apache.org on 2002/10/03 20:10:19 UTC

cvs commit: jakarta-commons/latka/src/java/org/apache/commons/latka/jelly LatkaTagLibrary.java RequestTag.java SessionTag.java SuiteSettings.java SuiteTag.java

morgand     2002/10/03 11:10:19

  Added:       latka/src/java/org/apache/commons/latka/jelly
                        LatkaTagLibrary.java RequestTag.java
                        SessionTag.java SuiteSettings.java SuiteTag.java
  Log:
  very preliminary HTTP tags
  
  Revision  Changes    Path
  1.21      +10 -46    jakarta-commons/latka/src/java/org/apache/commons/latka/jelly/LatkaTagLibrary.java
  
  
  
  
  1.1                  jakarta-commons/latka/src/java/org/apache/commons/latka/jelly/RequestTag.java
  
  Index: RequestTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/jelly/RequestTag.java,v 1.1 2002/10/03 18:10:19 morgand Exp $
   * $Revision: 1.1 $
   * $Date: 2002/10/03 18:10:19 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    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
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    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", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.commons.latka.jelly;
  
  import java.net.URL;
  
  import org.apache.commons.jelly.TagSupport;
  import org.apache.commons.jelly.XMLOutput;
  
  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;
  import org.apache.commons.latka.http.SessionImpl;
  
  import org.apache.log4j.Category;
  
  /**
   *
   * @author  Morgan Delagrange
   */
  public class RequestTag extends TagSupport {
          
      protected String  _host = null;
      protected int     _port = -1;
      protected String  _proxyHost = null;
      protected int     _proxyPort = -1;
      protected String  _label = null;
      protected int  _method = Request.HTTP_METHOD_GET;
      protected String  _path = null;
      protected boolean _secure = false;
      protected boolean _followRedirects = true;
      protected String  _httpVersion = "1.1";
  
      protected static final Category _log = Category.getInstance(RequestTag.class);
  
      /** Creates a new instance of SuiteTag */
      public RequestTag() {
      }
      
      /**
       *  Wraps Latka tests, provides some defaults for host, port etc.
       *
       * @param xmlOutput a place to write output
       * @throws Exception when any error occurs
       */
      public void doTag(XMLOutput xmlOutput) throws Exception {
          String host = _host;
          int port    = _port;
          String proxyHost = _proxyHost;
          int proxyPort    = _proxyPort;
          
          if (host == null || port == -1 || proxyHost == null || proxyPort == -1) {
              SuiteSettings settings = 
                  (SuiteSettings) getContext().getVariable(SuiteTag.SUITE_SETTINGS_VAR);
              if (host == null) {
                  host = settings.getDefaultHost();
              }
              if (port == -1) {
                  port = settings.getDefaultPort();
              }
              if (proxyHost == null) {
                  proxyHost = settings.getDefaultProxyHost();
              }
              if (proxyPort == -1) {
                  proxyPort = settings.getDefaultProxyPort();
              }
          }
  
          invokeBody(xmlOutput);
  
          // for now, create an 
          _log.warn("broken, needs session handling");
          Session session = new SessionImpl();
  
          Proxy proxy = null;
          if (proxyHost != null) {
              proxy = new Proxy(proxyHost,proxyPort);
          }
  
          URL url = new URL(_secure ? "https" : "http", host, port, _path);
  
          Request request = session.createRequest(_label,url,_method,_httpVersion,_followRedirects,proxy);
          Response response = request.execute();
          // hack for HttpClient behaviour sometimes generates a new request
          request = response.getRequest();
          _log.warn("Eventually this debug needs to go.");
          if (_log.isDebugEnabled()) {
              _log.debug(response.getResource());
          }
      }
  
      /**
       * Setter for host
       * 
       * @param host
       *               host for the request
       */
      public void setHost(String host) {
          _host = host;
      }
      
      /**
       * Setter for port
       * 
       * @param port
       *               port for all requests 
       */
      public void setPort(int port) {
          _port = port;
      }
  
  
      /**
       * Setter for defaultProxyHost
       * 
       * @param defaultHost
       *               defaultProxyHost for all requests
       */
      public void setProxyHost(String host) {
          _proxyHost = host;
      }
  
      /**
       * Setter for defaultProxyPort
       * 
       * @param defaultPort
       *               defaultProxyPort for all requests
       * @return 
       */
      public void setProxyPort(int port) {
          _proxyPort = port;
      }
  
      /**
       * Set the label for this suite
       * 
       * @param label  suite label
       */
      public void setLabel(String label) {
          _label = label;
      }
  
      /**
       * Sets the HTTP method to use.  Supports post, get,
       * and head.  Default is "get".
       * 
       * @param method set method to post, get or head
       * @exception UnsupportedOperationException
       *                   if an unsupported HTTP method is set
       */
      public void setMethod(String method) throws UnsupportedOperationException {
          if (method.equals("get")) {
              _method = Request.HTTP_METHOD_GET;
          } else if (method.equals("post")) {
              _method = Request.HTTP_METHOD_POST;
          } else if (method.equals("head")) {
              _method = Request.HTTP_METHOD_HEAD;
          } else {
              throw new UnsupportedOperationException("Unkonwn HTTP method: " + method);
          }
      }
  
      /**
       * Sets the path of the document on the server, combined
       * with the host and port
       * 
       * @param path   Path to the document on the server
       */
      public void setPath(String path) {
          _path = path;
      }
  
      /**
       * Sets whether or not to transmit the request over
       * SSL.
       * 
       * @param secure whether or not this request is SSL
       */
      public void setSecure(String secure) {
          _secure = Boolean.valueOf(secure).booleanValue();
      }
  
  
      /**
       * Sets whether or not to transmit the request over
       * SSL.
       * 
       * @param secure whether or not this request is SSL
       */
      public void setFollowRedirects(String followRedirects) {
          _followRedirects = Boolean.valueOf(followRedirects).booleanValue();
      }
  
      /**
       * HTTP version to use.  Legal values are 1.0 and 1.1.
       * 1.1 is the default.
       * 
       * @param version HTTP specification version
       */
      public void setVersion(String version) {
          _httpVersion = version;
      }
  
  }
  
  
  
  1.10      +26 -190   jakarta-commons/latka/src/java/org/apache/commons/latka/jelly/SessionTag.java
  
  
  
  
  1.1                  jakarta-commons/latka/src/java/org/apache/commons/latka/jelly/SuiteSettings.java
  
  Index: SuiteSettings.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/jelly/SuiteSettings.java,v 1.1 2002/10/03 18:10:19 morgand Exp $
   * $Revision: 1.1 $
   * $Date: 2002/10/03 18:10:19 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    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
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    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", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.commons.latka.jelly;
  
  /**
   *
   * @author  Morgan Delagrange
   */
  public class SuiteSettings {
          
      protected String _defaultHost = null;
      protected int _defaultPort = -1;
      protected String _defaultProxyHost = null;
      protected int _defaultProxyPort = -1;
  
      /** Creates a new instance of SuiteSettings */
      public SuiteSettings(String defaultHost, int defaultPort,
                           String defaultProxyHost, int defaultProxyPort) {
          _defaultHost = defaultHost;
          _defaultPort = defaultPort;
          _defaultProxyHost = defaultProxyHost;
          _defaultProxyPort = defaultProxyPort;
      }
      
      /**
       * defaultHost
       * 
       * @return defaultHost for all requests
       */
      public String getDefaultHost() {
          return _defaultHost;
      }
      
      /**
       * defaultPort
       * 
       * @return defaultPort for all requests
       */
      public int getDefaultPort() {
          return _defaultPort;
      }
  
  
      /**
       * defaultProxyHost
       * 
       * @return defaultProxyHost for all requests
       */
      public String getDefaultProxyHost() {
          return _defaultProxyHost;
      }
  
      /**
       * defaultProxyPort
       * 
       * @return defaultProxyPort for all requests
       */
      public int getDefaultProxyPort() {
          return _defaultProxyPort;
      }
  
  }
  
  
  
  1.11      +75 -16    jakarta-commons/latka/src/java/org/apache/commons/latka/jelly/SuiteTag.java
  
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>