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());
}
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));
}
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());
}
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();
}
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();
}
Aggregations