Search in sources :

Example 1 with ManagementException

use of org.apache.qpid.server.management.plugin.ManagementException in project qpid-broker-j by apache.

the class RestServlet method doDelete.

@Override
protected void doDelete(final HttpServletRequest httpServletRequest, final HttpServletResponse httpServletResponse, final ConfiguredObject<?> managedObject) throws IOException {
    try {
        final ManagementRequest request = new ServletManagementRequest(managedObject, httpServletRequest);
        final ManagementController controller = getManagementController();
        final ManagementResponse response = controller.handleDelete(request);
        sendResponse(request, response, httpServletRequest, httpServletResponse, controller);
    } catch (ManagementException e) {
        sendResponse(e, httpServletRequest, httpServletResponse);
    }
}
Also used : ManagementRequest(org.apache.qpid.server.management.plugin.ManagementRequest) ManagementException(org.apache.qpid.server.management.plugin.ManagementException) ManagementResponse(org.apache.qpid.server.management.plugin.ManagementResponse) ManagementController(org.apache.qpid.server.management.plugin.ManagementController)

Example 2 with ManagementException

use of org.apache.qpid.server.management.plugin.ManagementException in project qpid-broker-j by apache.

the class RestServlet method doPut.

@Override
protected void doPut(final HttpServletRequest httpServletRequest, final HttpServletResponse httpServletResponse, final ConfiguredObject<?> managedObject) throws IOException {
    try {
        final ManagementRequest request = new ServletManagementRequest(managedObject, httpServletRequest);
        final ManagementController controller = getManagementController();
        final ManagementResponse response = controller.handlePut(request);
        sendResponse(request, response, httpServletRequest, httpServletResponse, controller);
    } catch (ManagementException e) {
        sendResponse(e, httpServletRequest, httpServletResponse);
    }
}
Also used : ManagementRequest(org.apache.qpid.server.management.plugin.ManagementRequest) ManagementException(org.apache.qpid.server.management.plugin.ManagementException) ManagementResponse(org.apache.qpid.server.management.plugin.ManagementResponse) ManagementController(org.apache.qpid.server.management.plugin.ManagementController)

Example 3 with ManagementException

use of org.apache.qpid.server.management.plugin.ManagementException in project qpid-broker-j by apache.

the class RestServlet method doGet.

@Override
protected void doGet(final HttpServletRequest httpServletRequest, final HttpServletResponse httpServletResponse, final ConfiguredObject<?> managedObject) throws IOException {
    try {
        final ManagementRequest request = new ServletManagementRequest(managedObject, httpServletRequest);
        final ManagementController controller = getManagementController();
        final ManagementResponse response = controller.handleGet(request);
        sendResponse(request, response, httpServletRequest, httpServletResponse, controller);
    } catch (ManagementException e) {
        sendResponse(e, httpServletRequest, httpServletResponse);
    }
}
Also used : ManagementRequest(org.apache.qpid.server.management.plugin.ManagementRequest) ManagementException(org.apache.qpid.server.management.plugin.ManagementException) ManagementResponse(org.apache.qpid.server.management.plugin.ManagementResponse) ManagementController(org.apache.qpid.server.management.plugin.ManagementController)

Example 4 with ManagementException

use of org.apache.qpid.server.management.plugin.ManagementException in project qpid-broker-j by apache.

the class BindingController method delete.

