org/objectweb/proactive/core/rmi/ClassServerServlet.java

00001 /* 
00002  * ################################################################
00003  * 
00004  * ProActive: The Java(TM) library for Parallel, Distributed, 
00005  *            Concurrent computing with Security and Mobility
00006  * 
00007  * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
00008  * Contact: proactive@objectweb.org
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or any later version.
00014  *  
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00023  * USA
00024  *  
00025  *  Initial developer(s):               The ProActive Team
00026  *                        http://www.inria.fr/oasis/ProActive/contacts.html
00027  *  Contributor(s): 
00028  * 
00029  * ################################################################
00030  */ 
00031 package org.objectweb.proactive.core.rmi;
00032 
00033 import org.objectweb.proactive.core.util.UrlBuilder;
00034 
00035 import java.io.IOException;
00036 import java.io.InputStream;
00037 import java.io.OutputStream;
00038 
00039 import java.net.UnknownHostException;
00040 
00041 import javax.servlet.http.HttpServlet;
00042 import javax.servlet.http.HttpServletRequest;
00043 import javax.servlet.http.HttpServletResponse;
00044 
00045 
00046 public class ClassServerServlet extends HttpServlet {
00047     //  public static final String WEB_ROOT = "/proactive";
00048     public static final String SERVLET_NAME = "/ProActiveHTTP";
00049     private String url;
00050     private ClassServer classServer;
00051     private HttpServletRequest request;
00052     private HttpServletResponse response;
00053     private static int port;
00054 
00055     public ClassServerServlet(int newport) {
00056         System.out.println("New Class Server Servlet");
00057         this.port = newport;
00058         ClassServerHelper helper = new ClassServerHelper();
00059         System.setProperty("proactive.http.port", this.port + "");
00060         try {
00061             helper.initializeClassServer();
00062         } catch (IOException e) {
00063             e.printStackTrace();
00064         }
00065     }
00066 
00067     public static int getPort() {
00068         return port;
00069     }
00070 
00071     public void doGet(HttpServletRequest request, HttpServletResponse response) {
00072         //        try { 
00073 //        System.out.println(
00074 //            "*************************** DO GET ****************************** ");
00075         doPost(request, response);
00076         //            PrintWriter out = response.getWriter();
00077         //            out.println("Some informations about the ProActive runtime : \n");
00078         //            out.println("Proactive communication protocol = " +
00079         //                System.getProperty("proactive.communication.protocol") + "\n");
00080         //
00081         //            out.println("servlet Enabled =  " +
00082         //                ProActiveConfiguration.osgiServletEnabled());
00083         //            out.println("Servlet url = " + ClassServerServlet.getUrl());
00084         //        } catch (IOException e) {
00085         //            e.printStackTrace();
00086         //        }
00087     }
00088 
00089     public void doPost(HttpServletRequest request, HttpServletResponse response) {
00090         try {
00091             this.request = request;
00092             this.response = response;
00093 
00094             InputStream in = request.getInputStream();
00095             OutputStream out = response.getOutputStream();
00096             RequestInfo reqInfo = new RequestInfo();
00097             reqInfo.read(this.request);
00098             HTTPRequestHandler service = new HTTPRequestHandler(in, out,
00099                     reqInfo, response);
00100             service.run();
00101         } catch (IOException e) {
00102             e.printStackTrace();
00103         }
00104     }
00105 
00106     public static String getUrl() {
00107         try {
00108             //            int port = Integer.parseInt(System.getProperty(
00109             //                        "proactive.http.port"));
00110             String url = UrlBuilder.buildUrl(UrlBuilder.getHostNameorIP(
00111                         java.net.InetAddress.getLocalHost()), "", "http:", port); /*+
00112                "/" + SERVLET_NAME ;*/
00113 
00114             if (url.charAt(url.length() - 1) == '/') {
00115                 url = url.substring(0, url.length() - 1);
00116             }
00117             url += SERVLET_NAME;
00118             return url;
00119         } catch (UnknownHostException e) {
00120             e.printStackTrace();
00121         }
00122         return null;
00123     }
00124 }

Generated on Mon Jan 22 15:16:09 2007 for ProActive by  doxygen 1.5.1