org.springframework.ws.soap.SoapMessage Java Examples

The following examples show how to use org.springframework.ws.soap.SoapMessage. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ThrottlingInterceptor.java    From openemm with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public boolean handleRequest(MessageContext messageContext,
		Object paramObject) throws Exception {

	String userName = Utils.getUserName();
	String endpointName = paramObject.getClass().getName();
	
	try {
		if (!throttlingService.checkAndTrack(userName)) {
			logger.debug("Intercepted! User: " + userName + " Endpoint: " + endpointName);
			//TODO: exception resolver?
			throw new Exception("Rate limit exceeded! User: " + userName + " Endpoint: " + endpointName);
		}
	} catch(Exception ex) {
           SoapBody response = ((SoapMessage) messageContext.getResponse()).getSoapBody();
           response.addClientOrSenderFault(ex.getMessage(), Locale.ENGLISH);
           return false;
	}
	
	return true;
}
 
Example #2
Source File: AbstractTraceeInterceptor.java    From tracee with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected void parseContextFromSoapHeader(final WebServiceMessage message, final Channel channel) {
	if (message instanceof SoapMessage) {
		final SoapMessage soapMessage = (SoapMessage) message;

		final TraceeFilterConfiguration filterConfiguration = backend.getConfiguration(profile);

		if (filterConfiguration.shouldProcessContext(channel)) {
			final SoapHeader soapHeader = soapMessage.getSoapHeader();
			if (soapHeader != null) {
				Iterator<SoapHeaderElement> tpicHeaders;
				try {
					tpicHeaders = soapHeader.examineHeaderElements(SOAP_HEADER_QNAME);
				} catch (SoapHeaderException ignored) {
					tpicHeaders = Collections.<SoapHeaderElement>emptyList().iterator();
				}
				if (tpicHeaders.hasNext()) {
					final Map<String, String> parsedTpic = soapHeaderTransport.parseTpicHeader(tpicHeaders.next().getSource());
					backend.putAll(filterConfiguration.filterDeniedParams(parsedTpic, channel));
				}
			}
		}
	} else {
		logger.info("Message is obviously no soap message - Not instance of Spring-WS SoapMessage");
	}
}
 
Example #3
Source File: AbstractTraceeInterceptor.java    From tracee with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected void serializeContextToSoapHeader(final WebServiceMessage message, final Channel channel) {
	if (message instanceof SoapMessage) {
		final SoapMessage soapMessage = (SoapMessage) message;

		final TraceeFilterConfiguration filterConfiguration = backend.getConfiguration(profile);

		if (!backend.isEmpty() && filterConfiguration.shouldProcessContext(channel)) {
			final SoapHeader soapHeader = soapMessage.getSoapHeader();
			if (soapHeader != null) {

				final Map<String, String> context = filterConfiguration.filterDeniedParams(backend.copyToMap(), channel);
				soapHeaderTransport.renderSoapHeader(context, soapHeader.getResult());
			}
		}
	} else {
		logger.info("Message is obviously no soap message - Not instance of Spring-WS SoapMessage");
	}
}
 
Example #4
Source File: TraceeEndpointInterceptorTest.java    From tracee with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void parseTpicHeaderFromRequestToTraceeBackend() throws Exception {
	final Map<String, String> context = new HashMap<>();
	context.put("our key", "is our value");
	final StringResult result = new StringResult();
	new SoapHeaderTransport().renderSoapHeader(context, result);
	final Source source = new StringSource(result.toString());

	final SoapHeader soapHeader = mock(SoapHeader.class);
	when(((SoapMessage) messageContext.getRequest()).getSoapHeader()).thenReturn(soapHeader);
	final SoapHeaderElement element = mock(SoapHeaderElement.class);
	when(element.getSource()).thenReturn(source);
	when(soapHeader.examineHeaderElements(eq(SOAP_HEADER_QNAME))).thenReturn(singletonList(element).iterator());

	unit.handleRequest(messageContext, new Object());
	assertThat(backend.size(), is(2));
	assertThat(backend.copyToMap(), hasKey(INVOCATION_ID_KEY));
	assertThat(backend.copyToMap(), hasEntry("our key", "is our value"));
}
 
