001: /*
002: * <copyright>
003: *
004: * Copyright 2003-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026: package org.cougaar.lib.aggagent.servlet;
027:
028: import java.io.IOException;
029: import java.io.PrintWriter;
030:
031: import javax.servlet.http.HttpServlet;
032: import javax.servlet.http.HttpServletRequest;
033: import javax.servlet.http.HttpServletResponse;
034:
035: import org.cougaar.core.service.UIDService;
036: import org.cougaar.core.service.wp.WhitePagesService;
037: import org.cougaar.lib.aggagent.session.SessionManager;
038:
039: /**
040: * The AggregationComponent provides external access (via HTTP) to the
041: * Aggregation functionality. Currently, it supports both a HTML user
042: * interface with frames and a XML interface for thick clients.
043: */
044: public class AggregationComponent extends BlackboardServletComponent {
045: private Object lock = new Object();
046: private WhitePagesService wps = null;
047: private AggregationServletInterface htmlInterface = null;
048: private AggregationServletInterface xmlInterface = null;
049:
050: private UIDService UIDService;
051:
052: /**
053: * Constructor.
054: */
055: public AggregationComponent() {
056: super ();
057: myServlet = new AggregationServlet();
058: }
059:
060: public void setWhitePagesService(WhitePagesService wps) {
061: this .wps = wps;
062: }
063:
064: /** Getter for property UIDService.
065: * @return Value of property UIDService.
066: */
067: public UIDService getUIDService() {
068: return this .UIDService;
069: }
070:
071: /** Setter for property UIDService.
072: * @param UIDService New value of property UIDService.
073: */
074: public void setUIDService(UIDService UIDService) {
075: this .UIDService = UIDService;
076: }
077:
078: /**
079: * When this class is created the "load()" method will
080: * be called, at which time we'll register our Servlet.
081: */
082: public void load() {
083: super .load();
084:
085: // create interface objects
086: SessionManager man = new SessionManager(agentId.toString(),
087: blackboard, createSubscriptionSupport());
088: htmlInterface = new AggregationHTMLInterface(blackboard,
089: createSubscriptionSupport(), myPath, getUIDService());
090: xmlInterface = new AggregationXMLInterface(blackboard,
091: createSubscriptionSupport(), agentId.toString(), wps,
092: man, getUIDService());
093: }
094:
095: /**
096: * Here is our inner class that will handle all HTTP and
097: * HTTPS service requests for our <tt>myPath</tt>.
098: */
099: private class AggregationServlet extends HttpServlet {
100: public void doGet(HttpServletRequest request,
101: HttpServletResponse response) throws IOException {
102: handleRequest(request, response);
103: }
104:
105: public void doPut(HttpServletRequest request,
106: HttpServletResponse response) throws IOException {
107: handleRequest(request, response);
108: }
109:
110: private void handleRequest(HttpServletRequest request,
111: HttpServletResponse response) throws IOException {
112: PrintWriter out = response.getWriter();
113:
114: synchronized (lock) {
115: if (request.getParameter("THICK_CLIENT") != null) {
116: xmlInterface.handleRequest(out, request);
117: } else {
118: htmlInterface.handleRequest(out, request);
119: }
120: out.flush();
121: }
122: }
123: }
124: }
|