@Override
public int delete(final ConfiguredObject<?> root, final List<String> path, final Map<String, List<String>> parameters) throws ManagementException {
    if (path.contains("*")) {
        throw createBadRequestManagementException("Wildcards in path are not supported for delete requests");
    }
    final Collection<String> hierarchy = _managementController.getCategoryHierarchy(root, getCategory());
    if (path.size() < hierarchy.size() - 2) {
        throw createBadRequestManagementException(String.format("Cannot delete binding for path %s", String.join("/", path)));
    }
    final String bindingName = path.size() == hierarchy.size() ? path.get(hierarchy.size() - 1) : null;
    final String queueName = path.get(hierarchy.size() - 2);
    final List<String> ids = parameters.get(GenericLegacyConfiguredObject.ID);
    final List<String> exchangePath = path.subList(0, hierarchy.size() - 2);
    final LegacyConfiguredObject exchange = getNextVersionObject(root, exchangePath, ExchangeController.TYPE);
    final AtomicInteger counter = new AtomicInteger();
    if (ids != null && !ids.isEmpty()) {
        @SuppressWarnings("unchecked") Collection<Binding> bindings = (Collection<Binding>) exchange.getAttribute("bindings");
        if (bindings != null) {
            bindings.stream().filter(b -> ids.contains(String.valueOf(generateBindingId(exchange, b.getDestination(), b.getBindingKey())))).forEach(b -> {
                Map<String, Object> params = new LinkedHashMap<>();
                params.put("bindingKey", b.getBindingKey());
                params.put("destination", b.getDestination());
                ManagementResponse r = exchange.invoke("unbind", params, true);
                if (Boolean.TRUE.equals(r.getBody())) {
                    counter.incrementAndGet();
                }
            });
        }
    } else if (bindingName != null) {
        Map<String, Object> params = new LinkedHashMap<>();
        params.put("bindingKey", bindingName);
        params.put("destination", queueName);
        ManagementResponse response = exchange.invoke("unbind", params, true);
        if (Boolean.TRUE.equals(response.getBody())) {
            counter.incrementAndGet();
        }
    } else {
        throw createBadRequestManagementException("Only deletion by binding full path or ids is supported");
    }
    return counter.get();
}
Also used : Binding(org.apache.qpid.server.model.Binding) ManagementException.createBadRequestManagementException(org.apache.qpid.server.management.plugin.ManagementException.createBadRequestManagementException) ManagementException(org.apache.qpid.server.management.plugin.ManagementException) GenericLegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.GenericLegacyConfiguredObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ManagementController(org.apache.qpid.server.management.plugin.ManagementController) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) CategoryController(org.apache.qpid.server.management.plugin.controller.CategoryController) Binding(org.apache.qpid.server.model.Binding) ControllerManagementResponse(org.apache.qpid.server.management.plugin.controller.ControllerManagementResponse) Collection(java.util.Collection) HttpServletResponse(javax.servlet.http.HttpServletResponse) State(org.apache.qpid.server.model.State) ManagementException.createInternalServerErrorManagementException(org.apache.qpid.server.management.plugin.ManagementException.createInternalServerErrorManagementException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) LegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject) ResponseType(org.apache.qpid.server.management.plugin.ResponseType) List(java.util.List) Stream(java.util.stream.Stream) ManagementResponse(org.apache.qpid.server.management.plugin.ManagementResponse) LegacyManagementController(org.apache.qpid.server.management.plugin.controller.LegacyManagementController) Collections(java.util.Collections) LinkedHashMap(java.util.LinkedHashMap) GenericLegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.GenericLegacyConfiguredObject) LegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ControllerManagementResponse(org.apache.qpid.server.management.plugin.controller.ControllerManagementResponse) ManagementResponse(org.apache.qpid.server.management.plugin.ManagementResponse) Collection(java.util.Collection) GenericLegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.GenericLegacyConfiguredObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) LegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 5 with ManagementException

use of org.apache.qpid.server.management.plugin.ManagementException in project qpid-broker-j by apache.

the class LegacyCategoryController_v8_0Test method testCreatePortWithSetAllowDenyTlsProtocolSettings.

@Test
public void testCreatePortWithSetAllowDenyTlsProtocolSettings() {
    final List<String> path = Arrays.asList("port", PORT_NAME);
    final Map<String, String> oldContext = new HashMap<>();
    oldContext.put(OLD_CONTEXT_TLS_PROTOCOL_WHITE_LIST, PROTOCOL_ALLOW_LIST);
    oldContext.put(OLD_CONTEXT_TLS_PROTOCOL_BLACK_LIST, PROTOCOL_DENY_LIST);
    final Map<String, Object> attributes = new HashMap<>();
    attributes.put(ATTRIBUTE_NAME, PORT_NAME);
    attributes.put(ATTRIBUTE_CONTEXT, oldContext);
    attributes.put("type", "AMQP");
    final Map<String, String> newVersionContext = new HashMap<>();
    newVersionContext.put(NEW_CONTEXT_TLS_PROTOCOL_ALLOW_LIST, PROTOCOL_ALLOW_LIST);
    newVersionContext.put(NEW_CONTEXT_TLS_PROTOCOL_DENY_LIST, PROTOCOL_DENY_LIST);
    Map<String, Object> newAttributes = new HashMap<>();
    newAttributes.put(ATTRIBUTE_NAME, PORT_NAME);
    newAttributes.put(ATTRIBUTE_CONTEXT, newVersionContext);
    newAttributes.put("type", "AMQP");
    LegacyConfiguredObject newVersionPort = createNewVersionPortMock();
    when(_nextVersionManagementController.createOrUpdate(eq(_root), eq(TEST_CATEGORY), eq(path), eq(newAttributes), eq(false))).thenReturn(newVersionPort);
    ManagementException error = ManagementException.createUnprocessableManagementException("unexpected");
    when(_nextVersionManagementController.createOrUpdate(any(ConfiguredObject.class), anyString(), eq(path), not(eq(newAttributes)), anyBoolean())).thenThrow(error);
    LegacyConfiguredObject port = _controller.createOrUpdate(_root, path, attributes, false);
    assertThat(port, is(notNullValue()));
    assertPortTLSSettings(port);
}
Also used : LegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject) ManagementException(org.apache.qpid.server.management.plugin.ManagementException) HashMap(java.util.HashMap) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) LegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) LegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

ManagementException (org.apache.qpid.server.management.plugin.ManagementException)6 ManagementController (org.apache.qpid.server.management.plugin.ManagementController)5 ManagementResponse (org.apache.qpid.server.management.plugin.ManagementResponse)5 ManagementRequest (org.apache.qpid.server.management.plugin.ManagementRequest)4 HashMap (java.util.HashMap)2 LegacyConfiguredObject (org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject)2 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)2 StandardCharsets (java.nio.charset.StandardCharsets)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 UUID (java.util.UUID)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 ManagementException.createBadRequestManagementException (org.apache.qpid.server.management.plugin.ManagementException.createBadRequestManagementException)1