Search in sources :

Example 6 with WebFault

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());
}
Also used : WebFault(javax.xml.ws.WebFault) File(java.io.File) AbstractCodeGenTest(org.apache.cxf.tools.wsdlto.AbstractCodeGenTest) Test(org.junit.Test)

Example 7 with WebFault

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());
}
Also used : WebFault(javax.xml.ws.WebFault) AbstractCodeGenTest(org.apache.cxf.tools.wsdlto.AbstractCodeGenTest) Test(org.junit.Test)

Example 8 with WebFault

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);
}
Also used : Reasontext(org.w3._2003._05.soap_envelope.Reasontext) QName(javax.xml.namespace.QName) Fault(org.w3._2003._05.soap_envelope.Fault) WebFault(javax.xml.ws.WebFault) Method(java.lang.reflect.Method) JAXBElement(javax.xml.bind.JAXBElement) SOAPException(javax.xml.soap.SOAPException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) IOException(java.io.IOException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) WebFault(javax.xml.ws.WebFault) Faultcode(org.w3._2003._05.soap_envelope.Faultcode) ObjectFactory(org.w3._2003._05.soap_envelope.ObjectFactory) RuntimeCamelException(org.apache.camel.RuntimeCamelException) Faultreason(org.w3._2003._05.soap_envelope.Faultreason) Detail(org.w3._2003._05.soap_envelope.Detail)

Example 9 with WebFault

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);
    }
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) CorbaBindingException(org.apache.cxf.binding.corba.CorbaBindingException) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) CorbaMessage(org.apache.cxf.binding.corba.CorbaMessage) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) Fault(org.apache.cxf.interceptor.Fault) WebFault(javax.xml.ws.WebFault) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) InvocationTargetException(java.lang.reflect.InvocationTargetException) SystemException(org.omg.CORBA.SystemException) CorbaBindingException(org.apache.cxf.binding.corba.CorbaBindingException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Exchange(org.apache.cxf.message.Exchange) WebFault(javax.xml.ws.WebFault) CorbaDestination(org.apache.cxf.binding.corba.CorbaDestination) RaisesType(org.apache.cxf.binding.corba.wsdl.RaisesType) SystemException(org.omg.CORBA.SystemException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) BindingInfo(org.apache.cxf.service.model.BindingInfo) OperationType(org.apache.cxf.binding.corba.wsdl.OperationType) ORB(org.omg.CORBA.ORB)

Example 10 with WebFault

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;
}
Also used : WebFault(javax.xml.ws.WebFault) QName(javax.xml.namespace.QName)

Aggregations

WebFault (javax.xml.ws.WebFault)13 QName (javax.xml.namespace.QName)8 IOException (java.io.IOException)3 Method (java.lang.reflect.Method)3 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)3 Fault (org.apache.cxf.interceptor.Fault)3 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)3 AbstractCodeGenTest (org.apache.cxf.tools.wsdlto.AbstractCodeGenTest)3 Test (org.junit.Test)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 JAXBElement (javax.xml.bind.JAXBElement)2 SOAPException (javax.xml.soap.SOAPException)2 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)2 RuntimeCamelException (org.apache.camel.RuntimeCamelException)2 SoapFault (org.apache.cxf.binding.soap.SoapFault)2 FaultMode (org.apache.cxf.message.FaultMode)2 OperationInfo (org.apache.cxf.service.model.OperationInfo)2 File (java.io.File)1 Locale (java.util.Locale)1 Schema (javax.xml.validation.Schema)1