Search in sources :

Example 6 with RaisesType

use of org.apache.cxf.binding.corba.wsdl.RaisesType 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 = null;
    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 7 with RaisesType

use of org.apache.cxf.binding.corba.wsdl.RaisesType in project cxf by apache.

the class CorbaStreamFaultOutInterceptor method getRaisesType.

protected RaisesType getRaisesType(OperationType opType, String exClassName, Throwable ex) {
    RaisesType result = null;
    List<RaisesType> exList = opType.getRaises();
    result = findRaisesType(exList, exClassName);
    if (result == null) {
        // if doc-literal, the part element name should be used, but for RPC, the message part name
        try {
            Method faultMethod = ex.getClass().getMethod("getFaultInfo");
            if (faultMethod != null) {
                Class<?> faultClass = faultMethod.getReturnType();
                XmlType exType = faultClass.getAnnotation(XmlType.class);
                exClassName = exType.name();
                result = findRaisesType(exList, exClassName);
            }
        } catch (Exception exp) {
        // Ignore it
        }
    }
    return result;
}
Also used : RaisesType(org.apache.cxf.binding.corba.wsdl.RaisesType) Method(java.lang.reflect.Method) SystemException(org.omg.CORBA.SystemException) CorbaBindingException(org.apache.cxf.binding.corba.CorbaBindingException) InvocationTargetException(java.lang.reflect.InvocationTargetException) XmlType(javax.xml.bind.annotation.XmlType)

Example 8 with RaisesType

use of org.apache.cxf.binding.corba.wsdl.RaisesType in project cxf by apache.

the class CorbaConduitTest method testGetOperationExceptions.

@Test
public void testGetOperationExceptions() {
    CorbaConduit conduit = control.createMock(CorbaConduit.class);
    OperationType opType = control.createMock(OperationType.class);
    CorbaTypeMap typeMap = control.createMock(CorbaTypeMap.class);
    List<RaisesType> exlist = CastUtils.cast(control.createMock(ArrayList.class));
    opType.getRaises();
    EasyMock.expectLastCall().andReturn(exlist);
    int i = 0;
    EasyMock.expect(exlist.size()).andReturn(i);
    RaisesType rType = control.createMock(RaisesType.class);
    EasyMock.expect(exlist.get(0)).andReturn(rType);
    control.replay();
    conduit.getOperationExceptions(opType, typeMap);
    assertEquals(exlist.size(), 0);
}
Also used : RaisesType(org.apache.cxf.binding.corba.wsdl.RaisesType) ArrayList(java.util.ArrayList) OperationType(org.apache.cxf.binding.corba.wsdl.OperationType) Test(org.junit.Test)

Aggregations

RaisesType (org.apache.cxf.binding.corba.wsdl.RaisesType)8 QName (javax.xml.namespace.QName)3 OperationType (org.apache.cxf.binding.corba.wsdl.OperationType)3 SystemException (org.omg.CORBA.SystemException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 BindingFault (javax.wsdl.BindingFault)2 Fault (javax.wsdl.Fault)2 CorbaBindingException (org.apache.cxf.binding.corba.CorbaBindingException)2 ArgType (org.apache.cxf.binding.corba.wsdl.ArgType)2 ParamType (org.apache.cxf.binding.corba.wsdl.ParamType)2 Fault (org.apache.cxf.interceptor.Fault)2 TypeCode (org.omg.CORBA.TypeCode)2 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 Definition (javax.wsdl.Definition)1 Message (javax.wsdl.Message)1 WSDLException (javax.wsdl.WSDLException)1 XmlType (javax.xml.bind.annotation.XmlType)1