本文整理汇总了Java中org.eclipse.jetty.proxy.ProxyServlet类的典型用法代码示例。如果您正苦于以下问题:Java ProxyServlet类的具体用法?Java ProxyServlet怎么用?Java ProxyServlet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ProxyServlet类属于org.eclipse.jetty.proxy包,在下文中一共展示了ProxyServlet类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testConfiguredHttpsProxy
import org.eclipse.jetty.proxy.ProxyServlet; //导入依赖的package包/类
public void testConfiguredHttpsProxy() throws Exception {
File testRepo = createMyModuleRepository("testConfiguredHttpsProxy");
File emptyRepo = Files.createTempDirectory("vertx").toFile();
emptyRepo.deleteOnExit();
startRemoteServer(configureTls(createRemoteServer(testRepo)));
Server server = new Server(8081);
ServletHandler handler = new ServletHandler();
server.setHandler(handler);
handler.addServletWithMapping(ProxyServlet.class, "/").setInitParameter("maxThreads", "10");
UrlCollectorFilter urlCollector = new UrlCollectorFilter();
handler.addFilterWithMapping(new FilterHolder(urlCollector), "/*", 0);
server.start();
servers.add(server);
System.setProperty(MavenVerticleFactory.HTTP_PROXY_SYS_PROP, "http://localhost:8081");
configureRepos(emptyRepo, "https://localhost:8443/");
URL expectedHost = new URL("http://localhost:8443/");
vertx.deployVerticle("maven:my:module:1.0::my.serviceA", new DeploymentOptions(), onSuccess(id -> {
assertTrue("Was expecting " + urlCollector.requestedHosts + " to contain " + expectedHost, urlCollector.requestedHosts.contains(expectedHost));
testComplete();
}));
await();
}
示例2: testConfiguredHttpProxy
import org.eclipse.jetty.proxy.ProxyServlet; //导入依赖的package包/类
@Test
public void testConfiguredHttpProxy() throws Exception {
File testRepo = createMyModuleRepository("testConfiguredHttpProxy");
File emptyRepo = Files.createTempDirectory("vertx").toFile();
emptyRepo.deleteOnExit();
startRemoteServer(createRemoteServer(testRepo));
System.setProperty(MavenVerticleFactory.HTTP_PROXY_SYS_PROP, "http://localhost:8081");
Server server = new Server(8081);
ServletHandler handler = new ServletHandler();
server.setHandler(handler);
handler.addServletWithMapping(ProxyServlet.class, "/*").setInitParameter("maxThreads", "10");
URL expectedHost = new URL("http://localhost:8080/");
UrlCollectorFilter urlCollector = new UrlCollectorFilter();
handler.addFilterWithMapping(new FilterHolder(urlCollector), "/*", 0);
server.start();
servers.add(server);
configureRepos(emptyRepo, "http://localhost:8080/");
vertx.deployVerticle("maven:my:module:1.0::my.serviceA", new DeploymentOptions(), onSuccess(id -> {
assertTrue("Was expecting " + urlCollector.requestedHosts + " to contain " + expectedHost, urlCollector.requestedHosts.contains(expectedHost));
testComplete();
}));
await();
}
示例3: testConfiguredAuthenticatingHttpProxy
import org.eclipse.jetty.proxy.ProxyServlet; //导入依赖的package包/类
@Test
public void testConfiguredAuthenticatingHttpProxy() throws Exception {
File testRepo = createMyModuleRepository("testConfiguredAuthenticatingHttpProxy");
File emptyRepo = Files.createTempDirectory("vertx").toFile();
emptyRepo.deleteOnExit();
startRemoteServer(createRemoteServer(testRepo));
System.setProperty(MavenVerticleFactory.HTTP_PROXY_SYS_PROP, "http://username_value:[email protected]:8081");
Server server = new Server(8081);
ServletHandler handler = new ServletHandler();
server.setHandler(handler);
AuthFilter filter = AuthFilter.proxyAuthenticator("username_value", "password_value");
handler.addFilterWithMapping(new FilterHolder(filter), "/*", 0);
handler.addServletWithMapping(ProxyServlet.class, "/*").setInitParameter("maxThreads", "10");
URL expectedHost = new URL("http://localhost:8080/");
UrlCollectorFilter urlCollector = new UrlCollectorFilter();
handler.addFilterWithMapping(new FilterHolder(urlCollector), "/*", 0);
server.start();
servers.add(server);
configureRepos(emptyRepo, "http://localhost:8080/");
vertx.deployVerticle("maven:my:module:1.0::my.serviceA", new DeploymentOptions(), onSuccess(id -> {
assertTrue("Was expecting " + urlCollector.requestedHosts + " to contain " + expectedHost, urlCollector.requestedHosts.contains(expectedHost));
assertTrue(filter.authenticated.get());
testComplete();
}));
await();
}
示例4: GadgetProxyServlet
import org.eclipse.jetty.proxy.ProxyServlet; //导入依赖的package包/类
@Inject
public GadgetProxyServlet(
@Named(CoreSettings.GADGET_SERVER_HOSTNAME) final String gadgetServerHostname,
@Named(CoreSettings.GADGET_SERVER_PORT) final int gadgetServerPort,
@Named(CoreSettings.GADGET_SERVER_PATH) final String gadgetServerPath) {
this.gadgetServerHostname = gadgetServerHostname;
this.gadgetServerPort = gadgetServerPort;
this.gadgetServerPath = gadgetServerPath;
LOG.info("Starting GadgetProxyServlet for " + gadgetServerHostname + ":" + gadgetServerPort);
proxyServlet = new ProxyServlet.Transparent();
}
示例5: testDeployUsingProxy
import org.eclipse.jetty.proxy.ProxyServlet; //导入依赖的package包/类
private void testDeployUsingProxy(TestContext context, Runnable configure) throws Exception {
proxyServer = new Server(8081);
ServletHandler handler = new ServletHandler();
proxyServer.setHandler(handler);
List<JsonObject> proxiedRequests = Collections.synchronizedList(new ArrayList<>());
ServletHolder holder = new ServletHolder(new ProxyServlet() {
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
proxiedRequests.add(new JsonObject()
.put("method", request.getMethod())
.put("host", request.getHeader("Host"))
.put("requestUri", request.getRequestURL().toString()));
super.service(request, response);
}
});
holder.setInitParameter("maxThreads", "10");
handler.addServletWithMapping(holder, "/*");
proxyServer.start();
configure.run();
vertx = Vertx.vertx();
HttpServer server = new RepoBuilder().setVerticle(verticleWithMain).build();
server.listen(
8080,
context.asyncAssertSuccess(s -> {
vertx.deployVerticle("http://localhost:8080/the_verticle.zip", context.asyncAssertSuccess(id -> {
context.assertEquals(Collections.singletonList(new JsonObject()
.put("method", "GET")
.put("host", "localhost:8080")
.put("requestUri", "http://localhost:8080/the_verticle.zip")), proxiedRequests);
}));
})
);
}
示例6: run
import org.eclipse.jetty.proxy.ProxyServlet; //导入依赖的package包/类
@Override
public void run(final ExampleConfiguration configuration, final Environment environment) throws Exception {
environment.jersey().register(new ExampleResource());
final String proxyPrefix = configuration.getProxyPrefix();
final String proxyTo = configuration.getProxyTo();
final ProxyServlet.Transparent proxyServlet = new ProxyServlet.Transparent(proxyTo, proxyPrefix);
environment.servlets().addServlet("ProxyServlet", proxyServlet).addMapping(proxyPrefix + "/*");
}
示例7: addTransparentProxy
import org.eclipse.jetty.proxy.ProxyServlet; //导入依赖的package包/类
/**
* Add a transparent proxy to the servlet registry. The servlet will proxy to the
* specified URL pattern.
* For example: addTransparentProxy("/gadgets/*","http://gmodules:80/gadgets", "/gadgets")
* @param urlPattern the URL pattern for paths. Eg, '/foo', '/foo/*'.
* @param proxyTo the URL to proxy to.
* @param prefix the prefix that should be proxied.
*/
public void addTransparentProxy(String urlPattern, String proxyTo, String prefix) {
Preconditions.checkNotNull(urlPattern);
Preconditions.checkNotNull(proxyTo);
Preconditions.checkNotNull(prefix);
ServletHolder proxy = new ServletHolder(ProxyServlet.Transparent.class);
proxy.setInitParameter("proxyTo", proxyTo);
proxy.setInitParameter("prefix", prefix);
servletRegistry.add(Pair.of(urlPattern, proxy));
}