use of org.apache.cxf.interceptor.Fault in project cxf by apache.
the class XMLStreamDataReader method read.
public DOMSource read(XMLStreamReader reader) {
// performance reasons
try {
XMLStreamReader reader2 = reader;
if (reader2 instanceof DepthXMLStreamReader) {
reader2 = ((DepthXMLStreamReader) reader2).getReader();
}
if (reader2 instanceof W3CDOMStreamReader) {
W3CDOMStreamReader domreader = (W3CDOMStreamReader) reader2;
DOMSource o = new DOMSource(domreader.getCurrentElement());
domreader.consumeFrame();
return o;
}
Document document = StaxUtils.read(reader);
if (reader.hasNext()) {
// need to actually consume the END_ELEMENT
reader.next();
}
return new DOMSource(document);
} catch (XMLStreamException e) {
throw new Fault("COULD_NOT_READ_XML_STREAM_CAUSED_BY", LOG, e, e.getMessage());
}
}
use of org.apache.cxf.interceptor.Fault in project cxf by apache.
the class XSLTUtils method transform.
public static Document transform(Templates xsltTemplate, Document in) {
try {
DOMSource beforeSource = new DOMSource(in);
Document out = DOMUtils.createDocument();
Transformer trans = xsltTemplate.newTransformer();
trans.transform(beforeSource, new DOMResult(out));
return out;
} catch (TransformerException e) {
throw new Fault("XML_TRANSFORM", LOG, e, e.getMessage());
}
}
use of org.apache.cxf.interceptor.Fault in project cxf by apache.
the class SoapBindingFactory method setupUDP.
protected void setupUDP(InterceptorProvider p, EndpointInfo ei) {
// soap UDP requires ws-addressing turned on
WSAddressingFeature add = new WSAddressingFeature();
add.setAddressingRequired(true);
add.initialize(p, bus);
// UDP has a strict size limit on messages (<64K) so we'll try to shrink the
// message a little by putting the WSA namespace into the
// the soap:env which allows it to not be written on every header
// element as well as disable the output stream optimizations (doesn't really
// matter on such small messages anyway) to make sure we pickup those
// namespaces that are declared there.
p.getOutInterceptors().add(new AbstractSoapInterceptor(Phase.POST_LOGICAL) {
public void handleMessage(SoapMessage message) throws Fault {
AddressingProperties p = ContextUtils.retrieveMAPs(message, false, true);
if (p == null) {
return;
}
String ns = p.getNamespaceURI();
Map<String, String> nsMap = message.getEnvelopeNs();
if (nsMap == null) {
nsMap = new HashMap<>();
} else {
nsMap = new HashMap<>(nsMap);
}
message.put("soap.env.ns.map", nsMap);
if (!nsMap.containsValue(ns) && !nsMap.containsKey("wsa")) {
nsMap.put("wsa", ns);
}
message.put(AbstractOutDatabindingInterceptor.DISABLE_OUTPUTSTREAM_OPTIMIZATION, Boolean.TRUE);
}
});
// don't send the optional ReplyTo headers if we don't need to either
ei.setProperty("ws-addressing.write.optional.replyto", Boolean.FALSE);
}
use of org.apache.cxf.interceptor.Fault in project cxf by apache.
the class RPCInInterceptor method handleMessage.
public void handleMessage(Message message) {
if (isGET(message)) {
LOG.fine("RPCInInterceptor skipped in HTTP GET method");
return;
}
DepthXMLStreamReader xmlReader = getXMLStreamReader(message);
if (!StaxUtils.toNextElement(xmlReader)) {
message.setContent(Exception.class, new RuntimeException("There must be a method name element."));
}
String opName = xmlReader.getLocalName();
if (isRequestor(message) && opName.endsWith("Response")) {
opName = opName.substring(0, opName.length() - 8);
}
final BindingOperationInfo operation;
if (message.getExchange().getBindingOperationInfo() == null) {
operation = getOperation(message, new QName(xmlReader.getNamespaceURI(), opName));
if (operation == null) {
// it's doc-lit-bare
new BareInInterceptor().handleMessage(message);
return;
}
setMessage(message, operation);
} else {
operation = message.getExchange().getBindingOperationInfo();
if (!operation.getName().getLocalPart().equals(opName)) {
String sa = (String) message.get(SoapBindingConstants.SOAP_ACTION);
throw new Fault("SOAP_ACTION_MISMATCH_OP", LOG, null, sa, opName);
}
}
MessageInfo msg;
DataReader<XMLStreamReader> dr = getDataReader(message, XMLStreamReader.class);
if (!isRequestor(message)) {
msg = operation.getOperationInfo().getInput();
} else {
msg = operation.getOperationInfo().getOutput();
}
message.put(MessageInfo.class, msg);
MessageContentsList parameters = new MessageContentsList();
StaxUtils.nextEvent(xmlReader);
boolean hasNext = true;
Iterator<MessagePartInfo> itr = msg.getMessageParts().iterator();
while (itr.hasNext()) {
MessagePartInfo part = itr.next();
if (hasNext) {
hasNext = StaxUtils.toNextElement(xmlReader);
}
if (hasNext) {
QName qn = xmlReader.getName();
if (qn.equals(SOAP12_RESULT)) {
// just ignore this. The parts should work correctly.
try {
while (xmlReader.getEventType() != XMLStreamConstants.END_ELEMENT) {
xmlReader.next();
}
xmlReader.next();
} catch (XMLStreamException e) {
// ignore
}
StaxUtils.toNextElement(xmlReader);
qn = xmlReader.getName();
}
// WSI-BP states that RPC/Lit part accessors should be completely unqualified
// However, older toolkits (Axis 1.x) are qualifying them. We'll go
// ahead and just match on the localpart. The RPCOutInterceptor
// will always generate WSI-BP compliant messages so it's unknown if
// the non-WSI-BP toolkits will be able to understand the CXF
// generated messages if they are expecting it to be qualified.
Iterator<MessagePartInfo> partItr = msg.getMessageParts().iterator();
while (!qn.getLocalPart().equals(part.getConcreteName().getLocalPart()) && partItr.hasNext()) {
part = partItr.next();
}
// only check the localpart as explained above
if (!qn.getLocalPart().equals(part.getConcreteName().getLocalPart())) {
throw new Fault(new org.apache.cxf.common.i18n.Message("UNKNOWN_RPC_LIT_PART", LOG, qn));
}
try {
parameters.put(part, dr.read(part, xmlReader));
} catch (Fault f) {
if (!isRequestor(message)) {
f.setFaultCode(Fault.FAULT_CODE_CLIENT);
}
throw f;
}
}
}
message.setContent(List.class, parameters);
}
use of org.apache.cxf.interceptor.Fault in project cxf by apache.
the class Soap11FaultOutInterceptor method handleMessage.
public void handleMessage(SoapMessage message) throws Fault {
Fault f = (Fault) message.getContent(Exception.class);
message.put(org.apache.cxf.message.Message.RESPONSE_CODE, f.getStatusCode());
if (message.getVersion() == Soap11.getInstance()) {
message.getInterceptorChain().add(Soap11FaultOutInterceptorInternal.INSTANCE);
} else {
message.getInterceptorChain().add(Soap12FaultOutInterceptorInternal.INSTANCE);
}
}
Aggregations