use of javax.xml.ws.WebFault in project cxf by apache.
the class CodeGenTest method testWebFault.
@Test
public void testWebFault() throws Exception {
env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl2java_wsdl/InvoiceServer-issue305570.wsdl"));
processor.setContext(env);
processor.execute();
assertNotNull(output);
File org = new File(output, "org");
assertTrue(org.exists());
File apache = new File(org, "apache");
assertTrue(apache.exists());
File invoiceserver = new File(apache, "invoiceserver");
assertTrue(invoiceserver.exists());
File invoice = new File(apache, "invoice");
assertTrue(invoice.exists());
Class<?> clz = classLoader.loadClass("org.apache.invoiceserver.NoSuchCustomerFault");
WebFault webFault = AnnotationUtil.getPrivClassAnnotation(clz, WebFault.class);
assertEquals("WebFault annotaion name attribute error", "NoSuchCustomer", webFault.name());
}
use of javax.xml.ws.WebFault in project cxf by apache.
the class CodeGenBugTest method testCXF964.
@Test
public void testCXF964() throws Exception {
env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl2java_wsdl/cxf964/hello_world_fault.wsdl"));
processor.setContext(env);
processor.execute();
Class<?> clz = classLoader.loadClass("org.apache.intfault.BadRecordLitFault");
WebFault webFault = AnnotationUtil.getPrivClassAnnotation(clz, WebFault.class);
assertEquals("int", webFault.name());
}
use of javax.xml.ws.WebFault in project camel by apache.
the class Soap12DataFormatAdapter method createFaultFromException.
/**
* Creates a SOAP fault from the exception and populates the message as well
* as the detail. The detail object is read from the method getFaultInfo of
* the throwable if present
*
* @param exception the cause exception
* @return SOAP fault from given Throwable
*/
@SuppressWarnings("unchecked")
private JAXBElement<Fault> createFaultFromException(final Throwable exception) {
WebFault webFault = exception.getClass().getAnnotation(WebFault.class);
if (webFault == null || webFault.targetNamespace() == null) {
throw new RuntimeException("The exception " + exception.getClass().getName() + " needs to have an WebFault annotation with name and targetNamespace", exception);
}
QName name = new QName(webFault.targetNamespace(), webFault.name());
Object faultObject;
try {
Method method = exception.getClass().getMethod("getFaultInfo");
faultObject = method.invoke(exception);
} catch (Exception e) {
throw new RuntimeCamelException("Exception while trying to get fault details", e);
}
Fault fault = new Fault();
Faultcode code = new Faultcode();
code.setValue(FAULT_CODE_SERVER);
fault.setCode(code);
Reasontext text = new Reasontext();
text.setValue(exception.getMessage());
text.setLang("en");
fault.setReason(new Faultreason().withText(text));
Detail detailEl = new ObjectFactory().createDetail();
@SuppressWarnings("rawtypes") JAXBElement<?> faultDetailContent = new JAXBElement(name, faultObject.getClass(), faultObject);
detailEl.getAny().add(faultDetailContent);
fault.setDetail(detailEl);
return new ObjectFactory().createFault(fault);
}
use of javax.xml.ws.WebFault in project cxf by apache.
the class CorbaStreamFaultOutInterceptor method handleMessage.
public void handleMessage(Message msg) {
CorbaMessage message = (CorbaMessage) msg;
Exchange exchange = message.getExchange();
CorbaDestination destination;
Fault faultEx = null;
if (message.getDestination() != null) {
destination = (CorbaDestination) message.getDestination();
} else {
destination = (CorbaDestination) exchange.getDestination();
}
orb = (ORB) message.get(CorbaConstants.ORB);
if (orb == null) {
orb = exchange.get(ORB.class);
}
DataWriter<XMLStreamWriter> writer = getDataWriter(message);
Throwable ex = message.getContent(Exception.class);
// is a Fault instance and contains a detail object.
if (ex.getCause() == null) {
if ((ex instanceof Fault) && (((Fault) ex).getDetail() != null)) {
faultEx = (Fault) ex;
} else {
throw new CorbaBindingException(ex);
}
} else {
ex = ex.getCause();
}
if (ex instanceof InvocationTargetException) {
ex = ex.getCause();
}
if (ex instanceof SystemException) {
setSystemException(message, ex, destination);
return;
}
String exClassName;
if (faultEx == null) {
// REVISIT, we should not have to depend on WebFault annotation
// Try changing the fault name to the proper mangled java exception classname.
WebFault fault = ex.getClass().getAnnotation(WebFault.class);
if (fault == null) {
throw new CorbaBindingException(ex);
}
exClassName = fault.name();
} else {
// JCGS: exClassName to be set to the exception name
Element faultElement = (Element) faultEx.getDetail().getFirstChild();
exClassName = faultElement.getLocalName();
}
// Get information about the operation being invoked from the WSDL
// definition.
// We need this to marshal data correctly
BindingInfo bInfo = destination.getBindingInfo();
String opName = message.getExchange().get(String.class);
Iterator<BindingOperationInfo> iter = bInfo.getOperations().iterator();
BindingOperationInfo bopInfo = null;
OperationType opType = null;
while (iter.hasNext()) {
bopInfo = iter.next();
if (bopInfo.getName().getLocalPart().equals(opName)) {
opType = bopInfo.getExtensor(OperationType.class);
break;
}
}
if (opType == null) {
throw new CorbaBindingException("Unable to find binding operation for " + opName);
}
OperationInfo opInfo = bopInfo.getOperationInfo();
if (faultEx != null) {
MessagePartInfo partInfo = getFaultMessagePartInfo(opInfo, new QName("", exClassName));
if (partInfo != null) {
exClassName = partInfo.getTypeQName().getLocalPart();
}
}
RaisesType exType = getRaisesType(opType, exClassName, ex);
try {
if (exType != null) {
if (faultEx != null) {
setUserExceptionFromFaultDetail(message, faultEx.getDetail(), exType, opInfo, writer, exchange.getEndpoint().getEndpointInfo().getService());
} else {
setUserException(message, ex, exType, opInfo, writer, exchange.getEndpoint().getEndpointInfo().getService());
}
} else {
throw new CorbaBindingException(ex);
}
} catch (Exception exp) {
throw new CorbaBindingException(exp);
}
}
use of javax.xml.ws.WebFault in project cxf by apache.
the class JaxWsServiceConfiguration method getFaultName.
@Override
public QName getFaultName(InterfaceInfo service, OperationInfo o, Class<?> exClass, Class<?> beanClass) {
WebFault fault = exClass.getAnnotation(WebFault.class);
if (fault != null) {
String name = fault.name();
if (name.length() == 0) {
name = exClass.getSimpleName();
}
String ns = fault.targetNamespace();
if (ns.length() == 0) {
ns = service.getName().getNamespaceURI();
}
return new QName(ns, name);
}
return null;
}
Aggregations