Search in sources :

Example 16 with CorbaBindingException

use of org.apache.cxf.binding.corba.CorbaBindingException in project cxf by apache.

the class CorbaStreamFaultInInterceptor method handleMessage.

public void handleMessage(Message msg) {
    CorbaMessage message = (CorbaMessage) msg;
    try {
        SystemException sysEx = message.getSystemException();
        if (sysEx != null) {
            message.setContent(Exception.class, sysEx);
            return;
        }
        CorbaStreamable exStreamable = message.getStreamableException();
        if (exStreamable != null) {
            DataReader<XMLStreamReader> reader = getDataReader(message);
            BindingOperationInfo bopInfo = message.getExchange().getBindingOperationInfo();
            OperationInfo opInfo = bopInfo.getOperationInfo();
            ServiceInfo service = message.getExchange().getEndpoint().getEndpointInfo().getService();
            org.omg.CORBA.ORB orb = (org.omg.CORBA.ORB) message.get(CorbaConstants.ORB);
            if (orb == null) {
                orb = message.getExchange().get(org.omg.CORBA.ORB.class);
            }
            QName elName = new QName("", exStreamable.getName());
            FaultInfo fault = getFaultInfo(opInfo, elName);
            CorbaTypeEventProducer faultEventProducer = CorbaHandlerUtils.getTypeEventProducer(exStreamable.getObject(), service, orb);
            CorbaStreamReader streamReader = new CorbaStreamReader(faultEventProducer);
            Object e = reader.read(fault.getMessageParts().get(0), streamReader);
            if (!(e instanceof Exception)) {
                Class<?> exClass = fault.getProperty(Class.class.getName(), Class.class);
                if (exClass != null) {
                    Class<?> beanClass = e.getClass();
                    Constructor<?> constructor = exClass.getConstructor(new Class[] { String.class, beanClass });
                    String repId = (message.getStreamableException()._type().id() != null) ? message.getStreamableException()._type().id() : "";
                    e = constructor.newInstance(new Object[] { repId, e });
                } else {
                    // Get the Fault
                    Fault faultEx = (Fault) message.getContent(Exception.class);
                    if (e instanceof Document) {
                        createFaultDetail((Document) e, fault, faultEx);
                    }
                    e = faultEx;
                }
            }
            message.setContent(Exception.class, e);
        }
    } catch (java.lang.Exception ex) {
        LOG.log(Level.SEVERE, "CORBA unmarshalFault exception", ex);
        throw new CorbaBindingException("CORBA unmarshalFault exception", ex);
    }
}
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) FaultInfo(org.apache.cxf.service.model.FaultInfo) XMLStreamReader(javax.xml.stream.XMLStreamReader) Fault(org.apache.cxf.interceptor.Fault) Document(org.w3c.dom.Document) CorbaStreamReader(org.apache.cxf.binding.corba.runtime.CorbaStreamReader) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) SystemException(org.omg.CORBA.SystemException) CorbaTypeEventProducer(org.apache.cxf.binding.corba.types.CorbaTypeEventProducer) CorbaStreamable(org.apache.cxf.binding.corba.CorbaStreamable) CorbaMessage(org.apache.cxf.binding.corba.CorbaMessage) QName(javax.xml.namespace.QName) SystemException(org.omg.CORBA.SystemException) CorbaBindingException(org.apache.cxf.binding.corba.CorbaBindingException)

Example 17 with CorbaBindingException

use of org.apache.cxf.binding.corba.CorbaBindingException 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 18 with CorbaBindingException

use of org.apache.cxf.binding.corba.CorbaBindingException in project cxf by apache.

the class CorbaDSIServant method init.

