use of org.eclipse.jetty.server.Connector in project camel by apache.
the class ExplicitHttpsSslContextParametersRouteTest method createRouteBuilder.
// END SNIPPET: e2
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
// START SNIPPET: e1
// create SSL select channel connectors for port 9080 and 9090
Map<Integer, Connector> connectors = new HashMap<Integer, Connector>();
connectors.put(port1, createSslSocketConnector(getContext(), port1));
connectors.put(port2, createSslSocketConnector(getContext(), port2));
JettyHttpComponent jetty = getContext().getComponent("jetty", JettyHttpComponent.class);
jetty.setSslSocketConnectors(connectors);
// END SNIPPET: e1
from("jetty:https://localhost:" + port1 + "/test").to("mock:a");
Processor proc = new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getOut().setBody("<b>Hello World</b>");
}
};
from("jetty:https://localhost:" + port1 + "/hello").process(proc);
from("jetty:https://localhost:" + port2 + "/test").to("mock:b");
}
};
}
use of org.eclipse.jetty.server.Connector in project jetty-runtime by GoogleCloudPlatform.
the class DeploymentCheck method lifeCycleStarted.
@Override
public void lifeCycleStarted(LifeCycle bean) {
if (bean instanceof Server) {
Server server = (Server) bean;
Connector[] connectors = server.getConnectors();
if (connectors == null || connectors.length == 0) {
server.dumpStdErr();
throw new IllegalStateException("No Connector");
} else if (!Arrays.stream(connectors).allMatch(Connector::isStarted)) {
server.dumpStdErr();
throw new IllegalStateException("Connector not started");
}
ContextHandler context = server.getChildHandlerByClass(ContextHandler.class);
if (context == null || !context.isAvailable()) {
server.dumpStdErr();
throw new IllegalStateException("No Available Context");
}
}
}
use of org.eclipse.jetty.server.Connector in project http-request by kevinsawicki.
the class ServerTestCase method setUp.
/**
* Set up server with handler
*
* @param handler
* @return port
* @throws Exception
*/
public static String setUp(final Handler handler) throws Exception {
server = new Server();
if (handler != null)
server.setHandler(handler);
Connector connector = new SelectChannelConnector();
connector.setPort(0);
server.setConnectors(new Connector[] { connector });
server.start();
proxy = new Server();
Connector proxyConnector = new SelectChannelConnector();
proxyConnector.setPort(0);
proxy.setConnectors(new Connector[] { proxyConnector });
ServletHandler proxyHandler = new ServletHandler();
RequestHandler proxyCountingHandler = new RequestHandler() {
@Override
public void handle(Request request, HttpServletResponse response) {
proxyHitCount.incrementAndGet();
String auth = request.getHeader("Proxy-Authorization");
auth = auth.substring(auth.indexOf(' ') + 1);
try {
auth = B64Code.decode(auth, CHARSET_UTF8);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
int colon = auth.indexOf(':');
proxyUser.set(auth.substring(0, colon));
proxyPassword.set(auth.substring(colon + 1));
request.setHandled(false);
}
};
HandlerList handlerList = new HandlerList();
handlerList.addHandler(proxyCountingHandler);
handlerList.addHandler(proxyHandler);
proxy.setHandler(handlerList);
ServletHolder proxyHolder = proxyHandler.addServletWithMapping("org.eclipse.jetty.servlets.ProxyServlet", "/");
proxyHolder.setAsyncSupported(true);
proxy.start();
proxyPort = proxyConnector.getLocalPort();
return "http://localhost:" + connector.getLocalPort();
}
use of org.eclipse.jetty.server.Connector in project jetty.project by eclipse.
the class WebInfConfiguration method getCanonicalNameForWebAppTmpDir.
/**
* Create a canonical name for a webapp temp directory.
* <p>
* The form of the name is:
*
* <pre>"jetty-"+host+"-"+port+"-"+resourceBase+"-_"+context+"-"+virtualhost+"-"+randomdigits+".dir"</pre>
*
* host and port uniquely identify the server
* context and virtual host uniquely identify the webapp
* randomdigits ensure every tmp directory is unique
*
* @param context the context to get the canonical name from
* @return the canonical name for the webapp temp directory
*/
public static String getCanonicalNameForWebAppTmpDir(WebAppContext context) {
StringBuffer canonicalName = new StringBuffer();
canonicalName.append("jetty-");
//get the host and the port from the first connector
Server server = context.getServer();
if (server != null) {
Connector[] connectors = context.getServer().getConnectors();
if (connectors.length > 0) {
//Get the host
String host = null;
int port = 0;
if (connectors != null && (connectors[0] instanceof NetworkConnector)) {
NetworkConnector connector = (NetworkConnector) connectors[0];
host = connector.getHost();
port = connector.getLocalPort();
if (port < 0)
port = connector.getPort();
}
if (host == null)
host = "0.0.0.0";
canonicalName.append(host);
//Get the port
canonicalName.append("-");
//if not available (eg no connectors or connector not started),
//try getting one that was configured.
canonicalName.append(port);
canonicalName.append("-");
}
}
//Resource base
try {
Resource resource = context.getBaseResource();
if (resource == null) {
if (context.getWar() == null || context.getWar().length() == 0)
throw new IllegalStateException("No resourceBase or war set for context");
// Set dir or WAR
resource = context.newResource(context.getWar());
}
String tmp = URIUtil.decodePath(resource.getURL().getPath());
if (tmp.endsWith("/"))
tmp = tmp.substring(0, tmp.length() - 1);
if (tmp.endsWith("!"))
tmp = tmp.substring(0, tmp.length() - 1);
//get just the last part which is the filename
int i = tmp.lastIndexOf("/");
canonicalName.append(tmp.substring(i + 1, tmp.length()));
canonicalName.append("-");
} catch (Exception e) {
LOG.warn("Can't generate resourceBase as part of webapp tmp dir name: " + e);
LOG.debug(e);
}
//Context name
String contextPath = context.getContextPath();
contextPath = contextPath.replace('/', '_');
contextPath = contextPath.replace('\\', '_');
canonicalName.append(contextPath);
//Virtual host (if there is one)
canonicalName.append("-");
String[] vhosts = context.getVirtualHosts();
if (vhosts == null || vhosts.length <= 0)
canonicalName.append("any");
else
canonicalName.append(vhosts[0]);
// sanitize
for (int i = 0; i < canonicalName.length(); i++) {
char c = canonicalName.charAt(i);
if (!Character.isJavaIdentifierPart(c) && "-.".indexOf(c) < 0)
canonicalName.setCharAt(i, '.');
}
canonicalName.append("-");
return canonicalName.toString();
}
use of org.eclipse.jetty.server.Connector in project jetty.project by eclipse.
the class DebugHandler method doStop.
/* (non-Javadoc)
* @see org.eclipse.jetty.server.handler.HandlerWrapper#doStop()
*/
@Override
protected void doStop() throws Exception {
super.doStop();
_print.close();
for (Connector connector : getServer().getConnectors()) if (connector instanceof AbstractConnector)
((AbstractConnector) connector).removeBean(this);
}
Aggregations