Example #5
Source File: TraceeClientInterceptorTest.java    From tracee with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void parseTpicHeaderFromFaultResponseToBackend() throws Exception {
	final Map<String, String> context = new HashMap<>();
	context.put("our key", "is our value");
	final StringResult result = new StringResult();
	new SoapHeaderTransport().renderSoapHeader(context, result);
	final Source source = new StringSource(result.toString());

	final SoapHeader soapHeader = mock(SoapHeader.class);
	when(((SoapMessage) messageContext.getResponse()).getSoapHeader()).thenReturn(soapHeader);
	final SoapHeaderElement element = mock(SoapHeaderElement.class);
	when(element.getSource()).thenReturn(source);
	when(soapHeader.examineHeaderElements(eq(SOAP_HEADER_QNAME))).thenReturn(Collections.singletonList(element).iterator());

	unit.handleFault(messageContext);
	assertThat(backend.size(), is(1));
	assertThat(backend.copyToMap(), hasEntry("our key", "is our value"));
}
 
Example #6
Source File: TraceeClientInterceptorTest.java    From tracee with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void parseTpicHeaderFromResponseToBackend() throws Exception {
	final Map<String, String> context = new HashMap<>();
	context.put("our key", "is our value");
	final StringResult result = new StringResult();
	new SoapHeaderTransport().renderSoapHeader(context, result);
	final Source source = new StringSource(result.toString());

	final SoapHeader soapHeader = mock(SoapHeader.class);
	when(((SoapMessage) messageContext.getResponse()).getSoapHeader()).thenReturn(soapHeader);
	final SoapHeaderElement element = mock(SoapHeaderElement.class);
	when(element.getSource()).thenReturn(source);
	when(soapHeader.examineHeaderElements(eq(SOAP_HEADER_QNAME))).thenReturn(Collections.singletonList(element).iterator());

	unit.handleResponse(messageContext);
	assertThat(backend.size(), is(1));
	assertThat(backend.copyToMap(), hasEntry("our key", "is our value"));
}
 
Example #7
Source File: TraceeEndpointInterceptorTest.java    From tracee with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void renderTpicContextToResultForFaults() throws Exception {
	backend.put("our key", "is our value");
	final StringWriter writer = new StringWriter();
	final SoapHeader soapHeader = mock(SoapHeader.class);
	when(((SoapMessage) messageContext.getResponse()).getSoapHeader()).thenReturn(soapHeader);
	when(soapHeader.getResult()).thenReturn(new StreamResult(writer));
	unit.handleFault(messageContext, new Object());
	assertThat(writer.toString(), containsString("<entry key=\"our key\">is our value</entry>"));
}
 
Example #8
Source File: PermissionCheckingEndpointInterceptor.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public final boolean handleRequest(final MessageContext messageContext, final Object endpoint) throws Exception {
	final Class<?> endpointClass = endpoint.getClass();
	final String endpointName = endpointNameFromClass(endpointClass);
	
	if(Utils.isAuthorityGranted(new EndpointAuthority(endpointName)) || Utils.isAuthorityGranted(AllEndpointsAuthority.INSTANCE)) {
		return true;
	} else {
           final SoapBody response = ((SoapMessage) messageContext.getResponse()).getSoapBody();
           response.addClientOrSenderFault("Access to endpoint denied", Locale.ENGLISH);
		
		return false;
	}
}
 
Example #9
Source File: TraceeEndpointInterceptorTest.java    From tracee with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void renderTpicContextToResultForResponses() throws Exception {
	backend.put("our key", "is our value");
	final StringWriter writer = new StringWriter();
	final SoapHeader soapHeader = mock(SoapHeader.class);
	when(((SoapMessage) messageContext.getResponse()).getSoapHeader()).thenReturn(soapHeader);
	when(soapHeader.getResult()).thenReturn(new StreamResult(writer));
	unit.handleResponse(messageContext, new Object());
	assertThat(writer.toString(), containsString("<entry key=\"our key\">is our value</entry>"));
}
 
