Search in sources :

Example 21 with BindingFaultInfo

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

the class JaxWsClientProxy method mapException.

Exception mapException(Method method, BindingOperationInfo boi, Exception ex) {
    if (method != null) {
        for (Class<?> excls : method.getExceptionTypes()) {
            if (excls.isInstance(ex)) {
                return ex;
            }
        }
    } else if (boi != null) {
        for (BindingFaultInfo fi : boi.getFaults()) {
            Class<?> c = fi.getFaultInfo().getProperty(Class.class.getName(), Class.class);
            if (c != null && c.isInstance(ex)) {
                return ex;
            }
        }
        if (ex instanceof IOException) {
            return ex;
        }
    }
    if (ex instanceof Fault && ex.getCause() instanceof IOException) {
        return new WebServiceException(ex.getMessage(), ex.getCause());
    }
    if (getBinding() instanceof HTTPBinding) {
        HTTPException exception = new HTTPException(HttpURLConnection.HTTP_INTERNAL_ERROR);
        exception.initCause(ex);
        return exception;
    } else if (getBinding() instanceof SOAPBinding) {
        try {
            SOAPFault soapFault = createSoapFault((SOAPBinding) getBinding(), ex);
            if (soapFault == null) {
                throw new WebServiceException(ex);
            }
            SOAPFaultException exception = new SOAPFaultException(soapFault);
            if (ex instanceof Fault && ex.getCause() != null) {
                exception.initCause(ex.getCause());
            } else {
                exception.initCause(ex);
            }
            return exception;
        } catch (SOAPException e) {
            return new WebServiceException(ex);
        }
    }
    return new WebServiceException(ex);
}
Also used : HTTPException(javax.xml.ws.http.HTTPException) WebServiceException(javax.xml.ws.WebServiceException) SOAPException(javax.xml.soap.SOAPException) SOAPBinding(javax.xml.ws.soap.SOAPBinding) Fault(org.apache.cxf.interceptor.Fault) SOAPFault(javax.xml.soap.SOAPFault) SoapFault(org.apache.cxf.binding.soap.SoapFault) SOAPFault(javax.xml.soap.SOAPFault) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) IOException(java.io.IOException) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo) HTTPBinding(javax.xml.ws.http.HTTPBinding)

Example 22 with BindingFaultInfo

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

the class InternalContextUtils method getActionFromServiceModel.

/**
 * Get action from service model.
 *
 * @param message the current message
 * @param fault the fault if one is set
 */
private static String getActionFromServiceModel(Message message, Exception fault) {
    String action = null;
    BindingOperationInfo bindingOpInfo = message.getExchange().getBindingOperationInfo();
    if (bindingOpInfo != null) {
        if (bindingOpInfo.isUnwrappedCapable()) {
            bindingOpInfo = bindingOpInfo.getUnwrappedOperation();
        }
        if (fault == null) {
            action = (String) message.get(ContextUtils.ACTION);
            if (StringUtils.isEmpty(action)) {
                action = (String) message.get(SoapBindingConstants.SOAP_ACTION);
            }
            if (action == null || "".equals(action)) {
                MessageInfo msgInfo = ContextUtils.isRequestor(message) ? bindingOpInfo.getOperationInfo().getInput() : bindingOpInfo.getOperationInfo().getOutput();
                String cachedAction = (String) msgInfo.getProperty(ContextUtils.ACTION);
                if (cachedAction == null) {
                    action = getActionFromMessageAttributes(msgInfo);
                } else {
                    action = cachedAction;
                }
                if (action == null && ContextUtils.isRequestor(message)) {
                    SoapOperationInfo soi = getSoapOperationInfo(bindingOpInfo);
                    action = soi == null ? null : soi.getAction();
                    action = StringUtils.isEmpty(action) ? null : action;
                }
            }
        } else {
            Throwable t = fault.getCause();
            // http://www.w3.org/2005/02/addressing/wsdl schema
            for (BindingFaultInfo bfi : bindingOpInfo.getFaults()) {
                FaultInfo fi = bfi.getFaultInfo();
                if (fi.size() == 0) {
                    continue;
                }
                if (t != null && matchFault(t, fi)) {
                    if (fi.getExtensionAttributes() == null) {
                        continue;
                    }
                    String attr = (String) fi.getExtensionAttributes().get(Names.WSAW_ACTION_QNAME);
                    if (attr == null) {
                        attr = (String) fi.getExtensionAttributes().get(new QName(Names.WSA_NAMESPACE_WSDL_NAME_OLD, Names.WSAW_ACTION_NAME));
                    }
                    if (attr != null) {
                        action = attr;
                        break;
                    }
                }
            }
        }
    }
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("action determined from service model: " + action);
    }
    return action;
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo) FaultInfo(org.apache.cxf.service.model.FaultInfo) QName(javax.xml.namespace.QName) SoapOperationInfo(org.apache.cxf.binding.soap.model.SoapOperationInfo) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo) MessageInfo(org.apache.cxf.service.model.MessageInfo)

