001: /**
002: * $Id: Dispatcher.java,v 1.10 2005/09/21 10:52:16 dg154973 Exp $
003: * Copyright 2003 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and iPlanet
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.wireless.taglibs.dispatcher;
014:
015: import java.util.*;
016: import java.util.logging.Logger;
017: import java.util.logging.Level;
018: import javax.servlet.*;
019: import javax.servlet.http.*;
020:
021: import com.iplanet.sso.*;
022: import com.sun.portal.wireless.taglibs.base.Util;
023: import com.sun.portal.wireless.util.MAConfigProperties;
024: import com.sun.portal.log.common.PortalLogger;
025:
026: /**
027: * This class implements a servlet that is used to
028: * dispatch URLs generated by the Compressor class.
029: */
030: public class Dispatcher extends HttpServlet {
031:
032: // Create a logger for this class
033: private static Logger debugLogger = PortalLogger
034: .getLogger(Dispatcher.class);
035:
036: static private String dispatchServletName;
037: static private boolean compressorEnable;
038: static {
039: dispatchServletName = MAConfigProperties.get(
040: "ma.dispatch.servlet.name", "ma");
041: dispatchServletName = "/" + dispatchServletName;
042: String compressorEnableString = MAConfigProperties.get(
043: "ma.compressor.enable", "true");
044: compressorEnable = Boolean.valueOf(compressorEnableString)
045: .booleanValue();
046:
047: }
048:
049: public void init(ServletConfig config) throws ServletException {
050: super .init(config);
051: }
052:
053: public void doPost(HttpServletRequest request,
054: HttpServletResponse response) throws ServletException,
055: java.io.IOException {
056: doGet(request, response);
057: }
058:
059: public void doGet(HttpServletRequest request,
060: HttpServletResponse response) throws ServletException,
061: java.io.IOException {
062: SSOTokenManager tokenManager;
063: SSOToken token = null;
064: String urlString = null;
065: try {
066: tokenManager = SSOTokenManager.getInstance();
067: token = tokenManager.createSSOToken(request);
068: String charset = token.getProperty("CharSet");
069: if (charset != null && charset.length() > 0) {
070: /* this call must be made before calling any
071: request.parameter() call */
072: request.setCharacterEncoding(charset);
073: }
074: } catch (SSOException ex) {
075: urlString = MAConfigProperties.get(
076: "ma.dispatch.error.page",
077: "/jsp/default/errorpage.jsp");
078: debugLogger.log(Level.FINE, "PSMA_CSPWTD0003", ex);
079: }
080:
081: if ((request.getParameter("file") != null)
082: && (request.getParameter("comp") != null)) {
083: try {
084: request.getRequestDispatcher(
085: "/jsp/default/launchVoice.jsp").forward(
086: request, response);
087: } catch (Exception e) {
088: debugLogger.log(Level.FINE, "PSMA_CSPWTD0004", e);
089: }
090: return;
091: }
092:
093: String target = request.getParameter("target");
094: if (!compressorEnable && target != null
095: && !target.equals(dispatchServletName)) {
096: urlString = target;
097: } else if (token != null) {
098: Compressor compressor = Compressor.getCompressor(token);
099: // The retrieveURL will always return a URL. In the event
100: // of a mapping failure, it will return a URL to an error page.
101: urlString = compressor.retrieveURL(request);
102: }
103: request.getRequestDispatcher(urlString).forward(request,
104: response);
105:
106: }
107:
108: }
|