Search in sources :

Example 1 with RestServiceDetailsListType

use of ee.ria.xroad.common.metadata.RestServiceDetailsListType in project X-Road by nordic-institute.

the class RestMetadataServiceHandlerTest method shouldHandleListMethods.

@Test
public void shouldHandleListMethods() throws Exception {
    RestMetadataServiceHandlerImpl handlerToTest = new RestMetadataServiceHandlerImpl();
    ServiceId serviceId = ServiceId.create(DEFAULT_CLIENT, LIST_METHODS);
    RestRequest mockRestRequest = mock(RestRequest.class);
    when(mockRestRequest.getServiceId()).thenReturn(serviceId);
    when(mockRestRequest.getVerb()).thenReturn(RestRequest.Verb.GET);
    when(mockRestRequest.getClientId()).thenReturn(DEFAULT_CLIENT);
    when(mockRestRequest.getHash()).thenReturn(REQUEST_HASH);
    when(mockProxyMessage.getRest()).thenReturn(mockRestRequest);
    ProxyMessageDecoder mockDecoder = mock(ProxyMessageDecoder.class);
    ProxyMessageEncoder mockEncoder = mock(ProxyMessageEncoder.class);
    handlerToTest.startHandling(mockRequest, mockProxyMessage, mockDecoder, mockEncoder, httpClientMock, httpClientMock, mock(OpMonitoringData.class));
    RestResponse restResponse = handlerToTest.getRestResponse();
    assertEquals(HttpStatus.SC_OK, restResponse.getResponseCode());
    assertEquals("OK", restResponse.getReason());
    CachingStream restResponseBody = handlerToTest.getRestResponseBody();
    MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    RestServiceDetailsListType restServiceDetailsList = MAPPER.readValue(restResponseBody.getCachedContents(), RestServiceDetailsListType.class);
    assertEquals(3, restServiceDetailsList.getService().size());
    assertEquals(1, restServiceDetailsList.getService().get(0).getEndpointList().size());
}
Also used : OpMonitoringData(ee.ria.xroad.common.opmonitoring.OpMonitoringData) RestRequest(ee.ria.xroad.common.message.RestRequest) ProxyMessageDecoder(ee.ria.xroad.proxy.protocol.ProxyMessageDecoder) RestResponse(ee.ria.xroad.common.message.RestResponse) ProxyMessageEncoder(ee.ria.xroad.proxy.protocol.ProxyMessageEncoder) RestServiceDetailsListType(ee.ria.xroad.common.metadata.RestServiceDetailsListType) ServiceId(ee.ria.xroad.common.identifier.ServiceId) CachingStream(ee.ria.xroad.common.util.CachingStream) Test(org.junit.Test)

Example 2 with RestServiceDetailsListType

use of ee.ria.xroad.common.metadata.RestServiceDetailsListType in project X-Road by nordic-institute.

the class RestMetadataServiceHandlerTest method shouldHandleAllowedMethods.

@Test
public void shouldHandleAllowedMethods() throws Exception {
    RestMetadataServiceHandlerImpl handlerToTest = new RestMetadataServiceHandlerImpl();
    ServiceId serviceId = ServiceId.create(DEFAULT_CLIENT, ALLOWED_METHODS);
    RestRequest mockRestRequest = mock(RestRequest.class);
    when(mockRestRequest.getServiceId()).thenReturn(serviceId);
    when(mockRestRequest.getVerb()).thenReturn(RestRequest.Verb.GET);
    when(mockRestRequest.getClientId()).thenReturn(DEFAULT_CLIENT);
    when(mockRestRequest.getHash()).thenReturn(REQUEST_HASH);
    when(mockProxyMessage.getRest()).thenReturn(mockRestRequest);
    ProxyMessageDecoder mockDecoder = mock(ProxyMessageDecoder.class);
    ProxyMessageEncoder mockEncoder = mock(ProxyMessageEncoder.class);
    handlerToTest.startHandling(mockRequest, mockProxyMessage, mockDecoder, mockEncoder, httpClientMock, httpClientMock, mock(OpMonitoringData.class));
    RestResponse restResponse = handlerToTest.getRestResponse();
    assertEquals(HttpStatus.SC_OK, restResponse.getResponseCode());
    assertEquals("OK", restResponse.getReason());
    CachingStream restResponseBody = handlerToTest.getRestResponseBody();
    MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    RestServiceDetailsListType restServiceDetailsList = MAPPER.readValue(restResponseBody.getCachedContents(), RestServiceDetailsListType.class);
    assertEquals(3, restServiceDetailsList.getService().size());
    assertEquals(1, restServiceDetailsList.getService().get(0).getEndpointList().size());
}
Also used : OpMonitoringData(ee.ria.xroad.common.opmonitoring.OpMonitoringData) RestRequest(ee.ria.xroad.common.message.RestRequest) ProxyMessageDecoder(ee.ria.xroad.proxy.protocol.ProxyMessageDecoder) RestResponse(ee.ria.xroad.common.message.RestResponse) ProxyMessageEncoder(ee.ria.xroad.proxy.protocol.ProxyMessageEncoder) RestServiceDetailsListType(ee.ria.xroad.common.metadata.RestServiceDetailsListType) ServiceId(ee.ria.xroad.common.identifier.ServiceId) CachingStream(ee.ria.xroad.common.util.CachingStream) Test(org.junit.Test)

Example 3 with RestServiceDetailsListType

