use of org.eclipse.jetty.client.HttpClient in project jetty.project by eclipse.
the class FastCGIProxyServletTest method prepare.
public void prepare(HttpServlet servlet) throws Exception {
QueuedThreadPool serverThreads = new QueuedThreadPool();
serverThreads.setName("server");
server = new Server(serverThreads);
httpConnector = new ServerConnector(server);
server.addConnector(httpConnector);
fcgiConnector = new ServerConnector(server, new ServerFCGIConnectionFactory(new HttpConfiguration(), sendStatus200));
server.addConnector(fcgiConnector);
final String contextPath = "/";
context = new ServletContextHandler(server, contextPath);
final String servletPath = "/script";
FastCGIProxyServlet fcgiServlet = new FastCGIProxyServlet() {
@Override
protected String rewriteTarget(HttpServletRequest request) {
return "http://localhost:" + fcgiConnector.getLocalPort() + servletPath + request.getServletPath();
}
};
ServletHolder fcgiServletHolder = new ServletHolder(fcgiServlet);
fcgiServletHolder.setName("fcgi");
fcgiServletHolder.setInitParameter(FastCGIProxyServlet.SCRIPT_ROOT_INIT_PARAM, "/scriptRoot");
fcgiServletHolder.setInitParameter("proxyTo", "http://localhost");
fcgiServletHolder.setInitParameter(FastCGIProxyServlet.SCRIPT_PATTERN_INIT_PARAM, "(.+?\\.php)");
context.addServlet(fcgiServletHolder, "*.php");
context.addServlet(new ServletHolder(servlet), servletPath + "/*");
QueuedThreadPool clientThreads = new QueuedThreadPool();
clientThreads.setName("client");
client = new HttpClient();
client.setExecutor(clientThreads);
server.addBean(client);
server.start();
}
use of org.eclipse.jetty.client.HttpClient in project jetty.project by eclipse.
the class TestJettyOSGiBootContextAsService method testContextHandlerAsOSGiService.
/**
*/
@Test
public void testContextHandlerAsOSGiService() throws Exception {
// now test the context
HttpClient client = new HttpClient();
try {
client.start();
ContentResponse response = client.GET("http://127.0.0.1:" + TestJettyOSGiBootCore.DEFAULT_HTTP_PORT + "/acme/index.html");
assertEquals(HttpStatus.OK_200, response.getStatus());
String content = new String(response.getContent());
assertTrue(content.indexOf("<h1>Test OSGi Context</h1>") != -1);
} finally {
client.stop();
}
ServiceReference[] refs = bundleContext.getServiceReferences(ContextHandler.class.getName(), null);
assertNotNull(refs);
assertEquals(1, refs.length);
ContextHandler ch = (ContextHandler) bundleContext.getService(refs[0]);
assertEquals("/acme", ch.getContextPath());
// Stop the bundle with the ContextHandler in it and check the jetty
// Context is destroyed for it.
// TODO: think of a better way to communicate this to the test, other
// than checking stderr output
Bundle testWebBundle = TestOSGiUtil.getBundle(bundleContext, "org.eclipse.jetty.osgi.testcontext");
assertNotNull("Could not find the org.eclipse.jetty.test-jetty-osgi-context.jar bundle", testWebBundle);
assertTrue("The bundle org.eclipse.jetty.testcontext is not correctly resolved", testWebBundle.getState() == Bundle.ACTIVE);
testWebBundle.stop();
}
use of org.eclipse.jetty.client.HttpClient in project jetty.project by eclipse.
the class TestJettyOSGiBootWithJsp method testJspDump.
@Test
public void testJspDump() throws Exception {
// TestOSGiUtil.debugBundles(bundleContext);
HttpClient client = new HttpClient();
try {
client.start();
ContentResponse response = client.GET("http://127.0.0.1:" + TestJettyOSGiBootCore.DEFAULT_HTTP_PORT + "/jsp/jstl.jsp");
assertEquals(HttpStatus.OK_200, response.getStatus());
String content = new String(response.getContent());
assertTrue(content.contains("JSTL Example"));
} finally {
client.stop();
}
}
use of org.eclipse.jetty.client.HttpClient in project jetty.project by eclipse.
the class TestOSGiUtil method testHttpServiceGreetings.
protected static void testHttpServiceGreetings(BundleContext bundleContext, String protocol, int port) throws Exception {
assertActiveBundle(bundleContext, "org.eclipse.jetty.osgi.boot");
assertActiveBundle(bundleContext, "org.eclipse.jetty.osgi.httpservice");
assertActiveBundle(bundleContext, "org.eclipse.equinox.http.servlet");
// in the OSGi world this would be bad code and we should use a bundle
// tracker.
// here we purposely want to make sure that the httpService is actually
// ready.
ServiceReference sr = bundleContext.getServiceReference(HttpService.class.getName());
Assert.assertNotNull("The httpServiceOSGiBundle is started and should " + "have deployed a service reference for HttpService", sr);
HttpService http = (HttpService) bundleContext.getService(sr);
http.registerServlet("/greetings", new HttpServlet() {
private static final long serialVersionUID = 1L;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.getWriter().write("Hello");
}
}, null, null);
// now test the servlet
HttpClient client = protocol.equals("https") ? new HttpClient(newSslContextFactory()) : new HttpClient();
try {
client.start();
ContentResponse response = client.GET(protocol + "://127.0.0.1:" + port + "/greetings");
Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
String content = new String(response.getContent());
Assert.assertEquals("Hello", content);
} finally {
client.stop();
}
}
use of org.eclipse.jetty.client.HttpClient in project jetty.project by eclipse.
the class DigestPostTest method testServerWithHttpClientStreamContent.
@Test
public void testServerWithHttpClientStreamContent() throws Exception {
String srvUrl = "http://127.0.0.1:" + ((NetworkConnector) _server.getConnectors()[0]).getLocalPort() + "/test/";
HttpClient client = new HttpClient();
try {
AuthenticationStore authStore = client.getAuthenticationStore();
authStore.addAuthentication(new DigestAuthentication(new URI(srvUrl), "test", "testuser", "password"));
client.start();
String sent = IO.toString(new FileInputStream("src/test/resources/message.txt"));
Request request = client.newRequest(srvUrl);
request.method(HttpMethod.POST);
request.content(new StringContentProvider(sent));
_received = null;
request = request.timeout(5, TimeUnit.SECONDS);
ContentResponse response = request.send();
Assert.assertEquals(200, response.getStatus());
Assert.assertEquals(sent, _received);
} finally {
client.stop();
}
}
Aggregations