Example #10
Source File: TraceeEndpointInterceptorTest.java    From tracee with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void catchJaxbExceptionOnRenderingAndReturnWithoutException() throws Exception {
	backend.put("our key", "is our value");
	when(((SoapMessage) messageContext.getResponse()).getSoapHeader()).thenReturn(mock(SoapHeader.class));
	unit.handleResponse(messageContext, new Object());
	verify(((SoapMessage) messageContext.getResponse()).getSoapHeader()).getResult();
}
 
Example #11
Source File: TraceeEndpointInterceptorTest.java    From tracee with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void handleSoapHeaderExceptionGraceful() {
	final SoapHeader soapHeader = mock(SoapHeader.class);
	when(soapHeader.examineHeaderElements(eq(SOAP_HEADER_QNAME))).thenThrow(new SoapHeaderException("test exception"));
	when(((SoapMessage) messageContext.getRequest()).getSoapHeader()).thenReturn(soapHeader);
	unit.handleRequest(messageContext, new Object());
	assertThat(backend.size(), is(1));
	assertThat(backend.copyToMap(), hasKey(INVOCATION_ID_KEY));
}
 
Example #12
Source File: TraceeEndpointInterceptorTest.java    From tracee with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void skipIncomingHeaderProcessingIfNoTpicHeaderIsPresentAndGenerateRequestId() throws Exception {
	final SoapHeader soapHeader = mock(SoapHeader.class);
	when(((SoapMessage) messageContext.getRequest()).getSoapHeader()).thenReturn(soapHeader);
	when(soapHeader.examineHeaderElements(eq(SOAP_HEADER_QNAME))).thenReturn(Collections.<SoapHeaderElement>emptyList().iterator());

	unit.handleRequest(messageContext, new Object());
	assertThat(backend.copyToMap(), hasKey(INVOCATION_ID_KEY));
	assertThat(backend.size(), is(1));
}
 
Example #13
Source File: TraceeEndpointInterceptorTest.java    From tracee with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void skipIncomingHeaderProcessingIfNoSoapHeaderIsPresentAndGenerateRequestId() throws Exception {
	when(((SoapMessage) messageContext.getRequest()).getSoapHeader()).thenReturn(null);

	unit.handleRequest(messageContext, new Object());
	assertThat(backend.copyToMap(), hasKey(INVOCATION_ID_KEY));
	assertThat(backend.size(), is(1));
}
 
Example #14
Source File: TraceeEndpointInterceptorTest.java    From tracee with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Before
public void setup() {
	messageContext = mock(MessageContext.class);
	when(messageContext.getRequest()).thenReturn(mock(SoapMessage.class));
	when(messageContext.getResponse()).thenReturn(mock(SoapMessage.class));
	when(((SoapMessage) messageContext.getResponse()).getSoapHeader()).thenReturn(mock(SoapHeader.class));
}
 
Example #15
Source File: TraceeClientInterceptorTest.java    From tracee with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void skipResponseHeaderProcessingIfNoTpicHeaderIsPresent() throws Exception {
	final SoapHeader soapHeader = mock(SoapHeader.class);
	when(((SoapMessage) messageContext.getResponse()).getSoapHeader()).thenReturn(soapHeader);
	when(soapHeader.examineHeaderElements(eq(SOAP_HEADER_QNAME))).thenReturn(Collections.<SoapHeaderElement>emptyList().iterator());

	unit.handleResponse(messageContext);
	assertThat(backend.size(), is(0));
}
 
Example #16
Source File: TraceeClientInterceptorTest.java    From tracee with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void skipResponseHeaderProcessingIfNoSoapHeaderIsPresent() throws Exception {
	when(((SoapMessage) messageContext.getResponse()).getSoapHeader()).thenReturn(null);

	unit.handleResponse(messageContext);
	assertThat(backend.size(), is(0));
}
 
Example #17
Source File: TraceeClientInterceptorTest.java    From tracee with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void renderTpicContextToRequest() throws Exception {
	backend.put("our key", "is our value");
	final StringWriter writer = new StringWriter();
	final SoapHeader soapHeader = mock(SoapHeader.class);
	when(((SoapMessage) messageContext.getRequest()).getSoapHeader()).thenReturn(soapHeader);
	when(soapHeader.getResult()).thenReturn(new StreamResult(writer));
	unit.handleRequest(messageContext);
	assertThat(writer.toString(), containsString("<entry key=\"our key\">is our value</entry>"));
}
 