use of ee.ria.xroad.common.metadata.RestServiceDetailsListType in project X-Road by nordic-institute.

the class ServerConfImpl method getAllowedRestServices.

@Override
public RestServiceDetailsListType getAllowedRestServices(ClientId serviceProvider, ClientId client) {
    return tx(session -> {
        RestServiceDetailsListType restServiceDetailsList = new RestServiceDetailsListType();
        serviceDao.getServicesByDescriptionType(session, serviceProvider, DescriptionType.OPENAPI3, DescriptionType.REST).forEach(serviceId -> {
            final List<EndpointType> acl = getAclEndpoints(session, client, serviceId);
            if (!acl.isEmpty()) {
                final List<Endpoint> endpoints = getServiceEndpoints(serviceId);
                XRoadRestServiceDetailsType serviceDetails = createRestServiceDetails(serviceId);
                for (Endpoint e : endpoints) {
                    if (acl.stream().anyMatch(it -> it.matches(e.getMethod(), e.getPath()))) {
                        serviceDetails.getEndpointList().add(e);
                    }
                }
                restServiceDetailsList.getService().add(serviceDetails);
            }
        });
        return restServiceDetailsList;
    });
}
Also used : Endpoint(ee.ria.xroad.common.metadata.Endpoint) EndpointType(ee.ria.xroad.common.conf.serverconf.model.EndpointType) XRoadRestServiceDetailsType(ee.ria.xroad.common.metadata.XRoadRestServiceDetailsType) RestServiceDetailsListType(ee.ria.xroad.common.metadata.RestServiceDetailsListType)

Example 4 with RestServiceDetailsListType

use of ee.ria.xroad.common.metadata.RestServiceDetailsListType in project X-Road by nordic-institute.

the class ServerConfImpl method getRestServices.

@Override
public RestServiceDetailsListType getRestServices(ClientId serviceProvider) {
    return tx(session -> {
        RestServiceDetailsListType restServiceDetailsList = new RestServiceDetailsListType();
        serviceDao.getServicesByDescriptionType(session, serviceProvider, DescriptionType.OPENAPI3, DescriptionType.REST).forEach(serviceId -> {
            XRoadRestServiceDetailsType serviceDetails = createRestServiceDetails(serviceId);
            serviceDetails.getEndpointList().addAll(getServiceEndpoints(serviceId));
            restServiceDetailsList.getService().add(serviceDetails);
        });
        return restServiceDetailsList;
    });
}
Also used : XRoadRestServiceDetailsType(ee.ria.xroad.common.metadata.XRoadRestServiceDetailsType) RestServiceDetailsListType(ee.ria.xroad.common.metadata.RestServiceDetailsListType)

Example 5 with RestServiceDetailsListType

use of ee.ria.xroad.common.metadata.RestServiceDetailsListType in project X-Road by nordic-institute.

the class EmptyServerConf method getRestServices.

@Override
public RestServiceDetailsListType getRestServices(ClientId serviceProvider) {
    RestServiceDetailsListType restServiceDetailsList = new RestServiceDetailsListType();
    ServiceId serviceId1 = ServiceId.create(DEFAULT_CLIENT, SERVICE1);
    XRoadRestServiceDetailsType serviceDetails1 = createRestServiceDetails(serviceId1);
    serviceDetails1.getEndpointList().addAll(getServiceEndpoints(serviceId1));
    restServiceDetailsList.getService().add(serviceDetails1);
    ServiceId serviceId2 = ServiceId.create(DEFAULT_CLIENT, SERVICE2);
    XRoadRestServiceDetailsType serviceDetails2 = createRestServiceDetails(serviceId2);
    serviceDetails2.getEndpointList().addAll(getServiceEndpoints(serviceId2));
    restServiceDetailsList.getService().add(serviceDetails2);
    ServiceId serviceId3 = ServiceId.create(DEFAULT_CLIENT, SERVICE3);
    XRoadRestServiceDetailsType serviceDetails3 = createRestServiceDetails(serviceId3);
    serviceDetails3.getEndpointList().addAll(getServiceEndpoints(serviceId3));
    restServiceDetailsList.getService().add(serviceDetails3);
    return restServiceDetailsList;
}
Also used : XRoadRestServiceDetailsType(ee.ria.xroad.common.metadata.XRoadRestServiceDetailsType) RestServiceDetailsListType(ee.ria.xroad.common.metadata.RestServiceDetailsListType) ServiceId(ee.ria.xroad.common.identifier.ServiceId)

Aggregations

RestServiceDetailsListType (ee.ria.xroad.common.metadata.RestServiceDetailsListType)5 ServiceId (ee.ria.xroad.common.identifier.ServiceId)3 XRoadRestServiceDetailsType (ee.ria.xroad.common.metadata.XRoadRestServiceDetailsType)3 RestRequest (ee.ria.xroad.common.message.RestRequest)2 RestResponse (ee.ria.xroad.common.message.RestResponse)2 OpMonitoringData (ee.ria.xroad.common.opmonitoring.OpMonitoringData)2 CachingStream (ee.ria.xroad.common.util.CachingStream)2 ProxyMessageDecoder (ee.ria.xroad.proxy.protocol.ProxyMessageDecoder)2 ProxyMessageEncoder (ee.ria.xroad.proxy.protocol.ProxyMessageEncoder)2 Test (org.junit.Test)2 EndpointType (ee.ria.xroad.common.conf.serverconf.model.EndpointType)1 Endpoint (ee.ria.xroad.common.metadata.Endpoint)1