Search in sources :

Example 1 with FaultInfo

use of org.apache.cxf.service.model.FaultInfo in project cxf by apache.

the class FaultOutInterceptor method getFaultForClass.

/**
 * Find the correct Fault part for a particular exception.
 *
 * @param op
 * @param class1
 */
public FaultInfo getFaultForClass(BindingOperationInfo op, Class<?> class1) {
    FaultInfo selectedFaultInfo = null;
    Class<?> selectedFaultInfoClass = null;
    for (BindingFaultInfo bfi : op.getFaults()) {
        FaultInfo faultInfo = bfi.getFaultInfo();
        Class<?> c = (Class<?>) faultInfo.getProperty(Class.class.getName());
        if (c != null && c.isAssignableFrom(class1) && (selectedFaultInfo == null || (selectedFaultInfoClass != null && selectedFaultInfoClass.isAssignableFrom(c)))) {
            selectedFaultInfo = faultInfo;
            selectedFaultInfoClass = c;
        }
    }
    return selectedFaultInfo;
}
Also used : BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo) FaultInfo(org.apache.cxf.service.model.FaultInfo) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo)

Example 2 with FaultInfo

use of org.apache.cxf.service.model.FaultInfo in project cxf by apache.

the class ServiceModelVisitor method visitOperation.

private void visitOperation(OperationInfo o) {
    MessageInfo in = o.getInput();
    if (in != null) {
        begin(in);
        for (MessagePartInfo part : in.getMessageParts()) {
            begin(part);
            end(part);
        }
        end(in);
    }
    MessageInfo out = o.getOutput();
    if (out != null) {
        begin(out);
        for (MessagePartInfo part : out.getMessageParts()) {
            begin(part);
            end(part);
        }
        end(out);
    }
    for (FaultInfo f : o.getFaults()) {
        begin(f);
        for (MessagePartInfo part : f.getMessageParts()) {
            begin(part);
            end(part);
        }
        end(f);
    }
    if (o.isUnwrappedCapable()) {
        OperationInfo uop = o.getUnwrappedOperation();
        begin(uop);
        visitOperation(o.getUnwrappedOperation());
        end(uop);
    }
}
Also used : UnwrappedOperationInfo(org.apache.cxf.service.model.UnwrappedOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) FaultInfo(org.apache.cxf.service.model.FaultInfo) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) MessageInfo(org.apache.cxf.service.model.MessageInfo)

Example 3 with FaultInfo

use of org.apache.cxf.service.model.FaultInfo in project cxf by apache.

the class ReflectionServiceFactoryBean method setFaultClassInfo.

private void setFaultClassInfo(OperationInfo o, Method selected) {
    Class<?>[] types = selected.getExceptionTypes();
    Map<FaultInfo, List<MessagePartInfo>> mpiMap = null;
    if (types.length > 0) {
        // early iterate over FaultInfo before cycling on exception types
        // as fi.getMessageParts() is very time-consuming due to elements
        // copy in ArrayList constructor
        mpiMap = new HashMap<>();
        for (FaultInfo fi : o.getFaults()) {
            mpiMap.put(fi, fi.getMessageParts());
        }
    }
    for (int i = 0; i < types.length; i++) {
        Class<?> exClass = types[i];
        Class<?> beanClass = getBeanClass(exClass);
        if (beanClass == null) {
            continue;
        }
        QName name = getFaultName(o.getInterface(), o, exClass, beanClass);
        for (Entry<FaultInfo, List<MessagePartInfo>> entry : mpiMap.entrySet()) {
            FaultInfo fi = entry.getKey();
            List<MessagePartInfo> mpis = entry.getValue();
            if (mpis.size() != 1) {
                Message message = new Message("NO_FAULT_PART", LOG, fi.getFaultName());
                LOG.log(Level.WARNING, message.toString());
            }
            for (MessagePartInfo mpi : mpis) {
                String ns = null;
                if (mpi.isElement()) {
                    ns = mpi.getElementQName().getNamespaceURI();
                } else {
                    ns = mpi.getTypeQName().getNamespaceURI();
                }
                if (mpi.getConcreteName().getLocalPart().equals(name.getLocalPart()) && name.getNamespaceURI().equals(ns)) {
                    fi.setProperty(Class.class.getName(), exClass);
                    mpi.setTypeClass(beanClass);
                    sendEvent(Event.OPERATIONINFO_FAULT, o, exClass, fi);
                }
            }
        }
    }
}
Also used : FaultInfo(org.apache.cxf.service.model.FaultInfo) Message(org.apache.cxf.common.i18n.Message) QName(javax.xml.namespace.QName) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) XmlList(javax.xml.bind.annotation.XmlList)