public void init(ORB theOrb, POA poa, CorbaDestination dest, MessageObserver observer, CorbaTypeMap map) {
    orb = theOrb;
    servantPOA = poa;
    destination = dest;
    incomingObserver = observer;
    typeMap = map;
    // Get the list of interfaces that this servant will support
    try {
        BindingType bindType = destination.getBindingInfo().getExtensor(BindingType.class);
        if (bindType == null) {
            throw new CorbaBindingException("Unable to determine corba binding information");
        }
        List<String> bases = bindType.getBases();
        interfaces = new ArrayList<>();
        interfaces.add(bindType.getRepositoryID());
        for (Iterator<String> iter = bases.iterator(); iter.hasNext(); ) {
            interfaces.add(iter.next());
        }
    } catch (java.lang.Exception ex) {
        LOG.log(Level.SEVERE, "Couldn't initialize the corba DSI servant");
        throw new CorbaBindingException(ex);
    }
    // Build the list of CORBA operations and the WSDL operations they map to.  Note that
    // the WSDL operation name may not always match the CORBA operation name.
    BindingInfo bInfo = destination.getBindingInfo();
    Iterator<BindingOperationInfo> i = bInfo.getOperations().iterator();
    operationMap = new HashMap<>(bInfo.getOperations().size());
    while (i.hasNext()) {
        BindingOperationInfo bopInfo = i.next();
        OperationType opType = bopInfo.getExtensor(OperationType.class);
        if (opType != null) {
            operationMap.put(opType.getName(), bopInfo.getName());
        }
    }
}
Also used : CorbaBindingException(org.apache.cxf.binding.corba.CorbaBindingException) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingType(org.apache.cxf.binding.corba.wsdl.BindingType) BindingInfo(org.apache.cxf.service.model.BindingInfo) OperationType(org.apache.cxf.binding.corba.wsdl.OperationType)

Example 19 with CorbaBindingException

use of org.apache.cxf.binding.corba.CorbaBindingException in project cxf by apache.

the class CorbaObjectWriter method writeException.

public void writeException(CorbaExceptionHandler exHandler) throws CorbaBindingException {
    Exception exType = (Exception) exHandler.getType();
    List<CorbaObjectHandler> exMembers = exHandler.getMembers();
    stream.write_string(exType.getRepositoryID());
    for (int i = 0; i < exMembers.size(); ++i) {
        this.write(exMembers.get(i));
    }
}
Also used : CorbaObjectHandler(org.apache.cxf.binding.corba.types.CorbaObjectHandler) Exception(org.apache.cxf.binding.corba.wsdl.Exception) CorbaBindingException(org.apache.cxf.binding.corba.CorbaBindingException)

Example 20 with CorbaBindingException

use of org.apache.cxf.binding.corba.CorbaBindingException in project cxf by apache.

the class CorbaObjectWriter method writeEnum.

// -- complex types --
public void writeEnum(CorbaEnumHandler enumHandler) throws CorbaBindingException {
    Enum enumType = (Enum) enumHandler.getType();
    String enumLabel = enumHandler.getValue();
    List<Enumerator> enumerators = enumType.getEnumerator();
    for (int i = 0; i < enumerators.size(); ++i) {
        if (enumerators.get(i).getValue().equals(enumLabel)) {
            stream.write_long(i);
            return;
        }
    }
    throw new CorbaBindingException("CorbaObjectWriter: unable to find enumeration label");
}
Also used : Enum(org.apache.cxf.binding.corba.wsdl.Enum) CorbaBindingException(org.apache.cxf.binding.corba.CorbaBindingException) Enumerator(org.apache.cxf.binding.corba.wsdl.Enumerator)

Aggregations

CorbaBindingException (org.apache.cxf.binding.corba.CorbaBindingException)25 QName (javax.xml.namespace.QName)8 TypeCode (org.omg.CORBA.TypeCode)5 URISyntaxException (java.net.URISyntaxException)4 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)4 CorbaMessage (org.apache.cxf.binding.corba.CorbaMessage)3 CorbaObjectHandler (org.apache.cxf.binding.corba.types.CorbaObjectHandler)3 CorbaType (org.apache.cxf.binding.corba.wsdl.CorbaType)3 SystemException (org.omg.CORBA.SystemException)3 Method (java.lang.reflect.Method)2 URI (java.net.URI)2 XMLStreamReader (javax.xml.stream.XMLStreamReader)2 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)2 CorbaStreamable (org.apache.cxf.binding.corba.CorbaStreamable)2 Alias (org.apache.cxf.binding.corba.wsdl.Alias)2 Enum (org.apache.cxf.binding.corba.wsdl.Enum)2 Enumerator (org.apache.cxf.binding.corba.wsdl.Enumerator)2 OperationType (org.apache.cxf.binding.corba.wsdl.OperationType)2 Fault (org.apache.cxf.interceptor.Fault)2 Exchange (org.apache.cxf.message.Exchange)2