org.springframework.ws.context.MessageContext Java Examples

The following examples show how to use org.springframework.ws.context.MessageContext. 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: XTeeEndpointMapping.java    From j-road with Apache License 2.0 6 votes vote down vote up
@Override
protected Object getEndpointInternal(MessageContext messageCtx) throws Exception {
  SOAPMessage message = SOAPUtil.extractSoapMessage(messageCtx.getRequest());
  if (message.getSOAPHeader() != null) {
    AbstractXTeeBaseEndpoint endpoint = methodMap.get(getRequestMethod(message.getSOAPHeader()));
    if (endpoint != null) {
      if (log.isDebugEnabled()) {
        log.debug("Matched " + endpoint + " to " + endpoint.getClass().getSimpleName());
      }
      return endpoint;
    }
  }

  try {
    if (SOAPUtil.getNodeByXPath(message.getSOAPBody(), "/*/*/*[local-name()='listMethods']") != null) {
      log.debug("Matched headerless listMethods request.");
      return getApplicationContext().getBean(getApplicationContext().getBeanNamesForType(ListMethodsEndpoint.class)[0]);
    }
  } catch (NullPointerException e) {
    // ListMethods lookup failed
  }
  return null;
}
 
Example #2
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 #3
Source File: WSConsumptionLoggingInterceptor.java    From j-road with Apache License 2.0 6 votes vote down vote up
private boolean logMessage(MessageContext mc, MessageType messageType) {
  if (log.isDebugEnabled()) {
    WebServiceMessage message = MessageType.REQUEST.equals(messageType) ? mc.getRequest() : mc.getResponse();

    if (message instanceof SaajSoapMessage) {
      OutputStream out = new ByteArrayOutputStream();
      try {
        ((SaajSoapMessage) message).writeTo(out);
        log.debug(messageType + " message follows:\n" + out.toString());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
  }

  return true;
}
 
Example #4
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 #5
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 #6
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 #7
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 #8
Source File: UsageInterceptor.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 {
	try {
		final ZonedDateTime now = ZonedDateTime.now();
		final String username = Utils.getUserName();
		final int companyID = Utils.getUserCompany();
		
		this.usageLogger.logWebserviceUsage(now, endpoint.getClass().getCanonicalName(), companyID, username);
	} catch(final Exception e) {
		logger.warn("Error logging webservice usage", e);
	}

	return true;	// Continue processing of Interceptor chain

}
 
Example #9
Source File: AbstractXTeeBaseEndpoint.java    From j-road with Apache License 2.0 5 votes vote down vote up
public final void invoke(MessageContext messageContext) throws Exception {
  SOAPMessage paringMessage = SOAPUtil.extractSoapMessage(messageContext.getRequest());
  SOAPMessage responseMessage = SOAPUtil.extractSoapMessage(messageContext.getResponse());

  version = parseProtocolVersion(paringMessage);

  // meta-service does not need 'header' element
  if (metaService) {
    responseMessage.getSOAPHeader().detachNode();
  }

  Document paring = metaService ? null : parseQuery(paringMessage);
  getResponse(paring, responseMessage, paringMessage);
}
 
Example #10
Source File: TraceeEndpointInterceptor.java    From tracee with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean handleRequest(MessageContext messageContext, Object o) {
	parseContextFromSoapHeader(messageContext.getRequest(), IncomingRequest);

	Utilities.generateInvocationIdIfNecessary(backend);
	return true;
}
 
Example #11
Source File: TraceeEndpointInterceptor.java    From tracee with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void afterCompletion(MessageContext messageContext, Object o, Exception e) {
	backend.clear();
}
 
Example #12
Source File: WSConsumptionLoggingInterceptor.java    From j-road with Apache License 2.0 4 votes vote down vote up
/**
 * X-tee soap fault messages are different than ordinary SOAP fault messages.
 */
public boolean handleFault(MessageContext mc) throws WebServiceClientException {
  return logMessage(mc, MessageType.FAULT);
}
 
Example #13
Source File: WSConsumptionLoggingInterceptor.java    From j-road with Apache License 2.0 4 votes vote down vote up
public boolean handleRequest(MessageContext mc) throws WebServiceClientException {
  return logMessage(mc, MessageType.REQUEST);
}
 
Example #14
Source File: WSConsumptionLoggingInterceptor.java    From j-road with Apache License 2.0 4 votes vote down vote up
public boolean handleResponse(MessageContext mc) throws WebServiceClientException {
  return logMessage(mc, MessageType.RESPONSE);
}
 
Example #15
Source File: TraceeEndpointInterceptor.java    From tracee with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public boolean handleResponse(MessageContext messageContext, Object o) {
	serializeContextToSoapHeader(messageContext.getResponse(), OutgoingResponse);
	return true;
}
 
Example #16
Source File: TraceeEndpointInterceptor.java    From tracee with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public boolean handleFault(MessageContext messageContext, Object o) {
	return handleResponse(messageContext, o);
}
 
Example #17
Source File: LogHttpHeaderClientInterceptor.java    From spring-ws with MIT License 4 votes vote down vote up
@Override
public boolean handleResponse(MessageContext messageContext) throws WebServiceClientException {
  HttpLoggingUtils.logMessage("Client Response Message", messageContext.getResponse());

  return true;
}
 
Example #18
Source File: TraceeClientInterceptor.java    From tracee with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public boolean handleRequest(MessageContext messageContext) {
	serializeContextToSoapHeader(messageContext.getRequest(), OutgoingRequest);
	return true;
}
 
Example #19
Source File: TraceeClientInterceptor.java    From tracee with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public boolean handleResponse(MessageContext messageContext) {
	parseContextFromSoapHeader(messageContext.getResponse(), IncomingResponse);
	return true;
}
 
Example #20
Source File: TraceeClientInterceptor.java    From tracee with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public boolean handleFault(MessageContext messageContext) {
	return handleResponse(messageContext);
}
 
Example #21
Source File: TraceeEndpointInterceptorTest.java    From tracee with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void shouldCleanupBackendAfterInvocation() throws Exception {
	unit.afterCompletion(mock(MessageContext.class), new Object(), mock(Exception.class));
	verify(backend).clear();
}
 
Example #22
Source File: ThrottlingInterceptor.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void afterCompletion(MessageContext arg0, Object arg1, Exception arg2) throws Exception {
	// do nothing
}
 
Example #23
Source File: PermissionCheckingEndpointInterceptor.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public final boolean handleFault(final MessageContext messageContext, final Object endpoint) throws Exception {
	return true;
}
 
Example #24
Source File: PermissionCheckingEndpointInterceptor.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public final boolean handleResponse(final MessageContext messageContext, final Object endpoint) throws Exception {
	return true;
}
 
Example #25
Source File: UsageInterceptor.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public final void afterCompletion(MessageContext messageContext, final Object endpoint, Exception exception) throws Exception {
	// Nothing to do here
}
 
Example #26
Source File: UsageInterceptor.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public final boolean handleFault(final MessageContext messageContext, final Object endpoint) throws Exception {
	// Nothing to do here
	
	return true;	// Continue processing of Interceptor chain
}
 
Example #27
Source File: UsageInterceptor.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public final boolean handleResponse(final MessageContext messageContext, final Object endpoint) throws Exception {
	// Nothing to do here

	return true;	// Continue processing of Interceptor chain
}
 
Example #28
Source File: ThrottlingInterceptor.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public boolean handleFault(MessageContext paramMessageContext,
		Object paramObject) throws Exception {
	
	return true;
}
 
Example #29
Source File: ThrottlingInterceptor.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public boolean handleResponse(MessageContext paramMessageContext,
		Object paramObject) throws Exception {
	
	return true;
}
 
Example #30
Source File: PermissionCheckingEndpointInterceptor.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public final void afterCompletion(final MessageContext messageContext, final Object endpoint, final Exception arg2) throws Exception {
	// Nothing to do
}