Commit 38239c6b authored by Munilla Christophe's avatar Munilla Christophe

fix bug (#70) : complete unregisterServlet method to really do it when the...

fix bug (#70) : complete unregisterServlet method to really do it when the FraSCAtiServlet singleton is not concerned ; Test added
parent f187d566
......@@ -2,7 +2,7 @@
<!--
* OW2 FraSCAti: Servlet with Apache CXF
*
* Copyright (c) 2010-2011 INRIA, University of Lille 1
* Copyright (c) 2010-2012 Inria, University of Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -112,5 +112,6 @@
</dependency>
</dependencies>
</project>
/**
* OW2 FraSCAti: Servlet Manager
* Copyright (C) 2010-2011 INRIA, University of Lille 1
* Copyright (C) 2010-2012 Inria, University of Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -21,7 +21,7 @@
*
* Author: Philippe Merle
*
* Contributor(s):
* Contributor(s): Christophe Munilla
*
*/
......@@ -29,6 +29,7 @@ package org.ow2.frascati.servlet.manager;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import javax.servlet.Servlet;
......@@ -108,20 +109,25 @@ public class JettyServletManager
/**
* @see ServletManager#unregisterServlet(String)
*/
public final void unregisterServlet(final String uri)
{
// If the uri is relative and a FraSCAti servlet is started
public final void unregisterServlet(final String uri) {
// If the uri is relative and a FraSCAti servlet is started
if(uri.startsWith("/") && FraSCAtiServlet.singleton != null) {
// then delegate the unregistration to it.
FraSCAtiServlet.singleton.unregisterServlet(uri);
return;
}
log.info("UnregisterServlet(uri=" + uri + ") called.");
// TODO
// jettyServer.removeServant(URL url);
URI servletURI = URI.create(uri);
int port = servletURI.getPort();
// Obtain the Apache CXF Jetty server factory.
JettyHTTPServerEngineFactory jettyFactory =
BusFactory.getDefaultBus().getExtension(JettyHTTPServerEngineFactory.class);
//Remove the server engine to the port map and stop it
jettyFactory.destroyForPort(port);
log.info("UnregisterServlet(uri=" + uri + ") done.");
}
......
/**
* OW2 FraSCAti : Test Servlet with Apache CXF
* Copyright (C) 2010 - 2012 Inria, USTL
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author: Christophe Munilla
*
* Contributor(s):
*
*/
package org.ow2.frascati.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.junit.Test;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.control.ContentController;
import org.objectweb.fractal.api.control.NameController;
import org.osoa.sca.annotations.Reference;
import org.osoa.sca.annotations.Scope;
import org.ow2.frascati.FraSCAti;
import org.ow2.frascati.assembly.factory.api.CompositeManager;
import org.ow2.frascati.servlet.api.ServletManager;
/**
* JUnit test case for JettyServletManager class.
*/
public class FraSCAtiTest {
ServletManager manager;
private FraSCAti frascati;
@Test
public void newFraSCAti() throws Exception {
//init FraSCAti
frascati = FraSCAti.newFraSCAti();
//Found the ServletManager Component
Component c = getComponent("assembly-factory/servlet-manager");
manager = (ServletManager) frascati.getService(c, "servlet-manager", ServletManager.class);
//Create a new Servlet
Servlet s = new ServletTest();
//Register, Unregister and Register it again
manager.registerServlet("http://localhost:8090/myServlet", s);
manager.unregisterServlet("http://localhost:8090/myServlet");
manager.registerServlet("http://localhost:8090/myServlet", s);
}
/**
* Return a component in FraSCAti from its path
*
* @param path
* the path of the Component
* @return
* the found Component
* @throws Exception
*/
private Component getComponent(String path) throws Exception {
String[] pathElements = path.split("/");
Component c = frascati.getCompositeManager().getTopLevelDomainComposite();
ContentController controller = (ContentController) c.getFcInterface("content-controller");
c = controller.getFcSubComponents()[0];
for(String pathElement : pathElements){
c = getSubComponent(c,pathElement);
}
return c;
}
/**
* Return a sub-component from its name in the Component passed on as parameter
* @param c
* The Component where to look in
* @param name
* The name of the Component
* @return
* The found Component
* @throws Exception
*/
private Component getSubComponent(Component c,String name) throws Exception {
System.out.println("search " + name + " in " + c);
ContentController controller = (ContentController) c.getFcInterface("content-controller");
for(Component comp : controller.getFcSubComponents()){
NameController nameController = (NameController) comp.getFcInterface("name-controller");
String n = nameController.getFcName();
System.out.println("\t\tfound " + n + " in " + c);
if(name.equals(n)){
return comp;
}
}
return null;
}
/**
* A simple Helloworld Servlet
*/
@SuppressWarnings("serial")
private class ServletTest extends HttpServlet {
public ServletTest(){}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.println("Hello World");
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment