use of io.undertow.server.HttpHandler in project camel by apache.
the class CamelRootHandler method add.
public synchronized void add(String path, String[] methods, boolean prefixMatch, HttpHandler handler) {
String basePath = getBasePath(path);
HttpHandler basePathHandler = pathHandler.getHandler(basePath);
CamelMethodHandler targetHandler;
if (path.contains("{")) {
// Adding a handler for the template path
String relativePath = path.substring(basePath.length());
if (basePathHandler instanceof CamelPathTemplateHandler) {
CamelPathTemplateHandler templateHandler = (CamelPathTemplateHandler) basePathHandler;
targetHandler = templateHandler.get(relativePath);
if (targetHandler == null) {
targetHandler = new CamelMethodHandler();
templateHandler.add(relativePath, targetHandler);
}
} else {
CamelPathTemplateHandler templateHandler;
if (basePathHandler instanceof CamelMethodHandler) {
// A static path handler is already set for the base path. Use it as a default handler
templateHandler = new CamelPathTemplateHandler((CamelMethodHandler) basePathHandler);
} else if (basePathHandler == null) {
templateHandler = new CamelPathTemplateHandler(new CamelMethodHandler());
} else {
throw new IllegalArgumentException(String.format("Unsupported handler '%s' was found", basePathHandler));
}
targetHandler = new CamelMethodHandler();
templateHandler.add(relativePath, targetHandler);
pathHandler.addPrefixPath(basePath, templateHandler);
}
} else {
// Adding a handler for the static path
if (basePathHandler instanceof CamelPathTemplateHandler) {
CamelPathTemplateHandler templateHandler = (CamelPathTemplateHandler) basePathHandler;
if (prefixMatch) {
targetHandler = templateHandler.getDefault();
} else {
throw new IllegalArgumentException(String.format("Duplicate handlers on a path '%s'", path));
}
} else {
if (basePathHandler instanceof CamelMethodHandler) {
targetHandler = (CamelMethodHandler) basePathHandler;
} else if (basePathHandler == null) {
targetHandler = new CamelMethodHandler();
if (prefixMatch) {
pathHandler.addPrefixPath(basePath, targetHandler);
} else {
pathHandler.addExactPath(basePath, targetHandler);
}
} else {
throw new IllegalArgumentException(String.format("Unsupported handler '%s' was found", basePathHandler));
}
}
}
if (methods != null && methods.length != 0) {
targetHandler.add(methods, handler);
} else {
targetHandler.addDefault(handler);
}
}
use of io.undertow.server.HttpHandler in project syncany by syncany.
the class WebServer method initServer.
private void initServer(DaemonConfigTO daemonConfigTO) throws Exception {
WebServerTO webServerConfig = daemonConfigTO.getWebServer();
// Bind address and port
String bindAddress = webServerConfig.getBindAddress();
int bindPort = webServerConfig.getBindPort();
// Users (incl. CLI user!)
List<UserTO> users = readWebServerUsers(daemonConfigTO);
IdentityManager identityManager = new MapIdentityManager(users);
// (Re-)generate keypair/certificate (if requested)
boolean certificateAutoGenerate = webServerConfig.isCertificateAutoGenerate();
String certificateCommonName = webServerConfig.getCertificateCommonName();
if (certificateAutoGenerate && certificateCommonNameChanged(certificateCommonName)) {
generateNewKeyPairAndCertificate(certificateCommonName);
}
// Set up the handlers for WebSocket, REST and the web interface
HttpHandler pathHttpHandler = path().addPrefixPath(API_ENDPOINT_WS_XML, websocket(new InternalWebSocketHandler(this, certificateCommonName, RequestFormatType.XML))).addPrefixPath(API_ENDPOINT_WS_JSON, websocket(new InternalWebSocketHandler(this, certificateCommonName, RequestFormatType.JSON))).addPrefixPath(API_ENDPOINT_REST_XML, new InternalRestHandler(this, RequestFormatType.XML)).addPrefixPath(API_ENDPOINT_REST_JSON, new InternalRestHandler(this, RequestFormatType.JSON)).addPrefixPath("/", new InternalWebInterfaceHandler());
// Add some security spices
HttpHandler securityPathHttpHandler = addSecurity(pathHttpHandler, identityManager);
SSLContext sslContext = UserConfig.createUserSSLContext();
// And go for it!
webServer = Undertow.builder().addHttpsListener(bindPort, bindAddress, sslContext).setHandler(securityPathHttpHandler).build();
logger.log(Level.INFO, "Initialized web server.");
}
use of io.undertow.server.HttpHandler in project wildfly by wildfly.
the class ModClusterUndertowDeploymentProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
// Add mod_cluster-undertow integration service (jboss.modcluster.undertow) as a web deployment dependency
deploymentUnit.addToAttachmentList(Attachments.WEB_DEPENDENCIES, UndertowEventHandlerAdapterBuilder.SERVICE_NAME);
// Request count wrapping
if (isMetricEnabled(RequestCountLoadMetric.class)) {
deploymentUnit.addToAttachmentList(UndertowAttachments.UNDERTOW_INITIAL_HANDLER_CHAIN_WRAPPERS, new HandlerWrapper() {
@Override
public HttpHandler wrap(final HttpHandler handler) {
return new RequestCountHttpHandler(handler);
}
});
}
// Bytes Sent wrapping
if (isMetricEnabled(SendTrafficLoadMetric.class)) {
deploymentUnit.addToAttachmentList(UndertowAttachments.UNDERTOW_INITIAL_HANDLER_CHAIN_WRAPPERS, new HandlerWrapper() {
@Override
public HttpHandler wrap(final HttpHandler handler) {
return new BytesSentHttpHandler(handler);
}
});
}
// Bytes Received wrapping
if (isMetricEnabled(ReceiveTrafficLoadMetric.class)) {
deploymentUnit.addToAttachmentList(UndertowAttachments.UNDERTOW_INITIAL_HANDLER_CHAIN_WRAPPERS, new HandlerWrapper() {
@Override
public HttpHandler wrap(final HttpHandler handler) {
return new BytesReceivedHttpHandler(handler);
}
});
}
// Busyness thread setup actions
if (isMetricEnabled(BusyConnectorsLoadMetric.class)) {
deploymentUnit.addToAttachmentList(UndertowAttachments.UNDERTOW_OUTER_HANDLER_CHAIN_WRAPPERS, new HandlerWrapper() {
@Override
public HttpHandler wrap(final HttpHandler handler) {
return new RunningRequestsHttpHandler(handler);
}
});
}
}
use of io.undertow.server.HttpHandler in project wildfly by wildfly.
the class UndertowHostTestCase method findContext.
@Test
public void findContext() {
Deployment deployment = mock(Deployment.class);
DeploymentInfo info = new DeploymentInfo();
String expectedPath = "";
info.setContextPath(expectedPath);
HttpHandler handler = mock(HttpHandler.class);
when(deployment.getDeploymentInfo()).thenReturn(info);
this.undertowHost.registerDeployment(deployment, handler);
Context result = this.host.findContext(expectedPath);
assertSame(this.host, result.getHost());
assertSame(expectedPath, result.getPath());
result = this.host.findContext("unknown");
assertNull(result);
}
use of io.undertow.server.HttpHandler in project wildfly by wildfly.
the class UndertowHostTestCase method getContexts.
@Test
public void getContexts() {
Deployment deployment = mock(Deployment.class);
DeploymentInfo info = new DeploymentInfo();
String expectedPath = "";
info.setContextPath(expectedPath);
HttpHandler handler = mock(HttpHandler.class);
when(deployment.getDeploymentInfo()).thenReturn(info);
this.undertowHost.registerDeployment(deployment, handler);
Iterator<Context> result = this.host.getContexts().iterator();
assertTrue(result.hasNext());
Context context = result.next();
assertSame(this.host, context.getHost());
assertSame(expectedPath, context.getPath());
assertFalse(result.hasNext());
}
Aggregations