Example 23 with BindingFaultInfo

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

the class EndpointPolicyImpl method initializeVocabulary.

synchronized void initializeVocabulary(Message m) {
    if (vocabulary != null) {
        return;
    }
    List<Assertion> v = new ArrayList<>();
    List<Assertion> fv = null;
    if (requestor) {
        fv = new ArrayList<>();
    }
    // vocabulary of alternative chosen for endpoint
    if (getChosenAlternative() != null) {
        for (Assertion a : getChosenAlternative()) {
            if (a.isOptional()) {
                continue;
            }
            v.add(a);
            if (null != fv) {
                fv.add(a);
            }
        }
    }
    // (in case of a client endpoint) messages
    for (BindingOperationInfo boi : ei.getBinding().getOperations()) {
        EffectivePolicy p;
        if (!this.requestor) {
            p = engine.getEffectiveServerRequestPolicy(ei, boi, m);
            Collection<Assertion> c = engine.getAssertions(p, false);
            if (c != null) {
                addAll(v, c);
            }
        } else {
            p = engine.getEffectiveClientResponsePolicy(ei, boi, m);
            Collection<Assertion> c = engine.getAssertions(p, false);
            if (c != null) {
                addAll(v, c);
                if (null != fv) {
                    addAll(fv, c);
                }
            }
            if (boi.getFaults() != null && null != fv) {
                for (BindingFaultInfo bfi : boi.getFaults()) {
                    p = engine.getEffectiveClientFaultPolicy(ei, boi, bfi, m);
                    c = engine.getAssertions(p, false);
                    if (c != null) {
                        addAll(fv, c);
                    }
                }
            }
        }
    }
    if (requestor) {
        faultVocabulary = fv;
    }
    vocabulary = v;
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Assertion(org.apache.neethi.Assertion) PolicyContainingAssertion(org.apache.neethi.PolicyContainingAssertion) ArrayList(java.util.ArrayList) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo)

Example 24 with BindingFaultInfo

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

the class PolicyAnnotationListener method addPolicies.

