use of javax.xml.stream.XMLStreamWriter in project cxf by apache.
the class CorbaStreamFaultOutInterceptor method getDataWriter.
protected DataWriter<XMLStreamWriter> getDataWriter(CorbaMessage message) {
Service serviceModel = ServiceModelUtil.getService(message.getExchange());
DataWriter<XMLStreamWriter> dataWriter = serviceModel.getDataBinding().createWriter(XMLStreamWriter.class);
if (dataWriter == null) {
throw new CorbaBindingException("Couldn't create data writer for outgoing fault message");
}
return dataWriter;
}
use of javax.xml.stream.XMLStreamWriter 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 javax.xml.stream.XMLStreamWriter in project cxf by apache.
the class WebFaultOutInterceptor method handleMessage.
public void handleMessage(Message message) throws Fault {
Fault f = (Fault) message.getContent(Exception.class);
if (f == null) {
return;
}
try {
Throwable thr = f.getCause();
SOAPFaultException sf = null;
if (thr instanceof SOAPFaultException) {
sf = (SOAPFaultException) thr;
} else if (thr.getCause() instanceof SOAPFaultException) {
sf = (SOAPFaultException) thr.getCause();
}
if (sf != null) {
SoapVersion soapVersion = (SoapVersion) message.get(SoapVersion.class.getName());
if (soapVersion != null && soapVersion.getVersion() != 1.1) {
if (f instanceof SoapFault) {
for (Iterator<QName> it = CastUtils.cast(sf.getFault().getFaultSubcodes()); it.hasNext(); ) {
((SoapFault) f).addSubCode(it.next());
}
}
if (sf.getFault().getFaultReasonLocales().hasNext()) {
Locale lang = (Locale) sf.getFault().getFaultReasonLocales().next();
String convertedLang = lang.getLanguage();
String country = lang.getCountry();
if (country.length() > 0) {
convertedLang = convertedLang + '-' + country;
}
f.setLang(convertedLang);
}
}
message.setContent(Exception.class, f);
}
} catch (Exception e) {
// do nothing;
}
Throwable cause = f.getCause();
WebFault fault = null;
if (cause != null) {
fault = getWebFaultAnnotation(cause.getClass());
if (fault == null && cause.getCause() != null) {
fault = getWebFaultAnnotation(cause.getCause().getClass());
if (fault != null || cause instanceof RuntimeException) {
cause = cause.getCause();
}
}
}
if (cause instanceof Exception && fault != null) {
Exception ex = (Exception) cause;
Object faultInfo = null;
try {
Method method = cause.getClass().getMethod("getFaultInfo", new Class[0]);
faultInfo = method.invoke(cause, new Object[0]);
} catch (NoSuchMethodException e) {
faultInfo = createFaultInfoBean(fault, cause);
} catch (InvocationTargetException e) {
throw new Fault(new org.apache.cxf.common.i18n.Message("INVOCATION_TARGET_EXC", BUNDLE), e);
} catch (IllegalAccessException e) {
throw new Fault(new org.apache.cxf.common.i18n.Message("COULD_NOT_INVOKE", BUNDLE), e);
} catch (IllegalArgumentException e) {
throw new Fault(new org.apache.cxf.common.i18n.Message("COULD_NOT_INVOKE", BUNDLE), e);
}
Service service = message.getExchange().getService();
try {
DataWriter<XMLStreamWriter> writer = service.getDataBinding().createWriter(XMLStreamWriter.class);
if (ServiceUtils.isSchemaValidationEnabled(SchemaValidationType.OUT, message)) {
Schema schema = EndpointReferenceUtils.getSchema(service.getServiceInfos().get(0), message.getExchange().getBus());
writer.setSchema(schema);
}
OperationInfo op = message.getExchange().getBindingOperationInfo().getOperationInfo();
QName faultName = getFaultName(fault, cause.getClass(), op);
MessagePartInfo part = getFaultMessagePart(faultName, op);
if (f.hasDetails()) {
writer.write(faultInfo, part, new W3CDOMStreamWriter(f.getDetail()));
} else {
writer.write(faultInfo, part, new W3CDOMStreamWriter(f.getOrCreateDetail()));
if (!f.getDetail().hasChildNodes()) {
f.setDetail(null);
}
}
f.setMessage(ex.getMessage());
} catch (Exception nex) {
if (nex instanceof Fault) {
message.setContent(Exception.class, nex);
super.handleMessage(message);
} else {
// if exception occurs while writing a fault, we'll just let things continue
// and let the rest of the chain try handling it as is.
LOG.log(Level.WARNING, "EXCEPTION_WHILE_WRITING_FAULT", nex);
}
}
} else {
FaultMode mode = message.get(FaultMode.class);
if (mode == FaultMode.CHECKED_APPLICATION_FAULT) {
// only convert checked exceptions with this
// otherwise delegate down to the normal protocol specific stuff
super.handleMessage(message);
}
}
}
use of javax.xml.stream.XMLStreamWriter in project cxf by apache.
the class LogicalHandlerOutInterceptor method handleMessage.
public void handleMessage(Message message) throws Fault {
if (binding.getHandlerChain().isEmpty()) {
return;
}
HandlerChainInvoker invoker = getInvoker(message);
if (invoker.getLogicalHandlers().isEmpty()) {
return;
}
XMLStreamWriter origWriter = message.getContent(XMLStreamWriter.class);
Node nd = message.getContent(Node.class);
SOAPMessage m = message.getContent(SOAPMessage.class);
Document document = null;
if (m != null) {
document = m.getSOAPPart();
} else if (nd != null) {
document = nd.getOwnerDocument();
} else {
document = DOMUtils.newDocument();
message.setContent(Node.class, document);
}
W3CDOMStreamWriter writer = new W3CDOMStreamWriter(document.createDocumentFragment());
// Replace stax writer with DomStreamWriter
message.setContent(XMLStreamWriter.class, writer);
message.put(ORIGINAL_WRITER, origWriter);
message.getInterceptorChain().add(ending);
}
use of javax.xml.stream.XMLStreamWriter in project cxf by apache.
the class LogicalMessageImpl method write.
private void write(Source source, Node n) {
try {
if (source instanceof DOMSource && ((DOMSource) source).getNode() == null) {
return;
}
XMLStreamWriter writer = new W3CDOMStreamWriter((Element) n);
StaxUtils.copy(source, writer);
} catch (XMLStreamException e) {
throw new Fault(e);
}
}
Aggregations