Java Examples for org.springframework.ws.client.core.WebServiceMessageCallback
The following java examples will help you to understand the usage of org.springframework.ws.client.core.WebServiceMessageCallback. These source code samples are taken from different open source projects.
Example 1
| Project: BlackboardVCPortlet-master File: SASWebServiceTemplate.java View source code |
@Override
public Object marshalSendAndReceiveToSAS(final String soapAction, final Object requestPayload) {
return marshalSendAndReceive(requestPayload, new WebServiceMessageCallback() {
@Override
public void doWithMessage(WebServiceMessage webServiceMessage) throws IOException, TransformerException {
if (webServiceMessage instanceof SaajSoapMessage) {
final SaajSoapMessage casted = (SaajSoapMessage) webServiceMessage;
casted.setSoapAction(soapAction);
QName qName = new QName(elluminateMarshller.getContextPath(), "BasicAuth", "sas");
try {
SOAPElement baHeader = casted.getSaajMessage().getSOAPHeader().addChildElement(qName);
baHeader.addChildElement(new QName("sas", "Name")).addTextNode(username);
baHeader.addChildElement(new QName("sas", "Password")).addTextNode(password);
} catch (Exception e) {
logger.error("Error creating SOAPHeader: ", e);
}
}
}
});
}Example 2
| Project: smock-master File: AbstractMockWebServiceServerTest.java View source code |
protected WebServiceMessage sendMessage(String uri, final String request) {
WebServiceTemplate template = new WebServiceTemplate();
template.afterPropertiesSet();
WebServiceMessage response = template.sendAndReceive(uri, new WebServiceMessageCallback() {
public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException {
transform(loadMessage(request), message.getPayloadResult());
}
}, new WebServiceMessageExtractor<WebServiceMessage>() {
public WebServiceMessage extractData(WebServiceMessage message) throws IOException, TransformerException {
return message;
}
});
return response;
}Example 3
| Project: spring-ws-samples-master File: AxiomMtomClient.java View source code |
private void store(final String path) {
stopWatch.start("store");
getWebServiceTemplate().sendAndReceive(new WebServiceMessageCallback() {
public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException {
AxiomSoapMessage soapMessage = (AxiomSoapMessage) message;
SOAPMessage axiomMessage = soapMessage.getAxiomMessage();
SOAPFactory factory = (SOAPFactory) axiomMessage.getOMFactory();
SOAPBody body = axiomMessage.getSOAPEnvelope().getBody();
OMNamespace ns = factory.createOMNamespace("http://www.springframework.org/spring-ws/samples/mtom", "tns");
OMElement storeImageRequestElement = factory.createOMElement("StoreImageRequest", ns);
body.addChild(storeImageRequestElement);
OMElement nameElement = factory.createOMElement("name", ns);
storeImageRequestElement.addChild(nameElement);
nameElement.setText(StringUtils.getFilename(path));
OMElement imageElement = factory.createOMElement("image", ns);
storeImageRequestElement.addChild(imageElement);
DataSource dataSource = new FileDataSource(path);
DataHandler dataHandler = new DataHandler(dataSource);
OMText text = factory.createOMText(dataHandler, true);
imageElement.addChild(text);
OMOutputFormat outputFormat = new OMOutputFormat();
outputFormat.setSOAP11(true);
outputFormat.setDoOptimize(true);
soapMessage.setOutputFormat(outputFormat);
}
}, new WebServiceMessageExtractor() {
public Object extractData(WebServiceMessage message) throws IOException, TransformerException {
return null;
}
});
stopWatch.stop();
}Example 4
| Project: camel-spring-ws-master File: SpringWebserviceProducer.java View source code |
public void process(Exchange exchange) throws Exception {
// Let Camel TypeConverter hierarchy handle the conversion of XML messages to Source objects
Source sourcePayload = exchange.getIn().getMandatoryBody(Source.class);
// Extract optional headers
String endpointUri = exchange.getIn().getHeader(SpringWebserviceConstants.SPRING_WS_ENDPOINT_URI, String.class);
String soapAction = exchange.getIn().getHeader(SpringWebserviceConstants.SPRING_WS_SOAP_ACTION, String.class);
URI wsAddressingAction = exchange.getIn().getHeader(SpringWebserviceConstants.SPRING_WS_ADDRESSING_ACTION, URI.class);
WebServiceMessageCallback callback = new DefaultWebserviceMessageCallback(soapAction, wsAddressingAction);
Object body = null;
if (endpointUri != null) {
body = endpoint.getConfiguration().getWebServiceTemplate().sendSourceAndReceive(endpointUri, sourcePayload, callback, sourceExtractor);
} else {
body = endpoint.getConfiguration().getWebServiceTemplate().sendSourceAndReceive(sourcePayload, callback, sourceExtractor);
}
exchange.getOut().setBody(body);
}Example 5
| Project: AQL_sms_soap_api-master File: AqlMTSoapClient.java View source code |
/**
* <p>Set the callback url in the message before sending.</p>
*
* @param mTMessage
* @return Response
* @throws com.aql.message.AqlException if the message was not successfully processed by the Aql SoapSendSms service
*/
public MTResponse sendMTMessage(final MTMessage mTMessage) throws AqlException {
if (logger.isDebugEnabled())
logger.debug("AqlMTSmsSoapClient is sending an MT Message with id " + mTMessage.getId());
mTMessage.setCallbackUrl(callbackUrl);
MTResponse response = (MTResponse) webServiceTemplate.marshalSendAndReceive(mTMessage, new WebServiceMessageCallback() {
/**
* Add the header before sending.
*
* @param webServiceMessage
*/
public void doWithMessage(WebServiceMessage webServiceMessage) {
try {
SoapMessage soapMessage = (SoapMessage) webServiceMessage;
SoapHeader soapHeader = soapMessage.getSoapHeader();
StringSource headerSource = new StringSource(headerBuffer.toString());
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.transform(headerSource, soapHeader.getResult());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
if (!response.getResponseCode().equals(MTResponse.OK))
throw new AqlException("message send error " + response.getDescription());
if (logger.isDebugEnabled())
logger.debug("Aql soap api responded successfully - " + response.getDescription());
return response;
}Example 6
| Project: exchange-ws-client-master File: ExchangeWebServicesClient.java View source code |
/**
*
* @param request
* @return
*/
protected Object internalInvoke(Object request, WebServiceMessageCallback callback) {
try {
Object result;
log.trace("ExchangeRequest=" + request);
if (null == callback) {
result = getWebServiceTemplate().marshalSendAndReceive(request);
} else {
result = getWebServiceTemplate().marshalSendAndReceive(request, callback);
}
return result;
} catch (SoapFaultClientException e) {
if (e.getMessage().equals("The impersonation principal name is invalid.")) {
throw new ExchangeInvalidUPNRuntimeException(e);
}
if (log.isTraceEnabled()) {
log.error("SoapFaultClientException encountered for " + request + ". " + e.getMessage());
} else {
log.error("SoapFaultClientException encountered " + e.getMessage());
}
throw new ExchangeWebServicesRuntimeException(e);
}
}Example 7
| Project: j-road-master File: StandardXRoadConsumer.java View source code |
@SuppressWarnings({ "unchecked", "rawtypes" })
private <I, O> XRoadMessage<O> sendRealRequest(XRoadMessage<I> input, XRoadServiceConfiguration xroadServiceConfiguration, CustomCallback callback, CustomExtractor extractor) throws XRoadServiceConsumptionException {
try {
// First find all Objects.
for (XmlObject attachmentObj : XmlBeansUtil.getAllObjects((XmlObject) input.getContent())) {
// Introspect all methods, and find the ones that were generated during instrumentation
for (Method method : XmlBeansUtil.getSwaRefGetters(attachmentObj)) {
// Get the datahandler for the attachment
DataHandler handler = (DataHandler) method.invoke(attachmentObj);
if (handler != null) {
String field = XmlBeansUtil.getFieldName(method);
// Check whether the user has set a custom CID, if not, generate a random one and set it
String cid = XmlBeansUtil.getCid(attachmentObj, field);
if (cid == null) {
cid = AttachmentUtil.getUniqueCid();
} else {
cid = cid.startsWith("cid:") ? cid.substring(4) : cid;
}
XmlBeansUtil.setCid(attachmentObj, field, "cid:" + cid);
// Add a new attachment to the list
input.getAttachments().add(new XRoadAttachment(cid, handler));
}
}
}
XmlBeansXRoadMetadata curdata = metadata.get(xroadServiceConfiguration.getWsdlDatabase().toLowerCase() + xroadServiceConfiguration.getMethod().toLowerCase());
if (curdata == null) {
throw new IllegalStateException(String.format("Could not find metadata for %s.%s! Most likely the method name has been specified incorrectly.", xroadServiceConfiguration.getWsdlDatabase().toLowerCase(), xroadServiceConfiguration.getMethod().toLowerCase()));
}
WebServiceMessageCallback originalCallback = getNewConsumerCallback(input, xroadServiceConfiguration, curdata);
WebServiceMessageExtractor originalExtractor = new StandardXRoadConsumerMessageExtractor(curdata);
if (callback != null) {
callback.setOriginalCallback(originalCallback);
}
WebServiceMessageCallback finalCallback = callback == null ? originalCallback : callback;
if (extractor != null) {
extractor.setOriginalExtractor(originalExtractor);
}
WebServiceMessageExtractor finalExtractor = extractor == null ? originalExtractor : extractor;
return (XRoadMessage<O>) getWebServiceTemplate().sendAndReceive(xroadServiceConfiguration.getSecurityServer(), finalCallback, finalExtractor);
} catch (Exception e) {
e.printStackTrace();
XRoadServiceConsumptionException consumptionException = resolveException(e, xroadServiceConfiguration);
if (consumptionException != null) {
throw consumptionException;
}
throw new NestableRuntimeException(e);
}
}Example 8
| Project: spring-integration-master File: WebServiceOutboundGatewayParserTests.java View source code |
@Test
public void simpleGatewayWithCustomRequestCallback() {
AbstractEndpoint endpoint = this.context.getBean("gatewayWithCustomRequestCallback", AbstractEndpoint.class);
assertEquals(EventDrivenConsumer.class, endpoint.getClass());
Object gateway = new DirectFieldAccessor(endpoint).getPropertyValue("handler");
assertEquals(SimpleWebServiceOutboundGateway.class, gateway.getClass());
DirectFieldAccessor accessor = new DirectFieldAccessor(gateway);
WebServiceMessageCallback callback = (WebServiceMessageCallback) context.getBean("requestCallback");
assertEquals(callback, accessor.getPropertyValue("requestCallback"));
}Example 9
| Project: spring-ws-master File: MockWebServiceServerTest.java View source code |
@Test
public void soapHeaderMatch() throws Exception {
final QName soapHeaderName = new QName("http://example.com", "mySoapHeader");
server.expect(soapHeader(soapHeaderName));
template.sendSourceAndReceiveToResult(new StringSource("<request xmlns='http://example.com'/>"), new WebServiceMessageCallback() {
public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException {
SoapMessage soapMessage = (SoapMessage) message;
soapMessage.getSoapHeader().addHeaderElement(soapHeaderName);
}
}, new StringResult());
}Example 10
| Project: CalendarPortlet-master File: ExchangeCalendarAdapter.java View source code |
/**
* Retrieve a set of CalendarEvents from the Exchange server for the specified period and email
* address. An EWS message is constructed that looks something like the following. The <code>
* ExchangeImpersonation</code> element is optional based on whether Exchange Impersonation is
* enabled:
*
* <p>
*
* <pre>
* <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
* <SOAP-ENV:Header>
* <ns3:RequestServerVersion xmlns:ns3="http://schemas.microsoft.com/exchange/services/2006/types" Version="Exchange2007_SP1"/>
* <t:ExchangeImpersonation xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
* <t:ConnectingSID>
* <t:PrincipalName>o365st19@ed.ac.uk</t:PrincipalName>
* </t:ConnectingSID>
* </t:ExchangeImpersonation>
* <ns3:RequestServerVersion xmlns:ns3="http://schemas.microsoft.com/exchange/services/2006/types" Version="requestServerVersion"/><t:ExchangeImpersonation xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"><t:ConnectingSID><t:PrincipalName>impersonatedUser@ed.ac.uk</t:PrincipalName></t:ConnectingSID></t:ExchangeImpersonation></SOAP-ENV:Header>
* <SOAP-ENV:Body>
* <ns2:FindItem xmlns:ns2="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:ns3="http://schemas.microsoft.com/exchange/services/2006/types" Traversal="Shallow">
* <ns2:ItemShape>
* <ns3:BaseShape>AllProperties</ns3:BaseShape>
* </ns2:ItemShape>
* <ns2:ParentFolderIds>
* <ns3:DistinguishedFolderId Id="inbox"/>
* </ns2:ParentFolderIds>
* </ns2:FindItem>
* </SOAP-ENV:Body>
* </SOAP-ENV:Envelope>
* </pre>
*
* @param request Portlet request
* @param calendar calendar configuration
* @param interval interval to retrieve events for
* @param emailAddress email address of the user to retrieve events for
* @return Set of calendar events from the Exchange Server.
* @throws CalendarException
*/
private Set<VEvent> retrieveExchangeEvents(PortletRequest request, CalendarConfiguration calendar, Interval interval, String emailAddress) throws CalendarException {
log.debug("Retrieving exchange events for period: {}", interval);
Set<VEvent> events = new HashSet<VEvent>();
try {
// construct the SOAP request object to use
GetUserAvailabilityRequest soapRequest = getAvailabilityRequest(interval, emailAddress);
final WebServiceMessageCallback customCallback = new ExchangeWebServiceCallBack(AVAILABILITY_SOAP_ACTION, requestServerVersion, credentialsService.getImpersonatedAccountId(request));
// use the request to retrieve data from the Exchange server
GetUserAvailabilityResponse response = (GetUserAvailabilityResponse) webServiceOperations.marshalSendAndReceive(soapRequest, customCallback);
// for each FreeBusy response, parse the list of events
for (FreeBusyResponseType freeBusy : response.getFreeBusyResponseArray().getFreeBusyResponses()) {
ArrayOfCalendarEvent eventArray = freeBusy.getFreeBusyView().getCalendarEventArray();
if (eventArray != null && eventArray.getCalendarEvents() != null) {
List<com.microsoft.exchange.types.CalendarEvent> msEvents = eventArray.getCalendarEvents();
for (com.microsoft.exchange.types.CalendarEvent msEvent : msEvents) {
// add the new event to the list
VEvent event = getInternalEvent(calendar.getId(), msEvent);
events.add(event);
}
}
}
} catch (DatatypeConfigurationException e) {
throw new CalendarException(e);
}
return events;
}Example 11
| Project: email-preview-master File: ExchangeAccountDaoImpl.java View source code |
// ----------------------------------------------------------
// common send message and parse response
// ----------------------------------------------------------
private BaseResponseMessageType sendSoapRequest(BaseRequestType soapRequest, String soapAction, MailStoreConfiguration config) {
String uri = autoDiscoveryDao.getEndpointUri(config);
try {
final WebServiceMessageCallback actionCallback = new SoapActionCallback(soapAction);
final WebServiceMessageCallback customCallback = new WebServiceMessageCallback() {
@Override
public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException {
actionCallback.doWithMessage(message);
SoapMessage soap = (SoapMessage) message;
SoapHeaderElement version = soap.getEnvelope().getHeader().addHeaderElement(REQUEST_SERVER_VERSION_QNAME);
version.addAttribute(new QName("Version"), "Exchange2007_SP1");
}
};
if (log.isDebugEnabled()) {
StringResult message = new StringResult();
try {
marshaller.marshal(soapRequest, message);
log.debug("Attempting to send SOAP request to {}\nSoap Action: {}\nSoap message body" + " (not exact, log org.apache.http.wire to see actual message):\n{}", uri, soapAction, message);
} catch (IOException ex) {
log.debug("IOException attempting to display soap response", ex);
}
}
// use the request to retrieve data from the Exchange server
BaseResponseMessageType response = (BaseResponseMessageType) webServiceOperations.marshalSendAndReceive(uri, soapRequest, customCallback);
if (log.isDebugEnabled()) {
StringResult messageResponse = new StringResult();
try {
marshaller.marshal(response, messageResponse);
log.debug("Soap response body (not exact, log org.apache.http.wire to see actual message):\n{}", messageResponse);
} catch (IOException ex) {
log.debug("IOException attempting to display soap response", ex);
}
}
return response;
} catch (WebServiceClientException e) {
throw new EmailPreviewException(e);
}
//todo figure out if we can catch authentication exceptions to return them separate. Useful?
}Example 12
| Project: ws-proxy-master File: ForwardingClient.java View source code |
public WebServiceMessage forward(final QName webServiceIdentifier, final WebServiceMessage webServiceMessage, final HttpServletRequest httpServletRequest) {
final SaajSoapMessage responseMessage = (SaajSoapMessage) webServiceMessageFactory.createWebServiceMessage();
String targetUrl = calculateTargetUrl(webServiceIdentifier, httpServletRequest);
WebServiceTemplate webServiceTemplate = createAndConfigureWebServiceTemplate(responseMessage, webServiceIdentifier, httpServletRequest);
webServiceTemplate.sendAndReceive(targetUrl, new WebServiceMessageCallback() {
@Override
public void doWithMessage(WebServiceMessage message) throws IOException {
SaajSoapMessage saajSoapMessage = ((SaajSoapMessage) message);
saajSoapMessage.setSaajMessage(((SaajSoapMessage) webServiceMessage).getSaajMessage());
new SoapActionCallback(httpServletRequest.getHeader(SOAP_ACTION_HEADER)).doWithMessage(message);
}
}, new WebServiceMessageCallback() {
@Override
public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException {
try {
responseMessage.getSaajMessage().getSOAPPart().setContent(((SaajSoapMessage) message).getEnvelope().getSource());
} catch (SOAPException soapException) {
throw new RuntimeException(soapException);
}
}
});
LOG.debug("Forwarding (" + targetUrl + ") done.");
return responseMessage;
}Example 13
| Project: camel-master File: SpringWebserviceProducer.java View source code |
public void process(Exchange exchange) throws Exception {
// Let Camel TypeConverter hierarchy handle the conversion of XML messages to Source objects
Source sourcePayload = exchange.getIn().getMandatoryBody(Source.class);
// Extract optional headers
String endpointUriHeader = exchange.getIn().getHeader(SpringWebserviceConstants.SPRING_WS_ENDPOINT_URI, String.class);
String soapActionHeader = exchange.getIn().getHeader(SpringWebserviceConstants.SPRING_WS_SOAP_ACTION, String.class);
URI wsAddressingActionHeader = exchange.getIn().getHeader(SpringWebserviceConstants.SPRING_WS_ADDRESSING_ACTION, URI.class);
URI wsReplyToHeader = exchange.getIn().getHeader(SpringWebserviceConstants.SPRING_WS_ADDRESSING_PRODUCER_REPLY_TO, URI.class);
URI wsFaultToHeader = exchange.getIn().getHeader(SpringWebserviceConstants.SPRING_WS_ADDRESSING_PRODUCER_FAULT_TO, URI.class);
Source soapHeaderSource = exchange.getIn().getHeader(SpringWebserviceConstants.SPRING_WS_SOAP_HEADER, Source.class);
WebServiceMessageCallback callback = new DefaultWebserviceMessageCallback(soapActionHeader, wsAddressingActionHeader, wsReplyToHeader, wsFaultToHeader, soapHeaderSource, getEndpoint().getConfiguration(), exchange);
if (endpointUriHeader == null) {
endpointUriHeader = getEndpoint().getConfiguration().getWebServiceTemplate().getDefaultUri();
}
getEndpoint().getConfiguration().getWebServiceTemplate().sendAndReceive(endpointUriHeader, new WebServiceMessageCallback() {
@Override
public void doWithMessage(WebServiceMessage requestMessage) throws IOException, TransformerException {
XML_CONVERTER.toResult(sourcePayload, requestMessage.getPayloadResult());
callback.doWithMessage(requestMessage);
}
}, new WebServiceMessageCallback() {
@Override
public void doWithMessage(WebServiceMessage responseMessage) throws IOException, TransformerException {
SoapMessage soapMessage = (SoapMessage) responseMessage;
if (ExchangeHelper.isOutCapable(exchange)) {
exchange.getOut().copyFromWithNewBody(exchange.getIn(), soapMessage.getPayloadSource());
populateHeaderAndAttachmentsFromResponse(exchange.getOut(), soapMessage);
} else {
exchange.getIn().setBody(soapMessage.getPayloadSource());
populateHeaderAndAttachmentsFromResponse(exchange.getIn(), soapMessage);
}
}
});
}Example 14
| Project: Carolina-Digital-Repository-master File: AccessClient.java View source code |
WebServiceMessageCallback callback() { return new WebServiceMessageCallback() { @Override public void doWithMessage(WebServiceMessage message) { ((SoapMessage) message).setSoapAction(uri); } }; }