Example #18
Source File: TraceeClientInterceptorTest.java    From tracee with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void catchJaxbExceptionUponRenderingAndReturnWithoutException() throws Exception {
	backend.put("our key", "is our value");
	when(((SoapMessage) messageContext.getRequest()).getSoapHeader()).thenReturn(mock(SoapHeader.class));
	unit.handleRequest(messageContext);
	verify(((SoapMessage) messageContext.getRequest()).getSoapHeader()).getResult();
}
 
Example #19
Source File: TraceeClientInterceptorTest.java    From tracee with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Before
public void setup() {
	messageContext = mock(MessageContext.class);
	when(messageContext.getRequest()).thenReturn(mock(SoapMessage.class));
	when(messageContext.getResponse()).thenReturn(mock(SoapMessage.class));
	when(((SoapMessage) messageContext.getRequest()).getSoapHeader()).thenReturn(mock(SoapHeader.class));
	when(((SoapMessage) messageContext.getResponse()).getSoapHeader()).thenReturn(mock(SoapHeader.class));
}
 
Example #20
Source File: SoapActionRequestCreators.java    From spring-ws-security-soap-example with MIT License 5 votes vote down vote up
@Override
public final WebServiceMessage createRequest(
        WebServiceMessageFactory messageFactory) throws IOException {
    final WebServiceMessage message; // Message to create

    message = adaptee.createMessage(messageFactory);
    if (message instanceof SoapMessage) {
        ((SoapMessage) message).setSoapAction(action);
    }

    return message;
}
 
Example #21
Source File: SoapActionCreator.java    From spring-ws with MIT License 5 votes vote down vote up
@Override
public WebServiceMessage createRequest(WebServiceMessageFactory webServiceMessageFactory)
    throws IOException {
  WebServiceMessage webServiceMessage =
      new PayloadMessageCreator(payload).createMessage(webServiceMessageFactory);

  SoapMessage soapMessage = (SoapMessage) webServiceMessage;
  soapMessage.setSoapAction(soapAction);

  return webServiceMessage;
}
 
Example #22
Source File: SoapActionMatcher.java    From spring-ws with MIT License 5 votes vote down vote up
@Override
public void match(URI uri, WebServiceMessage webServiceMessage)
    throws IOException, AssertionError {
  assertThat(webServiceMessage).isInstanceOf(SoapMessage.class);

  SoapMessage soapMessage = (SoapMessage) webServiceMessage;
  assertThat(soapMessage.getSoapAction()).isEqualTo(expectedSoapAction);
}
 
Example #23
Source File: TicketAgentEndpoint.java    From spring-ws with MIT License 5 votes vote down vote up
@SoapAction(value = "http://example.com/TicketAgent/listFlights")
@ResponsePayload
public JAXBElement<TFlightsResponse> listFlights(
    @RequestPayload JAXBElement<TListFlights> request, MessageContext messageContext) {
  // access the SOAPAction value
  WebServiceMessage webServiceMessage = messageContext.getRequest();
  SoapMessage soapMessage = (SoapMessage) webServiceMessage;
  LOGGER.info("SOAPAction header: {}", soapMessage.getSoapAction());

  ObjectFactory factory = new ObjectFactory();
  TFlightsResponse tFlightsResponse = factory.createTFlightsResponse();
  tFlightsResponse.getFlightNumber().add(BigInteger.valueOf(101));

  return factory.createListFlightsResponse(tFlightsResponse);
}
 
Example #24
Source File: TraceeClientInterceptorTest.java    From tracee with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void doNotAddTpicHeaderIfBackendIsEmpty() throws Exception {
	unit.handleRequest(messageContext);
	verify(((SoapMessage) messageContext.getResponse()).getSoapHeader(), never()).addHeaderElement(eq(SOAP_HEADER_QNAME));
}
 
Example #25
Source File: TraceeEndpointInterceptorTest.java    From tracee with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void doNotAddTpicHeaderToResponseIfBackendIsEmpty() throws Exception {
	unit.handleRequest(messageContext, new Object());
	verify(((SoapMessage) messageContext.getResponse()).getSoapHeader(), never()).addHeaderElement(eq(SOAP_HEADER_QNAME));
}