use of javax.xml.soap.SOAPEnvelope in project OpenAM by OpenRock.
the class FSSOAPService method formSOAPError.
/**
* Forms a SOAP Fault and puts it in the SOAP Message's Body.
*
* @param faultcode fault code to be set in SOAPMEssage
* @param faultString fault string
* @param detail the details of the fault condition
* @return <code>SOAPMessage</code> containing the SOAP fault
*/
public SOAPMessage formSOAPError(String faultcode, String faultString, String detail) {
SOAPMessage msg = null;
SOAPEnvelope envelope = null;
SOAPFault sf = null;
SOAPBody body = null;
SOAPElement se = null;
try {
msg = fac.createMessage();
envelope = msg.getSOAPPart().getEnvelope();
body = envelope.getBody();
sf = body.addFault();
Name qname = envelope.createName(faultcode, null, IFSConstants.SOAP_URI);
sf.setFaultCode(qname);
sf.setFaultString(FSUtils.bundle.getString(faultString));
if ((detail != null) && !(detail.length() == 0)) {
Detail det = sf.addDetail();
se = (SOAPElement) det.addDetailEntry(envelope.createName("Problem"));
se.addAttribute(envelope.createName("details"), FSUtils.bundle.getString(detail));
}
} catch (SOAPException e) {
FSUtils.debug.error("FSSOAPService.formSOAPError:", e);
return null;
}
return msg;
}
use of javax.xml.soap.SOAPEnvelope in project OpenAM by OpenRock.
the class SAMLSOAPReceiver method FormSOAPError.
/**
* This method forms a SOAP Fault and puts it in the SOAP Message's
* Body.
*/
private SOAPMessage FormSOAPError(HttpServletResponse resp, String faultCode, String faultString, String detail) {
SOAPMessage msg = null;
SOAPEnvelope envelope = null;
SOAPFault sf = null;
SOAPBody body = null;
SOAPElement se = null;
try {
msg = msgFactory.createMessage();
envelope = msg.getSOAPPart().getEnvelope();
body = envelope.getBody();
sf = body.addFault();
Name qName = envelope.createName(faultCode, null, SOAPConstants.URI_NS_SOAP_ENVELOPE);
sf.setFaultCode(qName);
sf.setFaultString(SAMLUtils.bundle.getString(faultString));
if ((detail != null) && !(detail.length() == 0)) {
Detail det = sf.addDetail();
se = (SOAPElement) det.addDetailEntry(envelope.createName("Problem"));
se.addAttribute(envelope.createName("details"), SAMLUtils.bundle.getString(detail));
}
} catch (SOAPException e) {
SAMLUtils.debug.error("FormSOAPError:", e);
String[] data = { SAMLUtils.bundle.getString("soapFaultError") };
LogUtils.error(java.util.logging.Level.INFO, LogUtils.SOAP_FAULT_ERROR, data);
resp.setStatus(resp.SC_INTERNAL_SERVER_ERROR);
}
return msg;
}
use of javax.xml.soap.SOAPEnvelope in project OpenAM by OpenRock.
the class SAMLSOAPReceiver method containsFault.
/**
* containsFault is a utiltiy method to see if msg contains a soapfault.
*/
private boolean containsFault(SOAPMessage msg) {
try {
SOAPPart sp = msg.getSOAPPart();
SOAPEnvelope se = sp.getEnvelope();
SOAPBody sb = se.getBody();
return (sb.hasFault());
} catch (Exception e) {
if (SAMLUtils.debug.messageEnabled()) {
SAMLUtils.debug.message("Error in containFault!");
}
return false;
}
}
use of javax.xml.soap.SOAPEnvelope in project tdi-studio-se by Talend.
the class SOAPUtil method invokeSOAP.
public void invokeSOAP(String version, String destination, String soapAction, String soapMessage) throws SOAPException, TransformerException, ParserConfigurationException, FileNotFoundException, UnsupportedEncodingException {
MessageFactory messageFactory = null;
if (version.equals(SOAP12)) {
messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
} else {
messageFactory = MessageFactory.newInstance();
}
SOAPMessage message = messageFactory.createMessage();
MimeHeaders mimeHeaders = message.getMimeHeaders();
mimeHeaders.setHeader("SOAPAction", soapAction);
if (basicAuth) {
addBasicAuthHeader(mimeHeaders, username, password);
}
// Create objects for the message parts
SOAPPart soapPart = message.getSOAPPart();
String encoding = getEncoding(soapMessage);
ByteArrayInputStream stream = new ByteArrayInputStream(soapMessage.getBytes(encoding));
StreamSource preppedMsgSrc = new StreamSource(stream);
soapPart.setContent(preppedMsgSrc);
// InputStream stream = new FileInputStream(new File("d://soap.txt"));
// StreamSource preppedMsgSrc = new StreamSource(stream);
// soapPart.setContent(preppedMsgSrc);
message.saveChanges();
// Send the message
SOAPMessage reply = connection.call(message, destination);
SOAPPart reSoapPart = reply.getSOAPPart();
if (reSoapPart != null && reSoapPart instanceof SOAPPartImpl) {
((SOAPPartImpl) reSoapPart).setSourceCharsetEncoding(encoding);
}
SOAPEnvelope reEnvelope = reSoapPart.getEnvelope();
SOAPHeader reHeader = reEnvelope.getHeader();
if (reHeader != null) {
setReHeaderMessage(Doc2StringWithoutDeclare(extractContentAsDocument(reHeader)));
}
SOAPBody reBody = reEnvelope.getBody();
if (reBody.getFault() != null) {
hasFault = true;
setReFaultMessage(Doc2StringWithoutDeclare(extractContentAsDocument(reBody)));
setReBodyMessage(null);
} else {
hasFault = false;
if (reBody.getChildNodes().getLength() < 1) {
setReBodyMessage(null);
} else if (reBody.getChildNodes().getLength() == 1 && reBody.getChildNodes().item(0) instanceof javax.xml.soap.Text) {
setReBodyMessage(null);
} else {
setReBodyMessage(Doc2StringWithoutDeclare(extractContentAsDocument(reBody)));
}
setReFaultMessage(null);
}
}
use of javax.xml.soap.SOAPEnvelope in project cxf by apache.
the class TestMustUnderstandHandler method handleMessage.
public boolean handleMessage(SOAPMessageContext ctx) {
boolean continueProcessing = true;
try {
Object b = ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
boolean outbound = (Boolean) b;
SOAPMessage msg = ctx.getMessage();
if (isServerSideHandler()) {
if (outbound) {
QName qname = new QName("http://cxf.apache.org/mu", "MU");
SOAPPart soapPart = msg.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
SOAPHeader header = envelope.getHeader();
if (header == null) {
header = envelope.addHeader();
}
SOAPHeaderElement headerElement = header.addHeaderElement(envelope.createName("MU", "ns1", qname.getNamespaceURI()));
// QName soapMustUnderstand = new QName("http://schemas.xmlsoap.org/soap/envelope/",
// "mustUnderstand");
Name name = SOAPFactory.newInstance().createName("mustUnderstand", "soap", "http://schemas.xmlsoap.org/soap/envelope/");
headerElement.addAttribute(name, "1");
} else {
getHandlerInfoList(ctx).add(getHandlerId());
}
}
} catch (SOAPException e) {
e.printStackTrace();
}
return continueProcessing;
}
Aggregations