private void addPolicies(AbstractServiceFactoryBean factory, Endpoint ep, Class<?> cls) {
    List<Policy> list = CastUtils.cast((List<?>) ep.getEndpointInfo().getInterface().removeProperty(EXTRA_POLICIES));
    if (list != null) {
        addPolicies(factory, ep, cls, list, Policy.Placement.BINDING);
    }
    ServiceInfo service = ep.getService().getServiceInfos().get(0);
    for (BindingOperationInfo binfo : ep.getBinding().getBindingInfo().getOperations()) {
        List<Policy> later = CastUtils.cast((List<?>) binfo.getOperationInfo().removeProperty(EXTRA_POLICIES));
        if (later != null) {
            for (Policy p : later) {
                switch(p.placement()) {
                    case DEFAULT:
                    case BINDING_OPERATION:
                        addPolicy(binfo, service, p, cls, binfo.getName().getLocalPart() + "BindingOpPolicy");
                        break;
                    case BINDING_OPERATION_INPUT:
                        addPolicy(binfo.getInput(), service, p, cls, binfo.getName().getLocalPart() + "BindingOpInputPolicy");
                        break;
                    case BINDING_OPERATION_OUTPUT:
                        addPolicy(binfo.getOutput(), service, p, cls, binfo.getName().getLocalPart() + "BindingOpOutputPolicy");
                        break;
                    case BINDING_OPERATION_FAULT:
                        {
                            for (BindingFaultInfo f : binfo.getFaults()) {
                                if (p.faultClass().equals(f.getFaultInfo().getProperty(Class.class.getName()))) {
                                    addPolicy(f, service, p, cls, f.getFaultInfo().getName().getLocalPart() + "BindingOpFaultPolicy");
                                }
                            }
                            break;
                        }
                    default:
                }
            }
        }
    }
}
Also used : Policy(org.apache.cxf.annotations.Policy) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo)

Example 25 with BindingFaultInfo

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

the class PolicyVerificationInFaultInterceptor method handle.

/**
 * Determines the effective policy, and checks if one of its alternatives
 * is supported.
 *
 * @param message
 * @throws PolicyException if none of the alternatives is supported
 */
protected void handle(Message message) {
    AssertionInfoMap aim = message.get(AssertionInfoMap.class);
    if (null == aim) {
        return;
    }
    if (!MessageUtils.isRequestor(message)) {
        LOG.fine("Not a requestor.");
        return;
    }
    Exchange exchange = message.getExchange();
    assert null != exchange;
    BindingOperationInfo boi = exchange.getBindingOperationInfo();
    if (null == boi) {
        LOG.fine("No binding operation info.");
        return;
    }
    Endpoint e = exchange.getEndpoint();
    if (null == e) {
        LOG.fine("No endpoint.");
        return;
    }
    EndpointInfo ei = e.getEndpointInfo();
    Bus bus = exchange.getBus();
    PolicyEngine pe = bus.getExtension(PolicyEngine.class);
    if (null == pe) {
        return;
    }
    Exception ex = message.getContent(Exception.class);
    if (null == ex) {
        ex = exchange.get(Exception.class);
    }
    BindingFaultInfo bfi = getBindingFaultInfo(message, ex, boi);
    if (bfi == null) {
        return;
    }
    getTransportAssertions(message);
    EffectivePolicy effectivePolicy = pe.getEffectiveClientFaultPolicy(ei, boi, bfi, message);
    if (effectivePolicy != null) {
        aim.checkEffectivePolicy(effectivePolicy.getPolicy());
        LOG.fine("Verified policies for inbound message.");
    }
}
Also used : Exchange(org.apache.cxf.message.Exchange) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Bus(org.apache.cxf.Bus) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo)

Aggregations

BindingFaultInfo (org.apache.cxf.service.model.BindingFaultInfo)31 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)15 Test (org.junit.Test)13 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)9 QName (javax.xml.namespace.QName)6 BindingInfo (org.apache.cxf.service.model.BindingInfo)5 BindingMessageInfo (org.apache.cxf.service.model.BindingMessageInfo)5 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)5 Method (java.lang.reflect.Method)4 Bus (org.apache.cxf.Bus)4 Message (org.apache.cxf.message.Message)4 FaultInfo (org.apache.cxf.service.model.FaultInfo)4 Policy (org.apache.neethi.Policy)4 SoapOperationInfo (org.apache.cxf.binding.soap.model.SoapOperationInfo)3 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)3 ArrayList (java.util.ArrayList)2 BindingFault (javax.wsdl.BindingFault)2 UnknownExtensibilityElement (javax.wsdl.extensions.UnknownExtensibilityElement)2 Endpoint (org.apache.cxf.endpoint.Endpoint)2 Interceptor (org.apache.cxf.interceptor.Interceptor)2