001: /**
002: * Copyright 2003 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */package com.sun.portal.wsrp.producer.router;
013:
014: import java.io.PrintWriter;
015: import java.util.logging.Level;
016: import java.util.logging.Logger;
017:
018: import javax.servlet.ServletException;
019: import javax.servlet.RequestDispatcher;
020:
021: import javax.servlet.http.HttpServlet;
022: import javax.servlet.http.HttpServletRequest;
023: import javax.servlet.http.HttpServletResponse;
024:
025: import com.sun.portal.desktop.context.DesktopContextFactory;
026: import com.sun.portal.desktop.context.PSDesktopContextFactoryManager;
027: import com.sun.portal.desktop.context.DesktopAppContext;
028:
029: import com.sun.portal.desktop.context.DesktopContextFactory;
030: import com.sun.portal.desktop.context.PSDesktopContextFactoryManager;
031: import com.sun.portal.desktop.context.DesktopAppContext;
032:
033: import com.sun.portal.wsrp.producer.ProducerException;
034: import com.sun.portal.wsrp.producer.ISConnection;
035: import com.sun.portal.log.common.PortalLogger;
036:
037: public class RouterServlet extends HttpServlet {
038: public static final String WSRP_PRODUCER_KEY = "wsrp.producer.key";
039:
040: private static Logger logger = PortalLogger
041: .getLogger(RouterServlet.class);
042:
043: private static class Identifier {
044: private String key = null;
045: private String service = null;
046:
047: public Identifier(HttpServletRequest req)
048: throws ProducerException {
049: String pathinfo = req.getPathInfo();
050: if (pathinfo == null || pathinfo.length() == 0) {
051: throw new ProducerException("pathinfo was null");
052: }
053:
054: //
055: // remove leading "/"
056: //
057: pathinfo = pathinfo.substring(1);
058:
059: //
060: // find index of slash between the key and service
061: //
062: int i = pathinfo.indexOf("/");
063: if (i == -1) {
064: throw new ProducerException("invalid format pathinfo="
065: + pathinfo);
066: }
067:
068: service = pathinfo.substring(0, i);
069: key = pathinfo.substring(i + 1);
070: }
071:
072: public String getKey() {
073: return key;
074: }
075:
076: public String getService() {
077: return service;
078: }
079: }
080:
081: protected void service(HttpServletRequest req,
082: HttpServletResponse res) throws ServletException,
083: java.io.IOException {
084: try {
085: Identifier id = new Identifier(req);
086: if (logger.isLoggable(Level.FINEST)) {
087: String[] param = { "key", id.getKey() };
088: logger.log(Level.FINEST, "PSWS_CSPWPR0001", param);
089: param[0] = "service";
090: param[1] = id.getService();
091: logger.log(Level.FINEST, "PSWS_CSPWPR0001", param);
092: }
093:
094: req.setAttribute(WSRP_PRODUCER_KEY, id.getKey());
095: RequestDispatcher rd = req
096: .getRequestDispatcher("/wsrp/service/"
097: + id.getService());
098: rd.forward(req, res);
099: } catch (Throwable t) {
100: if (logger.isLoggable(Level.SEVERE))
101: logger.log(Level.SEVERE, "PSWS_CSPWPR0002", t);
102: res.sendError(HttpServletResponse.SC_NOT_ACCEPTABLE);
103: }
104: }
105: }
|