use of javax.xml.soap.MessageFactory in project cxf by apache.
the class HWSoapMessageProvider method invoke.
public SOAPMessage invoke(SOAPMessage request) {
SOAPMessage response = null;
try {
SOAPBody body = SAAJUtils.getBody(request);
Node n = body.getFirstChild();
while (n.getNodeType() != Node.ELEMENT_NODE) {
n = n.getNextSibling();
}
if (n.getLocalName().equals(sayHi.getLocalPart())) {
response = sayHiResponse;
if (request.countAttachments() > 0) {
MessageFactory factory = MessageFactory.newInstance();
InputStream is = getClass().getResourceAsStream("resources/sayHiRpcLiteralResp.xml");
response = factory.createMessage(null, is);
is.close();
Iterator<AttachmentPart> it = CastUtils.cast(request.getAttachments(), AttachmentPart.class);
while (it.hasNext()) {
response.addAttachmentPart(it.next());
}
}
} else if (n.getLocalName().equals(greetMe.getLocalPart())) {
response = greetMeResponse;
} else {
response = request;
// response.writeTo(System.out);
}
} catch (Exception ex) {
ex.printStackTrace();
}
return response;
}
use of javax.xml.soap.MessageFactory in project quickstarts by jboss-switchyard.
the class SoapAttachmentClient method sendMessage.
public static SOAPMessage sendMessage(String switchyard_web_service) throws Exception {
SOAPConnectionFactory conFactory = SOAPConnectionFactory.newInstance();
SOAPConnection connection = conFactory.createConnection();
MessageFactory msgFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SOAPMessage msg = msgFactory.createMessage();
SOAPBodyElement bodyElement = msg.getSOAPBody().addBodyElement(new QName("urn:switchyard-quickstart:soap-attachment:1.0", "echoImage"));
bodyElement.addTextNode("cid:switchyard.png");
AttachmentPart ap = msg.createAttachmentPart();
URL imageUrl = Classes.getResource("switchyard.png");
ap.setDataHandler(new DataHandler(new URLDataSource(imageUrl)));
ap.setContentId("switchyard.png");
msg.addAttachmentPart(ap);
return connection.call(msg, new URL(switchyard_web_service));
}
use of javax.xml.soap.MessageFactory in project jbossws-cxf by jbossws.
the class JaspiClientOutInterceptor method handleMessage.
@Override
public void handleMessage(SoapMessage message) throws Fault {
if (message.getContent(SOAPMessage.class) == null) {
SAAJInInterceptor saajIn = new SAAJInInterceptor();
saajIn.handleMessage(message);
}
SOAPMessage soapMessage = message.getContent(SOAPMessage.class);
if (soapMessage == null) {
return;
}
SOAPMessage copyMessage = null;
try {
MessageFactory messageFactory = SAAJPreInInterceptor.INSTANCE.getFactory(message);
ByteArrayOutputStream bout = new ByteArrayOutputStream();
soapMessage.writeTo(bout);
copyMessage = messageFactory.createMessage(soapMessage.getMimeHeaders(), new ByteArrayInputStream(bout.toByteArray()));
} catch (SOAPException e) {
throw new Fault(e);
} catch (IOException e) {
throw new Fault(e);
}
if (copyMessage != null) {
message.put(SOAPMessage.class, copyMessage);
}
try {
authManager.secureRequest(message);
} finally {
message.put(SOAPMessage.class, soapMessage);
}
}
use of javax.xml.soap.MessageFactory in project jbossws-cxf by jbossws.
the class SOAPConnectionImpl method readSoapMessage.
@SuppressWarnings("unchecked")
private SOAPMessage readSoapMessage(Exchange exch) throws SOAPException {
// read SOAPMessage
try {
InputStream ins = exch.get(InputStream.class);
Map<String, List<String>> inHeaders = (Map<String, List<String>>) exch.get(Message.PROTOCOL_HEADERS);
MimeHeaders mimeHeaders = new MimeHeaders();
if (inHeaders != null) {
for (Map.Entry<String, List<String>> entry : inHeaders.entrySet()) {
if (entry.getValue() != null) {
for (String value : entry.getValue()) {
mimeHeaders.addHeader(entry.getKey(), value);
}
}
}
}
if (ins == null)
return null;
// if inputstream is empty, no need to build
if (ins.markSupported()) {
ins.mark(1);
final int bytesRead = ins.read(new byte[1]);
ins.reset();
if (bytesRead == -1) {
return null;
}
} else if (ins.available() == 0) {
return null;
}
MessageFactory msgFac = MessageFactory.newInstance(SOAPConstants.DYNAMIC_SOAP_PROTOCOL);
return msgFac.createMessage(mimeHeaders, ins);
} catch (Exception ex) {
throw MESSAGES.soapMessageCouldNotBeRead(ex);
}
}
use of javax.xml.soap.MessageFactory in project jbossws-cxf by jbossws.
the class JaspiSeverInInterceptor method handleMessage.
@Override
public void handleMessage(SoapMessage message) throws Fault {
if (message.getContent(SOAPMessage.class) == null) {
SAAJInInterceptor saajIn = new SAAJInInterceptor();
saajIn.handleMessage(message);
}
SOAPMessage soapMessage = message.getContent(SOAPMessage.class);
if (soapMessage == null) {
return;
}
SOAPMessage copyMessage = null;
try {
MessageFactory messageFactory = SAAJPreInInterceptor.INSTANCE.getFactory(message);
ByteArrayOutputStream bout = new ByteArrayOutputStream();
soapMessage.writeTo(bout);
copyMessage = messageFactory.createMessage(soapMessage.getMimeHeaders(), new ByteArrayInputStream(bout.toByteArray()));
} catch (SOAPException e) {
throw new Fault(e);
} catch (IOException e) {
throw new Fault(e);
}
if (copyMessage != null) {
message.put(SOAPMessage.class, copyMessage);
}
try {
authManager.validateRequest(message);
} finally {
message.put(SOAPMessage.class, soapMessage);
}
}
Aggregations