use of org.apache.cxf.service.model.FaultInfo in project cxf by apache.
the class ClientFaultConverter method processFaultDetail.
protected void processFaultDetail(Fault fault, Message msg) {
Element exDetail = (Element) DOMUtils.getChild(fault.getDetail(), Node.ELEMENT_NODE);
if (exDetail == null) {
return;
}
QName qname = new QName(exDetail.getNamespaceURI(), exDetail.getLocalName());
FaultInfo faultWanted = null;
MessagePartInfo part = null;
BindingOperationInfo boi = msg.getExchange().getBindingOperationInfo();
if (boi == null) {
return;
}
if (boi.isUnwrapped()) {
boi = boi.getWrappedOperation();
}
for (FaultInfo faultInfo : boi.getOperationInfo().getFaults()) {
for (MessagePartInfo mpi : faultInfo.getMessageParts()) {
if (qname.equals(mpi.getConcreteName())) {
faultWanted = faultInfo;
part = mpi;
break;
}
}
if (faultWanted != null) {
break;
}
}
if (faultWanted == null) {
// did not find it using the proper qualified names, we'll try again with just the localpart
for (FaultInfo faultInfo : boi.getOperationInfo().getFaults()) {
for (MessagePartInfo mpi : faultInfo.getMessageParts()) {
if (qname.getLocalPart().equals(mpi.getConcreteName().getLocalPart())) {
faultWanted = faultInfo;
part = mpi;
break;
}
}
if (faultWanted != null) {
break;
}
}
}
if (faultWanted == null) {
return;
}
Service s = msg.getExchange().getService();
DataBinding dataBinding = s.getDataBinding();
Object e = null;
if (isDOMSupported(dataBinding)) {
DataReader<Node> reader = this.getNodeDataReader(msg);
reader.setProperty(DataReader.FAULT, fault);
e = reader.read(part, exDetail);
} else {
DataReader<XMLStreamReader> reader = this.getDataReader(msg);
XMLStreamReader xsr = new W3CDOMStreamReader(exDetail);
try {
xsr.nextTag();
} catch (XMLStreamException e1) {
throw new Fault(e1);
}
reader.setProperty(DataReader.FAULT, fault);
e = reader.read(part, xsr);
}
if (!(e instanceof Exception)) {
try {
Class<?> exClass = faultWanted.getProperty(Class.class.getName(), Class.class);
if (exClass == null) {
return;
}
if (e == null) {
Constructor<?> constructor = exClass.getConstructor(String.class);
e = constructor.newInstance(fault.getMessage());
} else {
try {
Constructor<?> constructor = getConstructor(exClass, e);
e = constructor.newInstance(fault.getMessage(), e);
} catch (NoSuchMethodException e1) {
// Use reflection to convert fault bean to exception
e = convertFaultBean(exClass, e, fault);
}
}
msg.setContent(Exception.class, e);
} catch (Exception e1) {
LogUtils.log(LOG, Level.INFO, "EXCEPTION_WHILE_CREATING_EXCEPTION", e1, e1.getMessage());
}
} else {
if (fault.getMessage() != null) {
Field f;
try {
f = Throwable.class.getDeclaredField("detailMessage");
ReflectionUtil.setAccessible(f);
f.set(e, fault.getMessage());
} catch (Exception e1) {
// ignore
}
}
msg.setContent(Exception.class, e);
}
}
use of org.apache.cxf.service.model.FaultInfo in project cxf by apache.
the class FaultOutInterceptor method handleMessage.
public void handleMessage(Message message) throws Fault {
Fault f = (Fault) message.getContent(Exception.class);
if (f == null) {
return;
}
Throwable cause = f.getCause();
if (cause == null) {
return;
}
BindingOperationInfo bop = message.getExchange().getBindingOperationInfo();
if (bop == null) {
return;
}
FaultInfo fi = getFaultForClass(bop, cause.getClass());
if (cause instanceof Exception && fi != null) {
Exception ex = (Exception) cause;
Object bean = getFaultBean(cause, fi, message);
Service service = message.getExchange().getService();
MessagePartInfo part = fi.getFirstMessagePart();
DataBinding db = service.getDataBinding();
try {
if (isDOMSupported(db)) {
DataWriter<Node> writer = db.createWriter(Node.class);
if (f.hasDetails()) {
writer.write(bean, part, f.getDetail());
} else {
writer.write(bean, part, f.getOrCreateDetail());
if (!f.getDetail().hasChildNodes()) {
f.setDetail(null);
}
}
} else {
if (f.hasDetails()) {
XMLStreamWriter xsw = new W3CDOMStreamWriter(f.getDetail());
DataWriter<XMLStreamWriter> writer = db.createWriter(XMLStreamWriter.class);
writer.write(bean, part, xsw);
} else {
XMLStreamWriter xsw = new W3CDOMStreamWriter(f.getOrCreateDetail());
DataWriter<XMLStreamWriter> writer = db.createWriter(XMLStreamWriter.class);
writer.write(bean, part, xsw);
if (!f.getDetail().hasChildNodes()) {
f.setDetail(null);
}
}
}
f.setMessage(ex.getMessage());
} catch (Exception fex) {
// ignore - if any exceptions occur here, we'll ignore them
// and let the default fault handling of the binding convert
// the fault like it was an unchecked exception.
LOG.log(Level.WARNING, "EXCEPTION_WHILE_WRITING_FAULT", fex);
}
}
}
use of org.apache.cxf.service.model.FaultInfo in project cxf by apache.
the class JaxWsServiceFactoryBean method buildWSAActions.
private void buildWSAActions(OperationInfo operation, Method method) {
// nothing
if (method == null) {
return;
}
Action action = method.getAnnotation(Action.class);
Addressing addressing = method.getDeclaringClass().getAnnotation(Addressing.class);
if (action == null && addressing == null) {
return;
}
WebMethod wm = method.getAnnotation(WebMethod.class);
String inputAction = "";
if (action != null) {
inputAction = action.input();
}
if (wm != null && StringUtils.isEmpty(inputAction)) {
inputAction = wm.action();
}
if (StringUtils.isEmpty(inputAction)) {
inputAction = computeAction(operation, "Request");
}
if (action == null && addressing != null) {
operation.getInput().addExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME, inputAction);
operation.getInput().addExtensionAttribute(JAXWSAConstants.WSAW_ACTION_QNAME, inputAction);
if (operation.getOutput() != null) {
operation.getOutput().addExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME, computeAction(operation, "Response"));
operation.getOutput().addExtensionAttribute(JAXWSAConstants.WSAW_ACTION_QNAME, computeAction(operation, "Response"));
}
} else {
MessageInfo input = operation.getInput();
input.addExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME, inputAction);
if (!StringUtils.isEmpty(action.input())) {
input.addExtensionAttribute(JAXWSAConstants.WSAW_ACTION_QNAME, inputAction);
}
MessageInfo output = operation.getOutput();
if (output != null && !StringUtils.isEmpty(action.output())) {
output.addExtensionAttribute(JAXWSAConstants.WSAW_ACTION_QNAME, action.output());
output.addExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME, action.output());
} else if (output != null) {
output.addExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME, computeAction(operation, "Response"));
}
FaultAction[] faultActions = action.fault();
if (faultActions != null && faultActions.length > 0 && operation.getFaults() != null) {
for (FaultAction faultAction : faultActions) {
FaultInfo faultInfo = getFaultInfo(operation, faultAction.className());
if (faultInfo != null && !StringUtils.isEmpty(faultAction.value())) {
faultInfo.addExtensionAttribute(JAXWSAConstants.WSAW_ACTION_QNAME, faultAction.value());
faultInfo.addExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME, faultAction.value());
}
if (operation.isUnwrappedCapable()) {
faultInfo = getFaultInfo(operation.getUnwrappedOperation(), faultAction.className());
if (faultInfo != null && !StringUtils.isEmpty(faultAction.value())) {
faultInfo.addExtensionAttribute(JAXWSAConstants.WSAW_ACTION_QNAME, faultAction.value());
faultInfo.addExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME, faultAction.value());
}
}
}
}
}
for (FaultInfo fi : operation.getFaults()) {
if (fi.getExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME) == null) {
String f = "/Fault/" + fi.getName().getLocalPart();
fi.addExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME, computeAction(operation, f));
if (operation.isUnwrappedCapable()) {
fi = operation.getUnwrappedOperation().getFault(fi.getName());
fi.addExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME, computeAction(operation, f));
}
}
}
}
use of org.apache.cxf.service.model.FaultInfo in project cxf by apache.
the class JaxWsServiceFactoryBeanTest method testEndpoint.
@Test
public void testEndpoint() throws Exception {
ReflectionServiceFactoryBean bean = new JaxWsServiceFactoryBean();
URL resource = getClass().getResource("/wsdl/hello_world.wsdl");
assertNotNull(resource);
bean.setWsdlURL(resource.toString());
Bus bus = getBus();
bean.setBus(bus);
bean.setServiceClass(GreeterImpl.class);
BeanInvoker invoker = new BeanInvoker(new GreeterImpl());
bean.setInvoker(invoker);
Service service = bean.create();
String ns = "http://apache.org/hello_world_soap_http";
assertEquals("SOAPService", service.getName().getLocalPart());
assertEquals(ns, service.getName().getNamespaceURI());
InterfaceInfo intf = service.getServiceInfos().get(0).getInterface();
OperationInfo op = intf.getOperation(new QName(ns, "sayHi"));
Class<?> wrapper = op.getInput().getMessageParts().get(0).getTypeClass();
assertNotNull(wrapper);
wrapper = op.getOutput().getMessageParts().get(0).getTypeClass();
assertNotNull(wrapper);
assertEquals(invoker, service.getInvoker());
op = intf.getOperation(new QName(ns, "testDocLitFault"));
Collection<FaultInfo> faults = op.getFaults();
assertEquals(2, faults.size());
FaultInfo f = op.getFault(new QName(ns, "BadRecordLitFault"));
assertNotNull(f);
Class<?> c = f.getProperty(Class.class.getName(), Class.class);
assertNotNull(c);
assertEquals(1, f.getMessageParts().size());
MessagePartInfo mpi = f.getMessagePartByIndex(0);
assertNotNull(mpi.getTypeClass());
}
use of org.apache.cxf.service.model.FaultInfo in project cxf by apache.
the class PolicyInterceptorsTest method testServerPolicyOutFaultInterceptorGetBindingFaultInfo.
@Test
public void testServerPolicyOutFaultInterceptorGetBindingFaultInfo() {
ServerPolicyOutFaultInterceptor interceptor = new ServerPolicyOutFaultInterceptor();
message = control.createMock(Message.class);
Exception ex = new UnsupportedOperationException(new RuntimeException());
boi = control.createMock(BindingOperationInfo.class);
EasyMock.expect(message.get(BindingFaultInfo.class)).andReturn(null);
BindingFaultInfo bfi = control.createMock(BindingFaultInfo.class);
Collection<BindingFaultInfo> bfis = CastUtils.cast(Collections.EMPTY_LIST);
EasyMock.expect(boi.getFaults()).andReturn(bfis);
BindingOperationInfo wrappedBoi = control.createMock(BindingOperationInfo.class);
EasyMock.expect(boi.getWrappedOperation()).andReturn(wrappedBoi).times(2);
Collection<BindingFaultInfo> wrappedBfis = CastUtils.cast(Collections.singletonList(bfi));
EasyMock.expect(wrappedBoi.getFaults()).andReturn(wrappedBfis);
FaultInfo fi = control.createMock(FaultInfo.class);
EasyMock.expect(bfi.getFaultInfo()).andReturn(fi);
EasyMock.expect(fi.getProperty(Class.class.getName(), Class.class)).andReturn(RuntimeException.class);
message.put(BindingFaultInfo.class, bfi);
EasyMock.expectLastCall();
control.replay();
assertSame(bfi, interceptor.getBindingFaultInfo(message, ex, boi));
control.verify();
}
Aggregations