Search in sources :

Example 1 with RequestType

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

the class AbstractLegacyConfiguredObjectControllerTest method getRequestType.

@Test
public void getRequestType() {
    final Map<String, List<String>> parameters = Collections.singletonMap("name", Collections.singletonList("test"));
    final ManagementRequest managementRequest = mock(ManagementRequest.class);
    doReturn(_root).when(managementRequest).getRoot();
    when(managementRequest.getMethod()).thenReturn("GET");
    when(managementRequest.getParameters()).thenReturn(parameters);
    when(managementRequest.getPath()).thenReturn(Collections.singletonList("test"));
    when(managementRequest.getCategory()).thenReturn(TEST_CATEGORY_2);
    when(_controller.getCategory(_root)).thenReturn(TEST_CATEGORY);
    final RequestType requestType = _controller.getRequestType(managementRequest);
    assertThat(requestType, is(equalTo(RequestType.MODEL_OBJECT)));
}
Also used : ManagementRequest(org.apache.qpid.server.management.plugin.ManagementRequest) List(java.util.List) RequestType(org.apache.qpid.server.management.plugin.RequestType) Test(org.junit.Test)

Example 2 with RequestType

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

the class LatestManagementControllerTest method getRequestTypeForGetAndVisiblePreferences.

@Test
public void getRequestTypeForGetAndVisiblePreferences() throws Exception {
    final String hostName = "test";
    final QueueManagingVirtualHost<?> virtualHost = createVirtualHostWithQueue(hostName, "foo", "bar");
    final ManagementRequest request = mock(ManagementRequest.class);
    when(request.getCategory()).thenReturn("queue");
    doReturn(virtualHost.getBroker()).when(request).getRoot();
    List<String> path = Arrays.asList(virtualHost.getParent().getName(), hostName, "bar", "visiblepreferences");
    when(request.getPath()).thenReturn(path);
    when(request.getParameters()).thenReturn(Collections.emptyMap());
    when(request.getMethod()).thenReturn("GET");
    final RequestType type = _controller.getRequestType(request);
    assertThat(type, is(equalTo(RequestType.VISIBLE_PREFERENCES)));
}
Also used : ManagementRequest(org.apache.qpid.server.management.plugin.ManagementRequest) RequestType(org.apache.qpid.server.management.plugin.RequestType) Test(org.junit.Test)

Example 3 with RequestType

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

the class AbstractManagementController method handlePostOrPut.

private ManagementResponse handlePostOrPut(final ManagementRequest request) throws ManagementException {
    final RequestType type = getRequestType(request);
    final Collection<String> hierarchy = getCategoryHierarchy(request.getRoot(), request.getCategory());
    switch(type) {
        case OPERATION:
            {
                final List<String> operationPath = request.getPath().subList(0, hierarchy.size());
                final String operationName = request.getPath().get(hierarchy.size());
                @SuppressWarnings("unchecked") final Map<String, Object> arguments = request.getBody(LinkedHashMap.class);
                return invoke(request.getRoot(), request.getCategory(), operationPath, operationName, arguments, true, request.isSecure() || request.isConfidentialOperationAllowedOnInsecureChannel());
            }
        case MODEL_OBJECT:
            {
                @SuppressWarnings("unchecked") final Map<String, Object> attributes = request.getBody(LinkedHashMap.class);
                final Object response = createOrUpdate(request.getRoot(), request.getCategory(), request.getPath(), attributes, "POST".equalsIgnoreCase(request.getMethod()));
                int responseCode = HttpServletResponse.SC_OK;
                ResponseType responseType = ResponseType.EMPTY;
                Map<String, String> headers = Collections.emptyMap();
                if (response != null) {
                    responseCode = HttpServletResponse.SC_CREATED;
                    final StringBuilder requestURL = new StringBuilder(request.getRequestURL());
                    if (hierarchy.size() != request.getPath().size()) {
                        Object name = attributes.get("name");
                        requestURL.append("/").append(encode(String.valueOf(name)));
                    }
                    headers = Collections.singletonMap("Location", requestURL.toString());
                    responseType = ResponseType.MODEL_OBJECT;
                }
                return new ControllerManagementResponse(responseType, response, responseCode, headers);
            }
        case VISIBLE_PREFERENCES:
        case USER_PREFERENCES:
            {
                setPreferences(request.getRoot(), request.getCategory(), request.getPath(), request.getBody(Object.class), request.getParameters(), "POST".equalsIgnoreCase(request.getMethod()));
                return new ControllerManagementResponse(ResponseType.EMPTY, null);
            }
        default:
            {
                throw createBadRequestManagementException(String.format("Unexpected request type '%s' for path '%s'", type, getCategoryMapping(request.getCategory())));
            }
    }
}
Also used : List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) RequestType(org.apache.qpid.server.management.plugin.RequestType) LinkedHashMap(java.util.LinkedHashMap) ResponseType(org.apache.qpid.server.management.plugin.ResponseType)

Example 4 with RequestType

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

the class LatestManagementControllerTest method getRequestTypeForGetAndModelObjectWithFullPath.

@Test
public void getRequestTypeForGetAndModelObjectWithFullPath() throws Exception {
    final String hostName = "test";
    final QueueManagingVirtualHost<?> virtualHost = createVirtualHostWithQueue(hostName, "foo", "bar");
    final ManagementRequest request = mock(ManagementRequest.class);
    when(request.getCategory()).thenReturn("queue");
    doReturn(virtualHost.getBroker()).when(request).getRoot();
    final List<String> path = Arrays.asList(virtualHost.getParent().getName(), hostName, "bar");
    when(request.getPath()).thenReturn(path);
    when(request.getParameters()).thenReturn(Collections.emptyMap());
    when(request.getMethod()).thenReturn("GET");
    final RequestType type = _controller.getRequestType(request);
    assertThat(type, is(equalTo(RequestType.MODEL_OBJECT)));
}
Also used : ManagementRequest(org.apache.qpid.server.management.plugin.ManagementRequest) RequestType(org.apache.qpid.server.management.plugin.RequestType) Test(org.junit.Test)

Example 5 with RequestType

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

the class LatestManagementControllerTest method getRequestTypeForGetAndModelObjectWithNotFullPath.

@Test
public void getRequestTypeForGetAndModelObjectWithNotFullPath() throws Exception {
    final String hostName = "test";
    final QueueManagingVirtualHost<?> virtualHost = createVirtualHostWithQueue(hostName, "foo", "bar");
    final ManagementRequest request = mock(ManagementRequest.class);
    when(request.getCategory()).thenReturn("queue");
    doReturn(virtualHost.getBroker()).when(request).getRoot();
    when(request.getPath()).thenReturn(Arrays.asList("*", hostName));
    when(request.getParameters()).thenReturn(Collections.emptyMap());
    when(request.getMethod()).thenReturn("GET");
    final RequestType type = _controller.getRequestType(request);
    assertThat(type, is(equalTo(RequestType.MODEL_OBJECT)));
}
Also used : ManagementRequest(org.apache.qpid.server.management.plugin.ManagementRequest) RequestType(org.apache.qpid.server.management.plugin.RequestType) Test(org.junit.Test)

Aggregations

RequestType (org.apache.qpid.server.management.plugin.RequestType)6 ManagementRequest (org.apache.qpid.server.management.plugin.ManagementRequest)5 Test (org.junit.Test)5 List (java.util.List)2 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ResponseType (org.apache.qpid.server.management.plugin.ResponseType)1