Search in sources :

Example 1 with ProxyMessageEncoder

use of ee.ria.xroad.proxy.protocol.ProxyMessageEncoder 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 ProxyMessageEncoder

use of ee.ria.xroad.proxy.protocol.ProxyMessageEncoder in project X-Road by nordic-institute.

the class RestMetadataServiceHandlerTest method shouldDetectUnsupportedOpenapiVersion.

@Test(expected = CodedException.class)
public void shouldDetectUnsupportedOpenapiVersion() throws Exception {
    RestMetadataServiceHandlerImpl handlerToTest = new RestMetadataServiceHandlerImpl();
    ProxyMessageDecoder mockDecoder = mock(ProxyMessageDecoder.class);
    ProxyMessageEncoder mockEncoder = mock(ProxyMessageEncoder.class);
    // Test for petstore.yaml parsing
    ServiceId serviceId = ServiceId.create(CLIENT_WITH_UNSUPPORTED_OPENAPI, GET_OPENAPI);
    RestRequest mockRestRequest = mock(RestRequest.class);
    when(mockRestRequest.getQuery()).thenReturn("serviceCode=yaml");
    when(mockRestRequest.getServiceId()).thenReturn(serviceId);
    when(mockRestRequest.getVerb()).thenReturn(RestRequest.Verb.GET);
    when(mockRestRequest.getClientId()).thenReturn(CLIENT_WITH_UNSUPPORTED_OPENAPI);
    when(mockRestRequest.getHash()).thenReturn(REQUEST_HASH);
    when(mockProxyMessage.getRest()).thenReturn(mockRestRequest);
    handlerToTest.startHandling(mockRequest, mockProxyMessage, mockDecoder, mockEncoder, httpClientMock, httpClientMock, mock(OpMonitoringData.class));
}
Also used : OpMonitoringData(ee.ria.xroad.common.opmonitoring.OpMonitoringData) RestRequest(ee.ria.xroad.common.message.RestRequest) ProxyMessageDecoder(ee.ria.xroad.proxy.protocol.ProxyMessageDecoder) ProxyMessageEncoder(ee.ria.xroad.proxy.protocol.ProxyMessageEncoder) ServiceId(ee.ria.xroad.common.identifier.ServiceId) Test(org.junit.Test)

Example 3 with ProxyMessageEncoder

use of ee.ria.xroad.proxy.protocol.ProxyMessageEncoder 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 4 with ProxyMessageEncoder

use of ee.ria.xroad.proxy.protocol.ProxyMessageEncoder in project X-Road by nordic-institute.

the class ServerMessageProcessor method preprocess.

@Override
protected void preprocess() throws Exception {
    encoder = new ProxyMessageEncoder(servletResponse.getOutputStream(), SoapUtils.getHashAlgoId());
    servletResponse.setContentType(encoder.getContentType());
    servletResponse.addHeader(HEADER_HASH_ALGO_ID, SoapUtils.getHashAlgoId());
}
Also used : ProxyMessageEncoder(ee.ria.xroad.proxy.protocol.ProxyMessageEncoder)

Example 5 with ProxyMessageEncoder

use of ee.ria.xroad.proxy.protocol.ProxyMessageEncoder in project X-Road by nordic-institute.

the class ServerRestMessageProcessor method preprocess.

@Override
protected void preprocess() throws Exception {
    encoder = new ProxyMessageEncoder(servletResponse.getOutputStream(), CryptoUtils.DEFAULT_DIGEST_ALGORITHM_ID);
    servletResponse.setContentType(encoder.getContentType());
    servletResponse.addHeader(HEADER_HASH_ALGO_ID, SoapUtils.getHashAlgoId());
}
Also used : ProxyMessageEncoder(ee.ria.xroad.proxy.protocol.ProxyMessageEncoder)

Aggregations

ProxyMessageEncoder (ee.ria.xroad.proxy.protocol.ProxyMessageEncoder)8 ServiceId (ee.ria.xroad.common.identifier.ServiceId)6 RestRequest (ee.ria.xroad.common.message.RestRequest)6 OpMonitoringData (ee.ria.xroad.common.opmonitoring.OpMonitoringData)6 ProxyMessageDecoder (ee.ria.xroad.proxy.protocol.ProxyMessageDecoder)6 Test (org.junit.Test)6 CachingStream (ee.ria.xroad.common.util.CachingStream)5 RestResponse (ee.ria.xroad.common.message.RestResponse)3 RestServiceDetailsListType (ee.ria.xroad.common.metadata.RestServiceDetailsListType)2 BufferedReader (java.io.BufferedReader)2 InputStreamReader (java.io.InputStreamReader)2