Search in sources :

Example 1 with ProxyMessageDecoder

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

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

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

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

the class ServerMessageProcessor method readMessage.

private void readMessage() throws Exception {
    log.trace("readMessage()");
    originalSoapAction = validateSoapActionHeader(servletRequest.getHeader(HEADER_ORIGINAL_SOAP_ACTION));
    requestMessage = new ProxyMessage(servletRequest.getHeader(HEADER_ORIGINAL_CONTENT_TYPE)) {

        @Override
        public void soap(SoapMessageImpl soapMessage, Map<String, String> additionalHeaders) throws Exception {
            super.soap(soapMessage, additionalHeaders);
            updateOpMonitoringDataBySoapMessage(opMonitoringData, soapMessage);
            requestServiceId = soapMessage.getService();
            verifySecurityServer();
            verifyClientStatus();
            responseSigningCtx = KeyConf.getSigningCtx(requestServiceId.getClientId());
            if (SystemProperties.isSslEnabled()) {
                verifySslClientCert();
            }
        }
    };
    decoder = new ProxyMessageDecoder(requestMessage, servletRequest.getContentType(), false, getHashAlgoId(servletRequest));
    try {
        decoder.parse(servletRequest.getInputStream());
    } catch (CodedException e) {
        throw e.withPrefix(X_SERVICE_FAILED_X);
    }
    updateOpMonitoringDataByRequest();
    // Check if the input contained all the required bits.
    checkRequest();
}
Also used : ProxyMessage(ee.ria.xroad.proxy.protocol.ProxyMessage) CodedException(ee.ria.xroad.common.CodedException) ProxyMessageDecoder(ee.ria.xroad.proxy.protocol.ProxyMessageDecoder) SoapMessageImpl(ee.ria.xroad.common.message.SoapMessageImpl) URISyntaxException(java.net.URISyntaxException) ErrorCodes.translateException(ee.ria.xroad.common.ErrorCodes.translateException) CodedException(ee.ria.xroad.common.CodedException)

Example 5 with ProxyMessageDecoder

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

the class ServerRestMessageProcessor method readMessage.

private void readMessage() throws Exception {
    log.trace("readMessage()");
    requestMessage = new ProxyMessage(servletRequest.getHeader(HEADER_ORIGINAL_CONTENT_TYPE)) {

        @Override
        public void rest(RestRequest message) throws Exception {
            super.rest(message);
            requestServiceId = message.getServiceId();
            verifyClientStatus();
            responseSigningCtx = KeyConf.getSigningCtx(requestServiceId.getClientId());
            if (SystemProperties.isSslEnabled()) {
                verifySslClientCert();
            }
        }
    };
    decoder = new ProxyMessageDecoder(requestMessage, servletRequest.getContentType(), false, getHashAlgoId(servletRequest));
    try {
        decoder.parse(servletRequest.getInputStream());
    } catch (CodedException e) {
        throw e.withPrefix(X_SERVICE_FAILED_X);
    }
    updateOpMonitoringDataByRequest();
    // Check if the input contained all the required bits.
    checkRequest();
}
Also used : ProxyMessage(ee.ria.xroad.proxy.protocol.ProxyMessage) RestRequest(ee.ria.xroad.common.message.RestRequest) CodedException(ee.ria.xroad.common.CodedException) ProxyMessageDecoder(ee.ria.xroad.proxy.protocol.ProxyMessageDecoder) CodedException(ee.ria.xroad.common.CodedException)

Aggregations

ProxyMessageDecoder (ee.ria.xroad.proxy.protocol.ProxyMessageDecoder)10 RestRequest (ee.ria.xroad.common.message.RestRequest)7 ServiceId (ee.ria.xroad.common.identifier.ServiceId)6 OpMonitoringData (ee.ria.xroad.common.opmonitoring.OpMonitoringData)6 ProxyMessageEncoder (ee.ria.xroad.proxy.protocol.ProxyMessageEncoder)6 Test (org.junit.Test)6 CachingStream (ee.ria.xroad.common.util.CachingStream)5 CodedException (ee.ria.xroad.common.CodedException)4 ProxyMessage (ee.ria.xroad.proxy.protocol.ProxyMessage)4 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 ErrorCodes.translateException (ee.ria.xroad.common.ErrorCodes.translateException)1 SoapMessageImpl (ee.ria.xroad.common.message.SoapMessageImpl)1 URISyntaxException (java.net.URISyntaxException)1