use of org.apache.cxf.staxutils.W3CDOMStreamReader in project cxf by apache.
the class SoapHeaderInterceptor method handleMessage.
public void handleMessage(Message m) throws Fault {
SoapMessage message = (SoapMessage) m;
SoapVersion soapVersion = message.getVersion();
Exchange exchange = message.getExchange();
MessageContentsList parameters = MessageContentsList.getContentsList(message);
if (null == parameters) {
parameters = new MessageContentsList();
}
BindingOperationInfo bop = exchange.getBindingOperationInfo();
if (null == bop) {
return;
}
if (bop.isUnwrapped()) {
bop = bop.getWrappedOperation();
}
boolean client = isRequestor(message);
BindingMessageInfo bmi = client ? bop.getOutput() : bop.getInput();
if (bmi == null) {
// one way operation.
return;
}
List<SoapHeaderInfo> headers = bmi.getExtensors(SoapHeaderInfo.class);
if (headers == null || headers.isEmpty()) {
return;
}
boolean supportsNode = this.supportsDataReader(message, Node.class);
Service service = ServiceModelUtil.getService(message.getExchange());
Schema schema = null;
final boolean schemaValidationEnabled = ServiceUtils.isSchemaValidationEnabled(SchemaValidationType.IN, message);
if (schemaValidationEnabled) {
schema = EndpointReferenceUtils.getSchema(service.getServiceInfos().get(0), message.getExchange().getBus());
}
for (SoapHeaderInfo header : headers) {
MessagePartInfo mpi = header.getPart();
try {
if (schemaValidationEnabled && schema != null) {
validateHeader(message, mpi, schema);
}
} catch (Fault f) {
if (!isRequestor(message)) {
f.setFaultCode(Fault.FAULT_CODE_CLIENT);
}
throw f;
}
if (mpi.getTypeClass() != null) {
Header param = findHeader(message, mpi);
Object object = null;
if (param != null) {
message.getHeaders().remove(param);
if (param.getDataBinding() == null) {
Node source = (Node) param.getObject();
if (source instanceof Element) {
// need to remove these attributes as they
// would cause validation failures
Element el = (Element) source;
el.removeAttributeNS(soapVersion.getNamespace(), soapVersion.getAttrNameMustUnderstand());
el.removeAttributeNS(soapVersion.getNamespace(), soapVersion.getAttrNameRole());
}
if (supportsNode) {
object = getNodeDataReader(message).read(mpi, source);
} else {
W3CDOMStreamReader reader = new W3CDOMStreamReader((Element) source);
try {
// advance into the first tag
reader.nextTag();
} catch (XMLStreamException e) {
// ignore
}
object = getDataReader(message, XMLStreamReader.class).read(mpi, reader);
}
} else {
object = param.getObject();
}
}
parameters.put(mpi, object);
}
}
if (!parameters.isEmpty()) {
message.setContent(List.class, parameters);
}
}
use of org.apache.cxf.staxutils.W3CDOMStreamReader in project cxf by apache.
the class MessageModeInInterceptor method doFromSoapMessage.
private void doFromSoapMessage(Message message, Object sm) {
SOAPMessage m = (SOAPMessage) sm;
MessageContentsList list = (MessageContentsList) message.getContent(List.class);
if (list == null) {
list = new MessageContentsList();
message.setContent(List.class, list);
}
Object o = m;
if (StreamSource.class.isAssignableFrom(type)) {
try {
try (CachedOutputStream out = new CachedOutputStream()) {
XMLStreamWriter xsw = StaxUtils.createXMLStreamWriter(out);
StaxUtils.copy(new DOMSource(m.getSOAPPart()), xsw);
xsw.close();
o = new StreamSource(out.getInputStream());
}
} catch (Exception e) {
throw new Fault(e);
}
} else if (SAXSource.class.isAssignableFrom(type)) {
o = new StaxSource(new W3CDOMStreamReader(m.getSOAPPart()));
} else if (Source.class.isAssignableFrom(type)) {
o = new DOMSource(m.getSOAPPart());
}
list.set(0, o);
}
use of org.apache.cxf.staxutils.W3CDOMStreamReader in project cxf by apache.
the class LogicalMessageImpl method setPayload.
public void setPayload(Source s) {
Message message = msgContext.getWrappedMessage();
Service.Mode mode = (Service.Mode) msgContext.getWrappedMessage().getContextualProperty(Service.Mode.class.getName());
SOAPMessage m = message.getContent(SOAPMessage.class);
if (m != null && !MessageUtils.isOutbound(message)) {
try {
SAAJUtils.getBody(m).removeContents();
W3CDOMStreamWriter writer = new W3CDOMStreamWriter(SAAJUtils.getBody(m));
StaxUtils.copy(s, writer);
writer.flush();
writer.close();
if (mode == Service.Mode.MESSAGE) {
s = new DOMSource(m.getSOAPPart());
} else {
s = new DOMSource(SAAJUtils.getBody(m).getFirstChild());
}
W3CDOMStreamReader r = new W3CDOMStreamReader(DOMUtils.getFirstElement(SAAJUtils.getBody(m)));
message.setContent(XMLStreamReader.class, r);
} catch (Exception e) {
throw new Fault(e);
}
} else if (mode != null) {
if (message instanceof SoapMessage) {
if (mode == Service.Mode.MESSAGE) {
try {
// REVISIT: should try to use the original SOAPMessage
// instead of creating a new empty one.
SOAPMessage msg = initSOAPMessage(null);
write(s, SAAJUtils.getBody(msg));
s = new DOMSource(msg.getSOAPPart());
} catch (Exception e) {
throw new Fault(e);
}
}
} else if (message instanceof XMLMessage && message.getContent(DataSource.class) != null) {
throw new Fault(new org.apache.cxf.common.i18n.Message("GETPAYLOAD_OF_DATASOURCE_NOT_VALID_XMLHTTPBINDING", LOG));
}
} else {
XMLStreamReader reader = StaxUtils.createXMLStreamReader(s);
msgContext.getWrappedMessage().setContent(XMLStreamReader.class, reader);
}
msgContext.getWrappedMessage().setContent(Source.class, s);
}
use of org.apache.cxf.staxutils.W3CDOMStreamReader 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.staxutils.W3CDOMStreamReader in project cxf by apache.
the class AegisElementDataReader method read.
public Object read(Element input, AegisType desiredType) throws Exception {
W3CDOMStreamReader sreader = new W3CDOMStreamReader(input);
// advance into the first tag
sreader.nextTag();
return reader.read(sreader, desiredType);
}
Aggregations