-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
+ Also made ContextHandler warning message about features that are unimplemented (and you should use ServletContextHandler) more clear. (this helped with diagnosing where the bug was in ServletHolder) Signed-off-by: Joakim Erdfelt <[email protected]>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// | ||
// ======================================================================== | ||
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd. | ||
// ------------------------------------------------------------------------ | ||
// All rights reserved. This program and the accompanying materials | ||
// are made available under the terms of the Eclipse Public License v1.0 | ||
// and Apache License v2.0 which accompanies this distribution. | ||
// | ||
// The Eclipse Public License is available at | ||
// http://www.eclipse.org/legal/epl-v10.html | ||
// | ||
// The Apache License v2.0 is available at | ||
// http://www.opensource.org/licenses/apache2.0.php | ||
// | ||
// You may elect to redistribute this code under either of these licenses. | ||
// ======================================================================== | ||
// | ||
|
||
package org.eclipse.jetty.embedded; | ||
|
||
import java.io.IOException; | ||
import java.net.HttpURLConnection; | ||
import java.net.URI; | ||
|
||
import org.eclipse.jetty.server.Server; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
public class MinimalServletsTest | ||
{ | ||
private Server server; | ||
|
||
@BeforeEach | ||
public void startServer() throws Exception | ||
{ | ||
server = MinimalServlets.createServer(0); | ||
server.start(); | ||
} | ||
|
||
@AfterEach | ||
public void stopServer() throws Exception | ||
{ | ||
server.stop(); | ||
} | ||
|
||
@Test | ||
public void testGetHello() throws IOException | ||
{ | ||
URI uri = server.getURI().resolve("/hello"); | ||
HttpURLConnection http = (HttpURLConnection)uri.toURL().openConnection(); | ||
assertThat("HTTP Response Status", http.getResponseCode(), is(HttpURLConnection.HTTP_OK)); | ||
|
||
// HttpUtil.dumpResponseHeaders(http); | ||
|
||
// test response content | ||
String responseBody = HttpUtil.getResponseBody(http); | ||
assertThat("Response Content", responseBody, containsString("Hello")); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1265,9 +1265,10 @@ protected Servlet newInstance() throws ServletException, IllegalAccessException, | |
try | ||
{ | ||
ServletContext ctx = getServletHandler().getServletContext(); | ||
if (ctx == null) | ||
return getHeldClass().getDeclaredConstructor().newInstance(); | ||
return ctx.createServlet(getHeldClass()); | ||
if (ctx instanceof ServletContextHandler.Context) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
joakime
Author
Contributor
|
||
return ctx.createServlet(getHeldClass()); | ||
return getHeldClass().getDeclaredConstructor().newInstance(); | ||
|
||
} | ||
catch (ServletException ex) | ||
{ | ||
|
the
createServlet
method is onServletContext
, so we don't need to check forServletContextHandler.Context