commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: jakarta-commons/latka/src/webapps/latka-webapp/src/org/apache/commons/latka/servlet ViewSuiteServlet.java ViewResponseServlet.java
Date Mon, 22 Apr 2002 15:50:05 GMT
dion        02/04/22 08:50:05

  Added:       latka/src/webapps/latka-webapp/webapp/WEB-INF web.xml
               latka/src/webapps/latka-webapp/webapp/WEB-INF/classes
                        latka.properties
               latka/src/webapps/latka-webapp/src/org/apache/commons/latka/servlet
                        ViewSuiteServlet.java ViewResponseServlet.java
  Log:
  Moved from top level into src
  
  Revision  Changes    Path
  1.1                  jakarta-commons/latka/src/webapps/latka-webapp/webapp/WEB-INF/web.xml
  
  Index: web.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?>
  
  <!DOCTYPE web-app
      PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
      "http://java.sun.com/j2ee/dtds/web-app_2.2.dtd">
  
  <web-app>
  
    <description>
      Latka standard web application
    </description>
    
    <context-param>
      <param-name>latka.testDir</param-name>
      <param-value>/lib/latka/tests/samples</param-value>
    </context-param>
  
    <!-- view response servlet -->
    <servlet>
      <servlet-name>viewResponse</servlet-name>
      <servlet-class>org.apache.commons.latka.servlet.ViewResponseServlet</servlet-class>
    </servlet>
    
    <!-- view suite servlet -->
    <servlet>
      <servlet-name>viewSuite</servlet-name>
      <servlet-class>org.apache.commons.latka.servlet.ViewSuiteServlet</servlet-class>
    </servlet>
  
    <!-- view response servlet -->
    <servlet-mapping>
      <servlet-name>viewResponse</servlet-name>
      <url-pattern>/viewResponse</url-pattern>
    </servlet-mapping>
  
    <!-- view suite servlet -->
    <servlet-mapping>
      <servlet-name>viewSuite</servlet-name>
      <url-pattern>/viewSuite</url-pattern>
    </servlet-mapping>
    
    <taglib>
      <taglib-uri>http://jakarta.apache.org/taglibs/latka-taglib</taglib-uri>
      <taglib-location>/WEB-INF/latka-taglib.tld</taglib-location>
    </taglib>
  
    <taglib>
      <taglib-uri>http://jakarta.apache.org/taglibs/io</taglib-uri>
      <taglib-location>/WEB-INF/io.tld</taglib-location>
    </taglib>
  
    <!-- if you want to test basic auth, you have to set it up the latka-auth
         role in your servlet container's security interface -->
    <security-constraint>
      <web-resource-collection>
        <web-resource-name>Protected Area</web-resource-name>
          
        <!-- Define the context-relative URL(s) to be protected -->
        <url-pattern>/self-test/basicAuth/*</url-pattern>
      </web-resource-collection>
      <auth-constraint>
         <!-- Anyone with one of the listed roles may access this area -->
         <role-name>latka-auth</role-name>
      </auth-constraint>
    </security-constraint>
  
    <login-config>
      <auth-method>BASIC</auth-method>
      <realm-name>latka-realm</realm-name>
    </login-config>
  
  </web-app>
  
  
  
  1.1                  jakarta-commons/latka/src/webapps/latka-webapp/webapp/WEB-INF/classes/latka.properties
  
  Index: latka.properties
  ===================================================================
  # User defined default properties for each test.  
  # These properties can be overridden on the command line. 
  # Some example properties:
  # defaultHost=localhost
  # defaultPort=8080
  
  
  
  1.1                  jakarta-commons/latka/src/webapps/latka-webapp/src/org/apache/commons/latka/servlet/ViewSuiteServlet.java
  
  Index: ViewSuiteServlet.java
  ===================================================================
  package org.apache.commons.latka.servlet;
  
  import java.io.IOException;
  import java.io.PrintWriter;
  
  import java.net.URL;
  
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import org.apache.commons.latka.Suite;
  import org.apache.commons.latka.xml.XMLPreprocessor;
  
  public class ViewSuiteServlet extends HttpServlet {
    
    public void doPost(HttpServletRequest req, HttpServletResponse res) 
    throws IOException {
      doGet(req,res);
    }
  
    public void doGet(HttpServletRequest req, HttpServletResponse res) 
    throws IOException {
  
      String suiteUrl = req.getParameter("url");
  
      res.setHeader("Content-type","text/xml");
  
      Suite suite = new Suite(new URL(suiteUrl));
  
      XMLPreprocessor processor = XMLPreprocessor.instance();
      
      PrintWriter writer = res.getWriter();
  
      // do an identity transform to resolve any external entities
      String xml = processor.identityTransform(suite);
      writer.print(xml);
    }
  
  }
  
  
  
  1.1                  jakarta-commons/latka/src/webapps/latka-webapp/src/org/apache/commons/latka/servlet/ViewResponseServlet.java
  
  Index: ViewResponseServlet.java
  ===================================================================
  package org.apache.commons.latka.servlet;
  
  import java.io.InputStream;
  import java.io.IOException;
  import java.io.OutputStream;
  
  import java.util.Collections;
  import java.util.Comparator;
  import java.util.List;
  
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpSession;
  
  import org.apache.commons.latka.http.Response;
  
  import org.apache.log4j.Category;
  
  public class ViewResponseServlet extends HttpServlet {
    
    public static Category _log = 
      Category.getInstance(ViewResponseServlet.class);
  
    public void doPost(HttpServletRequest req, HttpServletResponse res) 
    throws IOException {
      doGet(req,res);
    }
  
    public void doGet(HttpServletRequest req, HttpServletResponse res) 
    throws IOException {
      HttpSession session = req.getSession();
  
      List list = (List) session.getAttribute("latka.failedResponses");
  
      String responseHash = req.getParameter("responseId");
  
      Collections.sort(list,new ToStringComparator());
      int i = Collections.binarySearch(list,responseHash,new ToStringComparator());
  
      Response response = (Response) list.get(i);
  
      // set the content type, if specified
      String contentType = response.getHeader("Content-type");
      _log.debug("Content type = " + contentType);
      if (contentType != null) {
        res.setHeader("Content-type",contentType);
      }
  
      InputStream responseStream = response.getStream();
      OutputStream servletStream = res.getOutputStream();
  
      _log.debug("got input and output streams");
  
      int someByte = responseStream.read();
  
      _log.debug("read first byte: " + someByte);
  
      while (someByte > -1) {
        servletStream.write(someByte);
        someByte = responseStream.read();
      }
  
      _log.debug("end doGet(HttpServletRequest,HttpServletResponse)");
    }
  
    private class ToStringComparator implements Comparator {
      public int compare(Object o1, Object o2) {
        return o1.toString().compareTo(o2.toString());
      }
    }
  
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message