use of org.apache.qpid.server.model.port.HttpPort in project qpid-broker-j by apache.
the class HttpManagement method createConnector.
private ServerConnector createConnector(final HttpPort<?> port, final Server server) {
port.setPortManager(this);
if (port.getState() != State.ACTIVE) {
// TODO - RG - probably does nothing
port.startAsync();
}
HttpConnectionFactory httpConnectionFactory = new HttpConnectionFactory();
httpConnectionFactory.getHttpConfiguration().setSendServerVersion(false);
httpConnectionFactory.getHttpConfiguration().setSendXPoweredBy(false);
HttpConfiguration.Customizer requestAttributeCustomizer = (connector, httpConfiguration, request) -> HttpManagementUtil.getPortAttributeAction(port).performAction(request);
httpConnectionFactory.getHttpConfiguration().addCustomizer(requestAttributeCustomizer);
httpConnectionFactory.getHttpConfiguration().addCustomizer(new SecureRequestCustomizer());
ConnectionFactory[] connectionFactories;
Collection<Transport> transports = port.getTransports();
if (!transports.contains(Transport.SSL)) {
connectionFactories = new ConnectionFactory[] { httpConnectionFactory };
} else if (transports.contains(Transport.SSL)) {
SslContextFactory sslContextFactory = getSslContextFactory(port);
ConnectionFactory sslConnectionFactory;
if (port.getTransports().contains(Transport.TCP)) {
sslConnectionFactory = new TlsOrPlainConnectionFactory(sslContextFactory, httpConnectionFactory.getProtocol());
} else {
sslConnectionFactory = new SslConnectionFactory(sslContextFactory, httpConnectionFactory.getProtocol());
}
connectionFactories = new ConnectionFactory[] { sslConnectionFactory, httpConnectionFactory };
} else {
throw new IllegalArgumentException("Unexpected transport on port " + port.getName() + ":" + transports);
}
ServerConnector connector = new ServerConnector(server, new QBBTrackingThreadPool(port.getThreadPoolMaximum(), port.getThreadPoolMinimum()), null, null, port.getDesiredNumberOfAcceptors(), port.getDesiredNumberOfSelectors(), connectionFactories) {
@Override
public void open() throws IOException {
try {
super.open();
} catch (BindException e) {
InetSocketAddress addr = getHost() == null ? new InetSocketAddress(getPort()) : new InetSocketAddress(getHost(), getPort());
throw new PortBindFailureException(addr);
}
}
};
connector.setAcceptQueueSize(port.getAcceptBacklogSize());
String bindingAddress = port.getBindingAddress();
if (bindingAddress != null && !bindingAddress.trim().equals("") && !bindingAddress.trim().equals("*")) {
connector.setHost(bindingAddress.trim());
}
connector.setPort(port.getPort());
if (transports.contains(Transport.SSL)) {
connector.addBean(new SslHandshakeListener() {
@Override
public void handshakeFailed(final Event event, final Throwable failure) {
SSLEngine sslEngine = event.getSSLEngine();
if (LOGGER.isDebugEnabled()) {
LOGGER.info("TLS handshake failed: host='{}', port={}", sslEngine.getPeerHost(), sslEngine.getPeerPort(), failure);
} else {
LOGGER.info("TLS handshake failed: host='{}', port={}: {}", sslEngine.getPeerHost(), sslEngine.getPeerPort(), String.valueOf(failure));
}
}
});
}
int acceptors = connector.getAcceptors();
int selectors = connector.getSelectorManager().getSelectorCount();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Created connector for http port {} with maxThreads={}, minThreads={}, acceptors={}, selectors={}, acceptBacklog={}", port.getName(), port.getThreadPoolMaximum(), port.getThreadPoolMinimum(), acceptors, selectors, port.getAcceptBacklogSize());
}
int requiredNumberOfConnections = acceptors + 2 * selectors + 1;
if (port.getThreadPoolMaximum() < requiredNumberOfConnections) {
throw new IllegalConfigurationException(String.format("Insufficient number of threads is configured on http port '%s': max=%d < needed(acceptors=%d + selectors=2*%d + request=1)", port.getName(), port.getThreadPoolMaximum(), acceptors, selectors));
}
return connector;
}
use of org.apache.qpid.server.model.port.HttpPort in project qpid-broker-j by apache.
the class OAuth2InteractiveAuthenticatorTest method createMockRequest.
private HttpServletRequest createMockRequest(String host, String path, final Map<String, String> query, Map<String, Object> sessionAttributes) throws IOException {
final HttpServletRequest mockRequest = mock(HttpServletRequest.class);
UUID portId = UUID.randomUUID();
HttpPort port = mock(HttpPort.class);
when(mockRequest.getAttribute(eq("org.apache.qpid.server.model.Port"))).thenReturn(port);
when(port.getId()).thenReturn(portId);
when(mockRequest.getParameterNames()).thenReturn(Collections.enumeration(query.keySet()));
doAnswer(new Answer() {
@Override
public Object answer(final InvocationOnMock invocationOnMock) throws Throwable {
final Object[] arguments = invocationOnMock.getArguments();
assertEquals("Unexpected number of arguments", 1, arguments.length);
final String paramName = (String) arguments[0];
return new String[] { query.get(paramName) };
}
}).when(mockRequest).getParameterValues(any(String.class));
when(mockRequest.isSecure()).thenReturn(false);
Map<String, Object> originalAttrs = new HashMap<>(sessionAttributes);
sessionAttributes.clear();
for (Map.Entry<String, Object> entry : originalAttrs.entrySet()) {
sessionAttributes.put(HttpManagementUtil.getRequestSpecificAttributeName(entry.getKey(), mockRequest), entry.getValue());
}
final HttpSession mockHttpSession = createMockHttpSession(sessionAttributes);
when(mockRequest.getSession()).thenReturn(mockHttpSession);
when(mockRequest.getServletPath()).thenReturn("");
when(mockRequest.getPathInfo()).thenReturn(path);
final StringBuffer url = new StringBuffer(host + path);
when(mockRequest.getRequestURL()).thenReturn(url);
when(mockRequest.getRemoteHost()).thenReturn(TEST_REMOTE_HOST);
when(mockRequest.getRemotePort()).thenReturn(TEST_REMOTE_PORT);
return mockRequest;
}
use of org.apache.qpid.server.model.port.HttpPort in project qpid-broker-j by apache.
the class HttpManagement method logOperationalListenMessages.
private void logOperationalListenMessages() {
for (Map.Entry<HttpPort<?>, ServerConnector> portConnector : _portConnectorMap.entrySet()) {
HttpPort<?> port = portConnector.getKey();
NetworkConnector connector = portConnector.getValue();
logOperationalListenMessages(port, connector.getLocalPort());
}
}
use of org.apache.qpid.server.model.port.HttpPort in project qpid-broker-j by apache.
the class HttpManagement method doStart.
@StateTransition(currentState = { State.UNINITIALIZED, State.ERRORED }, desiredState = State.ACTIVE)
@SuppressWarnings("unused")
private ListenableFuture<Void> doStart() {
Collection<HttpPort<?>> httpPorts = getEligibleHttpPorts(getBroker().getPorts());
if (httpPorts.isEmpty()) {
LOGGER.warn("HttpManagement plugin is configured but no suitable HTTP ports are available.");
} else {
getBroker().getEventLogger().message(ManagementConsoleMessages.STARTUP(OPERATIONAL_LOGGING_NAME));
_server = createServer(httpPorts);
try {
_server.start();
logOperationalListenMessages();
} catch (PortBindFailureException e) {
getBroker().getEventLogger().message(PortMessages.BIND_FAILED("HTTP", e.getAddress().getPort()));
throw e;
} catch (Exception e) {
throw new ServerScopedRuntimeException("Failed to start HTTP management on ports : " + httpPorts, e);
}
getBroker().getEventLogger().message(ManagementConsoleMessages.READY(OPERATIONAL_LOGGING_NAME));
}
setState(State.ACTIVE);
return Futures.immediateFuture(null);
}
Aggregations