本文整理汇总了Java中org.springframework.ws.context.MessageContext类的典型用法代码示例。如果您正苦于以下问题:Java MessageContext类的具体用法?Java MessageContext怎么用?Java MessageContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MessageContext类属于org.springframework.ws.context包,在下文中一共展示了MessageContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleRequest
import org.springframework.ws.context.MessageContext; //导入依赖的package包/类
@Override
public boolean handleRequest(MessageContext messageContext) throws WebServiceClientException {
TransportContext transportContext = TransportContextHolder.getTransportContext();
WebServiceConnection webServiceConnection = transportContext.getConnection();
final String tenant = TenantContextHolder.getContext().getTenant();
if (webServiceConnection instanceof HeadersAwareSenderWebServiceConnection) {
if (StringUtils.hasText(tenant)) {
try {
((HeadersAwareSenderWebServiceConnection) webServiceConnection).addRequestHeader(getHeaderName(), tenant);
} catch (IOException e) {
throw new WebServiceIOException("Error setting header '" + getHeaderName() + "' on connection.", e);
}
}
}
return true;
}
示例2: handleResponse
import org.springframework.ws.context.MessageContext; //导入依赖的package包/类
@SuppressWarnings("serial")
@Override
public boolean handleResponse(MessageContext messageContext) {
String conversationId = null;
try {
MessageHeader header = extractMessageHeaderFromMessageContext(messageContext);
conversationId = header.getConversationId();
} catch (JAXBException | NullPointerException e) {
LOG.fatal("Error occurred during retrieving session token", e);
}
if (conversationId == null) {
throw new WebServiceClientException("Couldn't retrieve session token from message") {
};
}
logTokenAndConversationIdFromMessage("", conversationId);
sessionPool.returnToPool(conversationId);
return true;
}
示例3: invoke
import org.springframework.ws.context.MessageContext; //导入依赖的package包/类
/**
* Invoked by Spring-WS when a {@link WebServiceMessage} is received
*/
public void invoke(MessageContext messageContext) throws Exception {
Exchange exchange = getEndpoint().createExchange(ExchangePattern.InOptionalOut);
populateExchangeFromMessageContext(messageContext, exchange);
// start message processing
getProcessor().process(exchange);
if (exchange.getException() != null) {
throw exchange.getException();
} else if (exchange.getPattern().isOutCapable()) {
Message responseMessage = exchange.getOut(Message.class);
if (responseMessage != null) {
Source responseBody = responseMessage.getBody(Source.class);
WebServiceMessage response = messageContext.getResponse();
configuration.getMessageFilter().filterConsumer(exchange, response);
XmlConverter xmlConverter = configuration.getXmlConverter();
xmlConverter.toResult(responseBody, response.getPayloadResult());
}
}
}
示例4: getEndpointInternal
import org.springframework.ws.context.MessageContext; //导入依赖的package包/类
@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;
}
示例5: logMessage
import org.springframework.ws.context.MessageContext; //导入依赖的package包/类
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;
}
示例6: handleRequest
import org.springframework.ws.context.MessageContext; //导入依赖的package包/类
@Override
public boolean handleRequest(MessageContext messageContext, Object endpoint)
throws IOException, SAXException, TransformerException {
// validate payload
boolean reqValResult = super.handleRequest(messageContext, endpoint);
// validate header
if (reqValResult && validateHeader && !ignoreRequest(messageContext)) {
SaajSoapMessage soapMessage = (SaajSoapMessage) messageContext.getRequest();
SoapHeader soapHeader = soapMessage.getSoapHeader();
ValidationIntegrationException[] errors = validateHeader(soapHeader);
if (!ObjectUtils.isEmpty(errors)) {
return handleHeaderValidationErrors(messageContext, errors);
} else if (logger.isDebugEnabled()) {
logger.debug("Request header validated");
}
}
return reqValResult;
}
示例7: resolveExceptionInternal
import org.springframework.ws.context.MessageContext; //导入依赖的package包/类
@Override
protected final boolean resolveExceptionInternal(MessageContext messageContext, Object endpoint, Exception ex) {
Assert.isInstanceOf(SoapMessage.class, messageContext.getResponse(),
"SimpleSoapExceptionResolver requires a SoapMessage");
if (throttlingAsServerError && ex instanceof ThrottlingExceededException) {
// no SOAP fault => server error
return false;
} else {
SoapMessage response = (SoapMessage) messageContext.getResponse();
String faultString = StringUtils.hasLength(ex.getMessage()) ? ex.getMessage() : ex.toString();
SoapBody body = response.getSoapBody();
SoapFault fault = body.addServerOrReceiverFault(faultString, getLocale());
customizeFault(messageContext, endpoint, ex, fault);
return true;
}
}
示例8: handleInvalidXmlException
import org.springframework.ws.context.MessageContext; //导入依赖的package包/类
@Override
protected void handleInvalidXmlException(HttpServletRequest req, HttpServletResponse res, Object handler,
InvalidXmlException ex) throws Exception {
WebServiceConnection connection = new MyHttpServletConnection(req, res);
TransportContext previousTransportContext = TransportContextHolder.getTransportContext();
TransportContextHolder.setTransportContext(new DefaultTransportContext(connection));
try {
MessageContext messageContext = new DefaultMessageContext(getMessageFactory().createWebServiceMessage(),
getMessageFactory());
SoapBody soapBody = ((SoapMessage) messageContext.getResponse()).getSoapBody();
soapBody.addServerOrReceiverFault(getFaultString(ex), Locale.ENGLISH);
connection.send(messageContext.getResponse());
} finally {
TransportUtils.closeConnection(connection);
TransportContextHolder.setTransportContext(previousTransportContext);
}
}
示例9: handleValidationException
import org.springframework.ws.context.MessageContext; //导入依赖的package包/类
@Override //Overridden in order to be able to set the level of logging
protected boolean handleValidationException(WsSecurityValidationException ex, MessageContext messageContext) {
logFault.log(ex);
if (this.exceptionResolver != null) {
this.exceptionResolver.resolveException(messageContext, (Object) null, ex);
} else {
if (logger.isDebugEnabled()) {
logger.debug("No exception resolver present, creating basic soap fault");
}
SoapBody response = ((SoapMessage) messageContext.getResponse()).getSoapBody();
response.addClientOrSenderFault(ex.getMessage(), Locale.ENGLISH);
}
return false;
}
示例10: initializeRequestData
import org.springframework.ws.context.MessageContext; //导入依赖的package包/类
/**
* Creates and initializes a request data for the given message context.
*
* @param messageContext the message context
* @return the request data
*/
protected RequestData initializeRequestData(final MessageContext messageContext) {
RequestData requestData = new RequestData();
requestData.setMsgContext(messageContext);
// reads securementUsername first from the context then from the property
String contextUsername = (String) messageContext.getProperty(SECUREMENT_USER_PROPERTY_NAME);
if (StringUtils.hasLength(contextUsername)) {
requestData.setUsername(contextUsername);
} else {
requestData.setUsername(securementUsername);
}
requestData.setAppendSignatureAfterTimestamp(true);
requestData.setTimeStampTTL(securementTimeToLive);
requestData.setWssConfig(wssConfig);
return requestData;
}
示例11: doSendAndReceive
import org.springframework.ws.context.MessageContext; //导入依赖的package包/类
@Override
protected <T> T doSendAndReceive(final MessageContext messageContext, final WebServiceConnection connection,
final WebServiceMessageCallback requestCallback, final WebServiceMessageExtractor<T> responseExtractor) throws IOException {
EbmsContext ebmsContext = EbmsContext.from(messageContext);
ebmsContext.remoteParty = Optional.of(ebmsAktoerRemoteParty.orgnr);
if (requestCallback instanceof EbmsContextAware) {
((EbmsContextAware) requestCallback).setContext(ebmsContext);
}
if (responseExtractor instanceof EbmsContextAware) {
((EbmsContextAware) responseExtractor).setContext(ebmsContext);
}
try {
return super.doSendAndReceive(messageContext, connection, requestCallback, responseExtractor);
} catch (IOException e) {
throw new MessageSenderIOException(e.getMessage(), e);
}
}
示例12: handleRequest
import org.springframework.ws.context.MessageContext; //导入依赖的package包/类
@Override
public boolean handleRequest(MessageContext messageContext)
throws WebServiceClientException {
WebServiceMessage request = messageContext.getRequest();
if(request instanceof SoapMessage) {
SoapMessage soapMessage = (SoapMessage) request;
SoapEnvelope envelope = soapMessage.getEnvelope();
SoapHeader header = envelope.getHeader();
RequestServerVersion rsv = new RequestServerVersion();
try {
Marshaller m = jaxbContext.createMarshaller();
m.marshal(rsv, header.getResult());
} catch (JAXBException e) {
log.error("JAXBException raised while attempting to add RequestServerVersion to soap header " + rsv, e);
throw new ExchangeWebServicesRuntimeException("JAXBException raised while attempting to add RequestServerVersion to soap header " + rsv, e);
}
}
return true;
}
示例13: shouldInvoke
import org.springframework.ws.context.MessageContext; //导入依赖的package包/类
private boolean shouldInvoke(MessageContext messageContext) throws Exception {
List<EndpointMapping> endpointMappings = messageDispatcher.getEndpointMappings();
// There should be only one endpoint mapped in the module: check it
Assert.isTrue(endpointMappings != null && endpointMappings.size() == 1);
EndpointMapping endpointMapping = endpointMappings.iterator().next();
for (EndpointInterceptor endpointInterceptor : endpointMapping.getEndpoint(messageContext).getInterceptors()) {
// Check to see if the interceptor is directly an instance of a service specific interceptor.
// If so, we don't have to fall back to our default delegate
if (endpointInterceptor instanceof ServiceSpecificEndpointInterceptor) {
return false;
}
// Check to see if the interceptor is decorated by DelegatingSmartEndpointInterceptor
// Unfortunately there is no standard API way of detecting this, so we need some reflection.
// If so, check that the decorated instance is instance of a service specific interceptor.
// If so, we don't have to fall back to our default delegate
if (endpointInterceptor instanceof DelegatingSmartEndpointInterceptor) {
if (FieldUtils.readField(endpointInterceptor, "delegate", true) instanceof ServiceSpecificEndpointInterceptor) {
return false;
}
}
}
return true;
}
示例14: handleResponse
import org.springframework.ws.context.MessageContext; //导入依赖的package包/类
/**
* Processes response using interceptors.
* @param messageContext
* @throws IOException
*/
protected void handleResponse(MessageContext messageContext) throws IOException {
if (!interceptors.isEmpty())
{
boolean hasFault = hasFault(messageContext);
for (EndpointInterceptor interceptor:interceptors)
{
try {
if (!hasFault)
{
if (!interceptor.handleResponse(messageContext, null)) return;
}
else
{
if (!interceptor.handleFault(messageContext, null)) return;
}
} catch (Exception e) {
throw new IOException("Unexpected exception",e);
}
}
}
}
示例15: testSendMessageAndCompareResponseFail
import org.springframework.ws.context.MessageContext; //导入依赖的package包/类
@Test
public void testSendMessageAndCompareResponseFail() throws Exception
{
MessageContext message = wsTestHelper.receiveMessage("xml/valid-message.xml");
assertNotNull(message);
assertNotNull(message.getResponse().getPayloadSource());
try
{
wsTestHelper.createMessageValidator(message.getResponse()).compare("mock-responses/test/different-response.xml");
fail("Exception expected");
}
catch(WsTestException e)
{
//ok
}
}