use of ee.ria.xroad.proxy.common.WsdlRequestData in project X-Road by nordic-institute.
the class MetadataServiceHandlerTest method shouldThrowUnknownServiceWhenWsdlUrlNotFound.
@Test
public void shouldThrowUnknownServiceWhenWsdlUrlNotFound() throws Exception {
final ServiceId serviceId = ServiceId.create(DEFAULT_CLIENT, GET_WSDL);
final ServiceId requestingWsdlForService = ServiceId.create(DEFAULT_CLIENT, "someServiceWithoutWsdl");
MetadataServiceHandlerImpl handlerToTest = new MetadataServiceHandlerImpl();
WsdlRequestData wsdlRequestData = new WsdlRequestData();
wsdlRequestData.setServiceCode(requestingWsdlForService.getServiceCode());
InputStream soapContentInputStream = new TestSoapBuilder().withClient(DEFAULT_CLIENT).withService(serviceId).withModifiedBody(soapBody -> marshaller.marshal(wsdlRequestData, soapBody)).buildAsInputStream();
when(mockProxyMessage.getSoapContent()).thenReturn(soapContentInputStream);
handlerToTest.canHandle(serviceId, mockProxyMessage);
thrown.expect(CodedException.class);
thrown.expect(faultCodeEquals(X_UNKNOWN_SERVICE));
thrown.expectMessage(containsString("Could not find wsdl URL for service"));
// execution, should throw..
handlerToTest.startHandling(mockRequest, mockProxyMessage, httpClientMock, mock(OpMonitoringData.class));
}
use of ee.ria.xroad.proxy.common.WsdlRequestData in project X-Road by nordic-institute.
the class MetadataServiceHandlerImpl method handleGetWsdl.
private void handleGetWsdl(SoapMessageImpl request) throws Exception {
log.trace("handleGetWsdl()");
Unmarshaller um = JaxbUtils.createUnmarshaller(WsdlRequestData.class);
WsdlRequestData requestData = um.unmarshal(SoapUtils.getFirstChild(request.getSoap().getSOAPBody()), WsdlRequestData.class).getValue();
if (StringUtils.isBlank(requestData.getServiceCode())) {
throw new CodedException(X_INVALID_REQUEST, "Missing serviceCode in message body");
}
ServiceId serviceId = requestData.toServiceId(request.getService().getClientId());
String url = getWsdlUrl(serviceId);
if (url == null) {
throw new CodedException(X_UNKNOWN_SERVICE, "Could not find wsdl URL for service %s", requestData.toServiceId(request.getService().getClientId()));
}
log.info("Downloading WSDL from URL: {}", url);
try (InputStream in = modifyWsdl(getWsdl(url, serviceId))) {
Map<String, String> additionalHeaders = new HashMap<>();
additionalHeaders.put("Content-Transfer-Encoding", "binary");
additionalHeaders.put("Content-ID", "<wsdl=" + UUID.randomUUID().toString() + "@x-road.eu>");
responseEncoder.soap(SoapUtils.toResponse(request), new HashMap<>());
responseEncoder.attachment(MimeTypes.TEXT_XML, in, additionalHeaders);
}
}
use of ee.ria.xroad.proxy.common.WsdlRequestData in project X-Road by nordic-institute.
the class MetadataServiceHandlerTest method shouldThrowRuntimeExWhenWsdlUrlNotOk200.
@Test
public void shouldThrowRuntimeExWhenWsdlUrlNotOk200() throws Exception {
final ServiceId serviceId = ServiceId.create(DEFAULT_CLIENT, GET_WSDL);
final ServiceId requestingWsdlForService = ServiceId.create(DEFAULT_CLIENT, "someServiceWithWsdl122");
MetadataServiceHandlerImpl handlerToTest = new MetadataServiceHandlerImpl();
WsdlRequestData wsdlRequestData = new WsdlRequestData();
wsdlRequestData.setServiceCode(requestingWsdlForService.getServiceCode());
InputStream soapContentInputStream = new TestSoapBuilder().withClient(DEFAULT_CLIENT).withService(serviceId).withModifiedBody(soapBody -> marshaller.marshal(wsdlRequestData, soapBody)).buildAsInputStream();
when(mockProxyMessage.getSoapContent()).thenReturn(soapContentInputStream);
setUpDatabase(requestingWsdlForService);
mockServer.stubFor(WireMock.any(urlPathEqualTo(EXPECTED_WSDL_QUERY_PATH)).willReturn(aResponse().withStatus(HttpServletResponse.SC_FORBIDDEN)));
mockServer.start();
handlerToTest.canHandle(serviceId, mockProxyMessage);
thrown.expect(RuntimeException.class);
thrown.expectMessage(containsString("Received HTTP error: 403 - Forbidden"));
// execution, should throw..
handlerToTest.startHandling(mockRequest, mockProxyMessage, httpClientMock, mock(OpMonitoringData.class));
}
use of ee.ria.xroad.proxy.common.WsdlRequestData in project X-Road by nordic-institute.
the class MetadataServiceHandlerTest method prepareTestConstructsForWsdl.
/**
* Prepare TestMetadataServiceHandlerImpl, wiremock, et al for get WSDL tests
*/
private TestMetadataServiceHandlerImpl prepareTestConstructsForWsdl(ServiceId serviceId, boolean isRest) throws Exception {
final ServiceId requestingWsdlForService = ServiceId.create(DEFAULT_CLIENT, "someServiceWithWsdl122");
TestMetadataServiceHandlerImpl handlerToTest = new TestMetadataServiceHandlerImpl();
WsdlRequestData wsdlRequestData = new WsdlRequestData();
wsdlRequestData.setServiceCode(requestingWsdlForService.getServiceCode());
InputStream soapContentInputStream = new TestSoapBuilder().withClient(DEFAULT_CLIENT).withService(serviceId).withModifiedBody(soapBody -> marshaller.marshal(wsdlRequestData, soapBody)).buildAsInputStream();
when(mockProxyMessage.getSoapContent()).thenReturn(soapContentInputStream);
setUpDatabase(requestingWsdlForService, isRest);
mockServer.stubFor(WireMock.any(urlPathEqualTo(EXPECTED_WSDL_QUERY_PATH)).willReturn(aResponse().withBodyFile("wsdl.wsdl")));
mockServer.start();
when(mockResponse.getOutputStream()).thenReturn(mockServletOutputStream);
handlerToTest.canHandle(serviceId, mockProxyMessage);
return handlerToTest;
}
Aggregations