use of io.undertow.server.handlers.PeerNameResolvingHandler in project wildfly by wildfly.
the class ListenerAdd method performRuntime.
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
final PathAddress address = context.getCurrentAddress();
final PathAddress parent = address.getParent();
final String name = context.getCurrentAddressValue();
final String bindingRef = ListenerResourceDefinition.SOCKET_BINDING.resolveModelAttribute(context, model).asString();
final String workerName = ListenerResourceDefinition.WORKER.resolveModelAttribute(context, model).asString();
final String bufferPoolName = ListenerResourceDefinition.BUFFER_POOL.resolveModelAttribute(context, model).asString();
final boolean enabled = ListenerResourceDefinition.ENABLED.resolveModelAttribute(context, model).asBoolean();
final boolean peerHostLookup = ListenerResourceDefinition.RESOLVE_PEER_ADDRESS.resolveModelAttribute(context, model).asBoolean();
final boolean secure = ListenerResourceDefinition.SECURE.resolveModelAttribute(context, model).asBoolean();
OptionMap listenerOptions = OptionList.resolveOptions(context, model, ListenerResourceDefinition.LISTENER_OPTIONS);
OptionMap socketOptions = OptionList.resolveOptions(context, model, ListenerResourceDefinition.SOCKET_OPTIONS);
String serverName = parent.getLastElement().getValue();
final ServiceName listenerServiceName = UndertowService.listenerName(name);
final ListenerService service = createService(name, serverName, context, model, listenerOptions, socketOptions);
if (peerHostLookup) {
service.addWrapperHandler(new HandlerWrapper() {
@Override
public HttpHandler wrap(HttpHandler handler) {
return new PeerNameResolvingHandler(handler);
}
});
}
service.setEnabled(enabled);
if (secure) {
service.addWrapperHandler(MarkSecureHandler.WRAPPER);
}
List<String> disallowedMethods = ListenerResourceDefinition.DISALLOWED_METHODS.unwrap(context, model);
if (!disallowedMethods.isEmpty()) {
final Set<HttpString> methodSet = new HashSet<>();
for (String i : disallowedMethods) {
methodSet.add(new HttpString(i.trim()));
}
service.addWrapperHandler(new HandlerWrapper() {
@Override
public HttpHandler wrap(HttpHandler handler) {
return new DisallowedMethodsHandler(handler, methodSet);
}
});
}
final ServiceName socketBindingServiceName = context.getCapabilityServiceName(ListenerResourceDefinition.SOCKET_CAPABILITY, bindingRef, SocketBinding.class);
final ServiceName workerServiceName = context.getCapabilityServiceName(ListenerResourceDefinition.IO_WORKER_CAPABILITY, workerName, XnioWorker.class);
final ServiceName bufferPoolServiceName = context.getCapabilityServiceName(ListenerResourceDefinition.IO_BUFFER_POOL_CAPABILITY, bufferPoolName, Pool.class);
final ServiceBuilder<? extends UndertowListener> serviceBuilder = context.getServiceTarget().addService(listenerServiceName, service);
serviceBuilder.addDependency(workerServiceName, XnioWorker.class, service.getWorker()).addDependency(socketBindingServiceName, SocketBinding.class, service.getBinding()).addDependency(bufferPoolServiceName, (Injector) service.getBufferPool()).addDependency(UndertowService.SERVER.append(serverName), Server.class, service.getServerService()).addAliases(ListenerResourceDefinition.LISTENER_CAPABILITY.getCapabilityServiceName(name));
configureAdditionalDependencies(context, serviceBuilder, model, service);
serviceBuilder.install();
}
Aggregations