Example 4 with FaultInfo

use of org.apache.cxf.service.model.FaultInfo in project cxf by apache.

the class ReflectionServiceFactoryBean method addFault.

protected FaultInfo addFault(final InterfaceInfo service, final OperationInfo op, Class<?> exClass) {
    Class<?> beanClass = getBeanClass(exClass);
    if (beanClass == null) {
        return null;
    }
    String faultMsgName = null;
    for (AbstractServiceConfiguration c : serviceConfigurations) {
        faultMsgName = c.getFaultMessageName(op, exClass, beanClass);
        if (faultMsgName != null) {
            break;
        }
    }
    if (faultMsgName == null) {
        faultMsgName = exClass.getSimpleName();
    }
    QName faultName = getFaultName(service, op, exClass, beanClass);
    FaultInfo fi = op.addFault(new QName(op.getName().getNamespaceURI(), faultMsgName), new QName(op.getName().getNamespaceURI(), faultMsgName));
    fi.setProperty(Class.class.getName(), exClass);
    fi.setProperty("elementName", faultName);
    MessagePartInfo mpi = fi.addMessagePart(new QName(faultName.getNamespaceURI(), exClass.getSimpleName()));
    mpi.setElementQName(faultName);
    mpi.setTypeClass(beanClass);
    sendEvent(Event.OPERATIONINFO_FAULT, op, exClass, fi);
    return fi;
}
Also used : FaultInfo(org.apache.cxf.service.model.FaultInfo) QName(javax.xml.namespace.QName) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo)

Example 5 with FaultInfo

use of org.apache.cxf.service.model.FaultInfo in project cxf by apache.

the class ColocUtil method isSameFaultInfo.

public static boolean isSameFaultInfo(Collection<FaultInfo> fil1, Collection<FaultInfo> fil2) {
    if ((fil1 == null && fil2 != null) || (fil1 != null && fil2 == null)) {
        return false;
    }
    if (fil1 != null && fil2 != null) {
        if (fil1.size() != fil2.size()) {
            return false;
        }
        for (FaultInfo fi1 : fil1) {
            Iterator<FaultInfo> iter = fil2.iterator();
            Class<?> fiClass1 = fi1.getProperty(Class.class.getName(), Class.class);
            boolean match = false;
            while (iter.hasNext()) {
                FaultInfo fi2 = iter.next();
                Class<?> fiClass2 = fi2.getProperty(Class.class.getName(), Class.class);
                // So Compare Exception Class Instance.
                if (fiClass1.equals(fiClass2)) {
                    match = true;
                    break;
                }
            }
            if (!match) {
                return false;
            }
        }
    }
    return true;
}
Also used : FaultInfo(org.apache.cxf.service.model.FaultInfo)

Aggregations

FaultInfo (org.apache.cxf.service.model.FaultInfo)27 QName (javax.xml.namespace.QName)12 BindingFaultInfo (org.apache.cxf.service.model.BindingFaultInfo)11 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)11 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)11 OperationInfo (org.apache.cxf.service.model.OperationInfo)10 MessageInfo (org.apache.cxf.service.model.MessageInfo)8 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)7 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 Service (org.apache.cxf.service.Service)3 BindingMessageInfo (org.apache.cxf.service.model.BindingMessageInfo)3 UnwrappedOperationInfo (org.apache.cxf.service.model.UnwrappedOperationInfo)3 Method (java.lang.reflect.Method)2 HashMap (java.util.HashMap)2 BindingFault (javax.wsdl.BindingFault)2 Fault (javax.wsdl.Fault)2 Input (javax.wsdl.Input)2 Output (javax.wsdl.Output)2 XMLStreamReader (javax.xml.stream.XMLStreamReader)2