本文整理汇总了Java中org.springframework.ws.WebServiceMessage类的典型用法代码示例。如果您正苦于以下问题:Java WebServiceMessage类的具体用法?Java WebServiceMessage怎么用?Java WebServiceMessage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WebServiceMessage类属于org.springframework.ws包,在下文中一共展示了WebServiceMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testInvalidResponse
import org.springframework.ws.WebServiceMessage; //导入依赖的package包/类
@Test
@SuppressWarnings("unused")
public void testInvalidResponse() throws IOException
{
WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
webServiceTemplate.setCheckConnectionForFault(false);
MockWebServiceMessageSender messageSender = new MockWebServiceMessageSender();
DefaultResponseGenerator responseGenerator = new DefaultResponseGenerator();
responseGenerator.setNeverCreateEnvelope(true);
SimpleResourceLookup resourceLookup = new SimpleResourceLookup(new ClassPathResource("mock-responses/test/default-response-invalid.xml"));
resourceLookup.setTemplateProcessor(new TemplateProcessor() {
public Resource processTemplate(Resource resource, WebServiceMessage message) throws IOException {
return resource;
}
});
responseGenerator.setResourceLookup(resourceLookup);
messageSender.setRequestProcessors(Arrays.asList(responseGenerator));
webServiceTemplate.setMessageSender(messageSender);
Source source = getValidMessage().getPayloadSource();
StringResult result = new StringResult();
//TODO uncomment
// webServiceTemplate.sendSourceAndReceiveToResult(TEST_URI.toString(), source, result);
}
示例2: transformHeaders
import org.springframework.ws.WebServiceMessage; //导入依赖的package包/类
protected void transformHeaders(WebServiceMessage reqMessage, WebServiceMessage respMessage)
throws TransformerException, SOAPException {
SoapHeader reqHeader = getSoapHeader(reqMessage);
SoapHeader respHeader = getSoapHeader(respMessage);
TransformerFactory transformerFactory = TransformerFactory
.newInstance();
Transformer transformer = transformerFactory.newTransformer();
Iterator<SoapHeaderElement> iter = reqHeader.examineAllHeaderElements();
while (iter.hasNext()) {
SoapHeaderElement elem = iter.next();
transformer.transform(elem.getSource(), respHeader.getResult());
}
}
示例3: listFlights
import org.springframework.ws.WebServiceMessage; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public List<BigInteger> listFlights() {
ObjectFactory factory = new ObjectFactory();
TListFlights tListFlights = factory.createTListFlights();
JAXBElement<TListFlights> request = factory.createListFlightsRequest(tListFlights);
JAXBElement<TFlightsResponse> response = (JAXBElement<TFlightsResponse>) webServiceTemplate
.marshalSendAndReceive(request, new WebServiceMessageCallback() {
public void doWithMessage(WebServiceMessage message) {
TransportContext context = TransportContextHolder.getTransportContext();
HttpUrlConnection connection = (HttpUrlConnection) context.getConnection();
connection.getConnection().addRequestProperty("Authorization",
BasicAuthenticationUtil.generateBasicAutenticationHeader(clientConfig.getUserName(),
clientConfig.getUserPassword()));
}
});
return response.getValue().getFlightNumber();
}
示例4: invoke
import org.springframework.ws.WebServiceMessage; //导入依赖的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());
}
}
}
示例5: getMessage
import org.springframework.ws.WebServiceMessage; //导入依赖的package包/类
/**
* Retrieves the XML message from the WebServiceMessage obj using the transformer,
* returns null in case source is null
*
* @param source to retrieve the SOAP message
* @return String XML formatted
* @throws Exception
*/
private String getMessage(WebServiceMessage message) throws Exception {
Source source = message.getPayloadSource();
if (source != null) {
Transformer transformer = createNonIndentingTransformer();
StringWriter writer = new StringWriter();
transformer.transform(source, new StreamResult(writer));
//Retrieve msg and remove break line if requested
String msg = writer.toString();
if (removeNewline) {
msg = StringUtils.remove(msg, System.getProperty("line.separator"));
}
//Return processed message
return msg;
}
return null;
}
开发者ID:SpartaTech,项目名称:sparta-spring-webservice-utils,代码行数:27,代码来源:PayloadLoggingClientInterceptor.java
示例6: addSecurity
import org.springframework.ws.WebServiceMessage; //导入依赖的package包/类
/**
* Agrega seguridad a una llamada a un servicio, para ello agrega dos header
* params, pertenecientes a Usuario y Password.
*
* @param user
* usuario de la llamada
* @param password
* contraseña del que invoca el servicio.
* @param message
* mensaje que actualmente se esta enviando
*/
public void addSecurity(String user, String password,
WebServiceMessage message) {
Charset cs = Charset.forName(CharEncoding.UTF_8);
TransportContext context = TransportContextHolder.getTransportContext();
HttpUrlConnection connection = (HttpUrlConnection) context
.getConnection();
HttpURLConnection uRLConnection = connection.getConnection();
String auth = CREDENTIALS_FORMAT.replace("USER", user).replace(
"PASSWORD", password);
byte[] encode = Base64.encode(auth.getBytes(cs));
uRLConnection.addRequestProperty(AUTHORIZATION_HEADER_PARAM,
HEADER_CREDENTIALS_FORMAT.replace("CREDENTIALS", new String(
encode, cs)));
}
示例7: resolveFault
import org.springframework.ws.WebServiceMessage; //导入依赖的package包/类
@Override
public void resolveFault(WebServiceMessage message) throws IOException {
SoapMessage message2 = (SoapMessage) message;
SoapBody body = message2.getSoapBody();
// No Fault object, go to fallback
if (body.getFault() == null
|| body.getFault().getFaultDetail() == null
|| !body.getFault().getFaultDetail().getDetailEntries()
.hasNext()) {
fallBack(message2);
}
SoapFaultDetail sfd = body.getFault().getFaultDetail();
tryHttpException(message2, sfd.getDetailEntries().next());
}
示例8: responseMarshaller
import org.springframework.ws.WebServiceMessage; //导入依赖的package包/类
/**
* Retorna un {@link ResponseMatcher} que marshaliza el resultado.
*
* <p>
* Este {@link ResponseMatcher} no realiza ninguna acción, siempre valida y
* se encarga de parsear el resultado
* </p>
*
* @return dummy {@link ResponseMatcher}
*/
public ResponseMatcher responseMarshaller() {
return new ResponseMatcher() {
@Override
public void match(WebServiceMessage request,
WebServiceMessage response) throws IOException,
AssertionError {
WebServiceMessage dos = response;
Source source = dos.getPayloadSource();
result = unmarshaller.unmarshal(source);
}
};
}
示例9: doWithMessage
import org.springframework.ws.WebServiceMessage; //导入依赖的package包/类
@Override
public void doWithMessage(WebServiceMessage request) throws IOException, TransformerException {
callback.doWithMessage(request);
SaajSoapMessage message = (SaajSoapMessage) request;
SOAPMessage mes = message.getSaajMessage();
try {
SOAPBody body = mes.getSOAPBody();
SOAPElement queryEle = (SOAPElement) body.getChildElements().next();
SOAPElement kehaEle = (SOAPElement) queryEle.getChildElements().next();
java.util.Iterator kehaChilds = kehaEle.getChildElements();
while (kehaChilds.hasNext()) {
Object nextEle = kehaChilds.next();
if (nextEle instanceof SOAPElement) {
addType((SOAPElement) nextEle);
}
}
} catch(Exception ex) {
ex.printStackTrace();
}
}
示例10: doWithMessage
import org.springframework.ws.WebServiceMessage; //导入依赖的package包/类
public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException {
callback.doWithMessage(message);
try {
SaajSoapMessage saajMessage = (SaajSoapMessage) message;
SOAPMessage soapmess = saajMessage.getSaajMessage();
SOAPEnvelope env = soapmess.getSOAPPart().getEnvelope();
env.addNamespaceDeclaration("xro", "http://x-road.ee/xsd/x-road.xsd");
Iterator headers = env.getHeader().getChildElements();
while (headers.hasNext()) {
SOAPElement header = (SOAPElement) headers.next();
if (header.getNamespaceURI().equalsIgnoreCase("http://x-rd.net/xsd/xroad.xsd")) {
String localHeaderName = header.getLocalName();
QName qName = new QName("http://x-road.ee/xsd/x-road.xsd", localHeaderName, "xro");
header.setElementQName(qName);
}
}
} catch (SOAPException e) {
throw new RuntimeException(e);
}
}
示例11: doWithMessage
import org.springframework.ws.WebServiceMessage; //导入依赖的package包/类
public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException {
callback.doWithMessage(message);
try {
SaajSoapMessage saajMsg = (SaajSoapMessage) message;
SOAPMessage soapMsg = saajMsg.getSaajMessage();
SOAPEnvelope env = soapMsg.getSOAPPart().getEnvelope();
env.addNamespaceDeclaration(ns, nsV31Uri);
Iterator headers = env.getHeader().getChildElements();
while (headers.hasNext()) {
SOAPElement header = (SOAPElement) headers.next();
if (header.getNamespaceURI().equalsIgnoreCase(nsV30Uri)) {
QName qName = new QName(nsV31Uri, header.getLocalName(), ns);
header.setElementQName(qName);
}
}
formatDate(saajMsg, startDate);
formatDate(saajMsg, endDate);
} catch (SOAPException e) {
throw new RuntimeException(e);
}
}
示例12: substitute
import org.springframework.ws.WebServiceMessage; //导入依赖的package包/类
/**
* Substitutes all occurences of some given string inside the given {@link WebServiceMessage} with another value.
*
* @param message message to substitute in
* @param from the value to substitute
* @param to the value to substitute with
* @throws TransformerException
*/
public static void substitute(WebServiceMessage message, String from, String to) throws TransformerException {
SaajSoapMessage saajSoapMessage = (SaajSoapMessage) message;
SOAPPart soapPart = saajSoapMessage.getSaajMessage().getSOAPPart();
Source source = new DOMSource(soapPart);
StringResult stringResult = new StringResult();
TransformerFactory.newInstance().newTransformer().transform(source, stringResult);
String content = stringResult.toString().replaceAll(from, to);
try {
soapPart.setContent(new StringSource(content));
} catch (SOAPException e) {
throw new TransformerException(e);
}
}
示例13: doWithMessage
import org.springframework.ws.WebServiceMessage; //导入依赖的package包/类
public void doWithMessage(WebServiceMessage message) {
SaajSoapMessage saajMessage = (SaajSoapMessage) message;
try {
// Add attachments
if (attachments != null) {
for (XRoadAttachment attachment : attachments) {
saajMessage.addAttachment("<" + attachment.getCid() + ">", attachment, attachment.getContentType());
}
}
SOAPMessage soapmess = saajMessage.getSaajMessage();
SOAPEnvelope env = soapmess.getSOAPPart().getEnvelope();
protocolVersionStrategy.addNamespaces(env);
protocolVersionStrategy.addXTeeHeaderElements(env, serviceConfiguration);
} catch (SOAPException e) {
throw new RuntimeException(e);
}
}
示例14: logMessage
import org.springframework.ws.WebServiceMessage; //导入依赖的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;
}
示例15: createSoapMessage
import org.springframework.ws.WebServiceMessage; //导入依赖的package包/类
/**
* Creates a new SOAP message representation from given payload resource. Constructs a SOAP envelope
* with empty header and payload as body.
*
* @param message
* @return
* @throws IOException
*/
public Message createSoapMessage(Message message) {
try {
String payload = message.getPayload().toString();
LOG.info("Creating SOAP message from payload: " + payload);
WebServiceMessage soapMessage = soapMessageFactory.createWebServiceMessage();
transformerFactory.newTransformer().transform(
new StringSource(payload), soapMessage.getPayloadResult());
ByteArrayOutputStream bos = new ByteArrayOutputStream();
soapMessage.writeTo(bos);
return new SoapMessage(new String(bos.toByteArray()), message.getHeaders());
} catch (Exception e) {
throw new CitrusRuntimeException("Failed to create SOAP message from payload resource", e);
}
}