use of org.apache.qpid.server.model.Broker in project qpid-broker-j by apache.
the class QueueReportServlet method doGet.
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response, final ConfiguredObject<?> managedObject) throws IOException, ServletException {
List<String> pathInfoElements = HttpManagementUtil.getPathInfoElements(request.getServletPath(), request.getPathInfo());
Queue<?> queue;
String reportName;
if (managedObject instanceof Broker && pathInfoElements.size() == 3) {
queue = getQueueFromRequest(pathInfoElements);
reportName = pathInfoElements.get(2);
} else if (managedObject instanceof VirtualHost && pathInfoElements.size() == 2) {
queue = getQueueFromVirtualHost(pathInfoElements.get(0), (VirtualHost<?>) managedObject);
reportName = pathInfoElements.get(1);
} else {
queue = null;
reportName = null;
}
if (queue != null) {
ReportRunner<?> reportRunner = ReportRunner.createRunner(reportName, request.getParameterMap());
Object output = reportRunner.runReport(queue);
response.setContentType(reportRunner.getContentType());
if (reportRunner.isBinaryReport()) {
response.getOutputStream().write((byte[]) output);
} else {
response.getWriter().write((String) output);
}
} else {
throw new IllegalArgumentException("Invalid path is specified");
}
}
use of org.apache.qpid.server.model.Broker in project qpid-broker-j by apache.
the class ContentServlet method doGet.
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response, final ConfiguredObject<?> managedObject) throws IOException {
ConfiguredObject root = managedObject;
String pathInfo = request.getPathInfo();
if (managedObject instanceof Broker && null != pathInfo && !pathInfo.isEmpty()) {
final ConfiguredObjectFinder finder = getConfiguredObjectFinder(managedObject);
final ConfiguredObject virtualHost = finder.findObjectFromPath(pathInfo.substring(1), VirtualHost.class);
if (null == virtualHost) {
sendError(response, HttpServletResponse.SC_NOT_FOUND);
return;
} else {
root = virtualHost;
}
} else if (managedObject instanceof VirtualHost && null != pathInfo && !pathInfo.isEmpty()) {
sendError(response, HttpServletResponse.SC_BAD_REQUEST);
return;
}
final Map<String, String[]> parameters = request.getParameterMap();
Content content = _contentFactory.createContent(root, parameters);
try {
writeContent(content, request, response);
} finally {
content.release();
}
}
use of org.apache.qpid.server.model.Broker in project qpid-broker-j by apache.
the class TCPandSSLTransportTest method checkSSLExcluded.
private void checkSSLExcluded(String clientProtocol, final Transport... transports) throws Exception {
KeyStore keyStore = KeyStore.getInstance("JKS");
keyStore.load(new ByteArrayInputStream(DatatypeConverter.parseBase64Binary(keystoreString)), "password".toCharArray());
final SSLContext sslContext = SSLContext.getInstance("TLS");
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(keyStore, "password".toCharArray());
sslContext.init(kmf.getKeyManagers(), null, null);
final AmqpPort<?> port = mock(AmqpPort.class);
when(port.getPort()).thenReturn(0);
when(port.getName()).thenReturn("testAmqp");
when(port.getNetworkBufferSize()).thenReturn(64 * 1024);
when(port.canAcceptNewConnection(any(SocketAddress.class))).thenReturn(true);
when(port.getThreadPoolSize()).thenReturn(2);
when(port.getNumberOfSelectors()).thenReturn(1);
when(port.getSSLContext()).thenReturn(sslContext);
when(port.getContextValue(Long.class, AmqpPort.PORT_AMQP_THREAD_POOL_KEEP_ALIVE_TIMEOUT)).thenReturn(1L);
when(port.getContextValue(Integer.class, AmqpPort.PORT_AMQP_ACCEPT_BACKLOG)).thenReturn(AmqpPort.DEFAULT_PORT_AMQP_ACCEPT_BACKLOG);
when(port.getProtocolHandshakeTimeout()).thenReturn(AmqpPort.DEFAULT_PROTOCOL_HANDSHAKE_TIMEOUT);
ObjectMapper mapper = new ObjectMapper();
JavaType type = mapper.getTypeFactory().constructCollectionType(List.class, String.class);
List<String> whiteList = mapper.readValue(Broker.DEFAULT_SECURITY_TLS_PROTOCOL_WHITE_LIST, type);
List<String> blackList = mapper.readValue(Broker.DEFAULT_SECURITY_TLS_PROTOCOL_BLACK_LIST, type);
when(port.getTlsProtocolBlackList()).thenReturn(blackList);
when(port.getTlsProtocolWhiteList()).thenReturn(whiteList);
final Broker broker = mock(Broker.class);
when(broker.getEventLogger()).thenReturn(mock(EventLogger.class));
when(port.getParent()).thenReturn(broker);
TCPandSSLTransport transport = new TCPandSSLTransport(new HashSet<>(Arrays.asList(transports)), port, new HashSet<>(Arrays.asList(Protocol.AMQP_0_8, Protocol.AMQP_0_9, Protocol.AMQP_0_9_1, Protocol.AMQP_0_10, Protocol.AMQP_1_0)), Protocol.AMQP_0_9_1);
transport.start();
SSLContext clientContext = SSLContext.getInstance("TLS");
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(keyStore);
clientContext.init(null, tmf.getTrustManagers(), null);
try (SSLSocket sslSocket = (SSLSocket) clientContext.getSocketFactory().createSocket(InetAddress.getLoopbackAddress(), transport.getAcceptingPort())) {
sslSocket.setEnabledProtocols(new String[] { clientProtocol });
sslSocket.startHandshake();
} finally {
transport.close();
}
}
Aggregations