users@grizzly.java.net

Re: add second ServletAdapter to GrizzlyWebServer after webserver.start()

From: Hubert Iwaniuk <neotyk_at_kungfoo.pl>
Date: Fri, 3 Apr 2009 21:10:49 +0200

All credit to Jeanfrancois :)

Thank you for great bug report,
   Hubert


On Fri, Apr 3, 2009 at 8:34 PM, Edward Chou <Edward.Chou_at_sun.com> wrote:

> Thanks guys for solving the issue, :-) .
>
> Hubert Iwaniuk wrote:
>
>> Hi,
>>
>> Exactly and adding more than one already creates a chain, a different
>> adapter, so later additions don't need to modify adapter been used :)
>>
>> Cheers,
>> Hubert
>>
>> On Fri, Apr 3, 2009 at 3:44 PM, Jeanfrancois Arcand <
>> Jeanfrancois.Arcand_at_sun.com <mailto:Jeanfrancois.Arcand_at_sun.com>> wrote:
>>
>> Salut
>>
>>
>> Hubert Iwaniuk wrote:
>>
>> Hi Edward,
>>
>> I could reproduce your issue. Don't know yet what is going
>> wrong. I'll investigate it.
>>
>>
>> Thanks Hubert. What is strange is the unit test I've added
>> yesterday is almost the same, except more that one Adapter gets
>> added before starting GWS. The Mapper is laughing at us :-)
>>
>> A+
>>
>> -- Jeanfrancois
>>
>>
>> Thanks for nice bug report,
>> Hubert.
>>
>>
>> On Fri, Apr 3, 2009 at 1:30 AM, Edward Chou
>> <Edward.Chou_at_sun.com <mailto:Edward.Chou_at_sun.com>
>> <mailto:Edward.Chou_at_sun.com <mailto:Edward.Chou_at_sun.com>>> wrote:
>>
>> Hi Jeanfrancois,
>>
>> Attached is my testcase for this issue. Basically, it
>> registers
>> "/servlet1" to GrizzlyWebServer before server start, and
>> "/servlet2"
>> to GrizzlyWebServer after server start.
>> Then you point your browser to
>> "http://localhost:9999/servlet1", it
>> returns "content for servlet1", this is expected. However,
>> then you
>> point your browser to "http://localhost:9999/servlet2", it
>> still
>> returns "content for servlet1", but expected result should be
>> "content for servlet2".
>>
>> If you move the "webServer.start()" call after servlet2 is
>> added,
>> then everything works as expected.
>>
>> Thanks for your help,
>> Edward
>>
>>
>> Jeanfrancois Arcand wrote:
>>
>> Salut,
>>
>> Edward Chou wrote:
>>
>> I am using the latest version, 1.9.10.
>>
>> Jeanfrancois Arcand wrote:
>>
>> Salut,
>>
>> Edward Chou wrote:
>>
>> Hi,
>>
>> I am wondering if the following is possible:
>>
>> GrizzlyWebServer webServer = new
>> GrizzlyWebServer(9999);
>> ServletAdapter adapter1 =
>> createAdapter("/atom1");
>>
>> webServer.addGrizzlyAdapter(adapter1, new
>> String[] { "/atom1" });
>> webServer.start();
>>
>> < .. do something else ... >
>> ServletAdapter adapter2 =
>> createAdapter("/atom2");
>> webServer.addGrizzlyAdapter(adapter2, new
>> String[] { "/atom2" });
>>
>>
>> Yes, it should work:\. Take a look at:
>>
>>
>> https://grizzly.dev.java.net/nonav/xref-test/com/sun/grizzly/http/GrizzlyWebServerTest.html
>>
>>
>>
>> I've just added a unit test and for me it pass. Can you
>> share
>> your code?
>>
>> +
>> + public void
>> testAddGrizzlyAdapterBeforeAndAfterStart()
>> throws IOException {
>> +
>> System.out.println("testAddGrizzlyAdapterBeforeAndAfterStart");
>> + try {
>> + gws = new GrizzlyWebServer(PORT);
>> + String[] aliases = new String[]{"/1",
>> "/2", "/3"};
>> + for (String alias : aliases) {
>> + addAdapter(alias);
>> + }
>> + gws.start();
>> + String alias = "/4";
>> + addAdapter(alias);
>> +
>> + HttpURLConnection conn =
>> getConnection(alias);
>> + assertEquals(HttpServletResponse.SC_OK,
>> + getResponseCodeFromAlias(conn));
>> + assertEquals(alias, readResponse(conn));
>> + } finally {
>> + stopGrizzlyWebServer();
>> + }
>> + }
>> +
>> +
>> +
>>
>>
>> Thanks
>>
>> -- Jeanfrancois
>>
>>
>>
>>
>>
>>
>>
>> Basically, I want to deploy a second
>> ServletAdapter
>> after the GrizzlyWebServer has already been
>> started.
>> Currently, the second servlet is not
>> activated, but
>> first servlet is. Any help is appreciated.
>>
>>
>> Hum...let me try it then. Which version are you
>> using?
>>
>> Thanks
>>
>> -- Jeanfrancois
>>
>>
>>
>> Edward
>>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:
>> users-unsubscribe_at_grizzly.dev.java.net
>> <mailto:users-unsubscribe_at_grizzly.dev.java.net>
>> <mailto:users-unsubscribe_at_grizzly.dev.java.net
>> <mailto:users-unsubscribe_at_grizzly.dev.java.net>>
>>
>> For additional commands, e-mail:
>> users-help_at_grizzly.dev.java.net
>> <mailto:users-help_at_grizzly.dev.java.net>
>> <mailto:users-help_at_grizzly.dev.java.net
>> <mailto:users-help_at_grizzly.dev.java.net>>
>>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:
>> users-unsubscribe_at_grizzly.dev.java.net
>> <mailto:users-unsubscribe_at_grizzly.dev.java.net>
>> <mailto:users-unsubscribe_at_grizzly.dev.java.net
>> <mailto:users-unsubscribe_at_grizzly.dev.java.net>>
>>
>> For additional commands, e-mail:
>> users-help_at_grizzly.dev.java.net
>> <mailto:users-help_at_grizzly.dev.java.net>
>> <mailto:users-help_at_grizzly.dev.java.net
>> <mailto:users-help_at_grizzly.dev.java.net>>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:
>> users-unsubscribe_at_grizzly.dev.java.net
>> <mailto:users-unsubscribe_at_grizzly.dev.java.net>
>> <mailto:users-unsubscribe_at_grizzly.dev.java.net
>> <mailto:users-unsubscribe_at_grizzly.dev.java.net>>
>>
>> For additional commands, e-mail:
>> users-help_at_grizzly.dev.java.net
>> <mailto:users-help_at_grizzly.dev.java.net>
>> <mailto:users-help_at_grizzly.dev.java.net
>> <mailto:users-help_at_grizzly.dev.java.net>>
>>
>>
>>
>>
>> package grizzly;
>>
>> import java.io.IOException;
>>
>> import javax.servlet.ServletException;
>> import javax.servlet.http.HttpServlet;
>> import javax.servlet.http.HttpServletRequest;
>> import javax.servlet.http.HttpServletResponse;
>>
>> import com.sun.grizzly.http.embed.GrizzlyWebServer;
>> import com.sun.grizzly.http.servlet.ServletAdapter;
>>
>> /**
>> * GrizzlyServerTest.java
>> *
>> * @author Edward Chou
>> */
>> public class GrizzlyServerTest {
>>
>>
>> public static void main(String[] args) {
>>
>> GrizzlyWebServer webServer = new GrizzlyWebServer(9999);
>>
>> try {
>> ServletAdapter adapter1 = createAdapter1();
>> ServletAdapter adapter2 = createAdapter2();
>>
>> webServer.addGrizzlyAdapter(adapter1, new String[] {
>> "/servlet1" });
>>
>> System.out.println("server started ...");
>> webServer.start();
>>
>> System.out.println("sleeping for 10 seconds...");
>> Thread.sleep(10000);
>>
>> webServer.addGrizzlyAdapter(adapter2, new String[] {
>> "/servlet2" });
>> System.out.println("servlet2 added ...");
>>
>>
>> System.out.println("Hit return to stop...");
>> System.in.read();
>>
>> } catch (Exception e) {
>> e.printStackTrace();
>> } finally {
>> webServer.stop();
>> }
>>
>>
>> }
>>
>> private static ServletAdapter createAdapter1() {
>> ServletAdapter adapter = new ServletAdapter(new
>> HttpServlet() {
>> @Override
>> protected void doGet(HttpServletRequest req,
>> HttpServletResponse resp)
>> throws ServletException, IOException {
>> resp.setStatus(HttpServletResponse.SC_OK);
>> resp.getWriter().write("content for servlet1");
>> }
>> });
>> return adapter;
>>
>> }
>>
>> private static ServletAdapter createAdapter2() {
>> ServletAdapter adapter = new ServletAdapter(new
>> HttpServlet() {
>> @Override
>> protected void doGet(HttpServletRequest req,
>> HttpServletResponse resp)
>> throws ServletException, IOException {
>> resp.setStatus(HttpServletResponse.SC_OK);
>> resp.getWriter().write("content for servlet2");
>> }
>> });
>> return adapter;
>>
>> }
>>
>> }
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:
>> users-unsubscribe_at_grizzly.dev.java.net
>> <mailto:users-unsubscribe_at_grizzly.dev.java.net>
>> <mailto:users-unsubscribe_at_grizzly.dev.java.net
>> <mailto:users-unsubscribe_at_grizzly.dev.java.net>>
>>
>> For additional commands, e-mail:
>> users-help_at_grizzly.dev.java.net
>> <mailto:users-help_at_grizzly.dev.java.net>
>> <mailto:users-help_at_grizzly.dev.java.net
>> <mailto:users-help_at_grizzly.dev.java.net>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
>> <mailto:users-unsubscribe_at_grizzly.dev.java.net>
>> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>> <mailto:users-help_at_grizzly.dev.java.net>
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>
>