Java Code Examples for org.apache.cxf.service.model.BindingOperationInfo#getFaults()

The following examples show how to use org.apache.cxf.service.model.BindingOperationInfo#getFaults() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: cxf   File: FaultOutInterceptor.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 2
Source Project: cxf   File: MessageModeOutInterceptor.java    License: Apache License 2.0 5 votes vote down vote up
private void validateFaultDetail(Element detail, Schema schema, BindingOperationInfo bop) throws Exception {
    if (detail != null) {
        Element el = DOMUtils.getFirstElement(detail);
        while (el != null) {
            QName qn = DOMUtils.getElementQName(el);
            for (BindingFaultInfo bfi : bop.getFaults()) {
                if (bfi.getFaultInfo().getMessagePartByIndex(0).getConcreteName().equals(qn)) {
                    //Found a fault with the correct QName, we can validate it
                    schema.newValidator().validate(new DOMSource(DOMUtils.getDomElement(el)));
                }
            }
            el = DOMUtils.getNextElement(el);
        }
    }
}
 
Example 3
Source Project: cxf   File: PolicyEngineImpl.java    License: Apache License 2.0 5 votes vote down vote up
private BindingFaultInfo mapToWrappedBindingFaultInfo(BindingFaultInfo bfi) {
    BindingOperationInfo boi = bfi.getBindingOperation();
    if (boi != null && boi.isUnwrapped()) {
        boi = boi.getWrappedOperation();
        for (BindingFaultInfo bf2 : boi.getFaults()) {
            if (bf2.getFaultInfo().getName().equals(bfi.getFaultInfo().getName())) {
                return bf2;
            }
        }
    }
    return bfi;
}
 
Example 4
private void addBindingOperationDocs(Endpoint ep) {
    for (BindingOperationInfo binfo : ep.getBinding()
            .getBindingInfo().getOperations()) {
        List<WSDLDocumentation> later = CastUtils.cast((List<?>)binfo.getOperationInfo()
                                                           .getProperty(EXTRA_DOCUMENTATION));
        if (later != null) {
            for (WSDLDocumentation doc : later) {
                switch (doc.placement()) {
                case BINDING_OPERATION:
                    binfo.setDocumentation(doc.value());
                    break;
                case BINDING_OPERATION_INPUT:
                    binfo.getInput().setDocumentation(doc.value());
                    break;
                case BINDING_OPERATION_OUTPUT:
                    binfo.getOutput().setDocumentation(doc.value());
                    break;
                case BINDING_OPERATION_FAULT: {
                    for (BindingFaultInfo f : binfo.getFaults()) {
                        if (doc.faultClass().equals(f.getFaultInfo()
                                                        .getProperty(Class.class.getName()))) {
                            f.setDocumentation(doc.value());
                        }
                    }
                    break;
                }
                default:
                    //nothing
                }
            }
        }
    }
}
 
Example 5
Source Project: cxf   File: JaxWsEndpointImpl.java    License: Apache License 2.0 4 votes vote down vote up
private void extractWsdlExtensibilities(EndpointInfo endpoint) {
    List<ExtensibilityElement> portExtensors = getExtensors(endpoint);
    List<ExtensibilityElement> bindingExtensors = getExtensors(endpoint.getBinding());

    //check the extensions under <wsdl:binding>
    checkRespectBindingFeature(bindingExtensors);

    Collection<BindingOperationInfo> bindingOperations = endpoint.getBinding().getOperations();
    if (null != bindingOperations) {
        Iterator<BindingOperationInfo> iterator = bindingOperations.iterator();
        while (iterator.hasNext()) {
            BindingOperationInfo operationInfo = iterator.next();
            BindingMessageInfo inputInfo = operationInfo.getInput();
            BindingMessageInfo outputnfo = operationInfo.getOutput();
            Collection<BindingFaultInfo> faults = operationInfo.getFaults();

            //check the extensions under <wsdl:operation>
            checkRespectBindingFeature(getExtensors(operationInfo));
            //check the extensions under <wsdl:input>
            checkRespectBindingFeature(getExtensors(inputInfo));
            //check the extensions under <wsdl:output>
            checkRespectBindingFeature(getExtensors(outputnfo));
            if (null != faults) {
                Iterator<BindingFaultInfo> faultIterator = faults.iterator();
                while (faultIterator.hasNext()) {
                    BindingFaultInfo faultInfo = faultIterator.next();

                    //check the extensions under <wsdl:fault>
                    checkRespectBindingFeature(getExtensors(faultInfo));
                }
            }

        }
    }


    if (hasUsingAddressing(bindingExtensors) || hasUsingAddressing(portExtensors)) {
        WSAddressingFeature feature = new WSAddressingFeature();
        if (addressingRequired(bindingExtensors)
            || addressingRequired(portExtensors)) {
            feature.setAddressingRequired(true);
        }
        addAddressingFeature(feature);
    }
    extractWsdlEprs(endpoint);
}
 
Example 6
Source Project: cxf   File: PolicyAnnotationListener.java    License: Apache License 2.0 4 votes vote down vote up
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:
                    //nothing
                }
            }
        }
    }
}
 
Example 7
Source Project: cxf   File: InternalContextUtils.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 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();

            // FaultAction attribute is not defined in
            // 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;
}
 
Example 8
Source Project: cxf   File: SoapBindingFactoryTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testSoap12Factory() throws Exception {
    Definition d = createDefinition("/wsdl_soap/hello_world_soap12.wsdl");

    Bus bus = getMockBus();

    BindingFactoryManager bfm = getBindingFactoryManager(WSDLConstants.NS_SOAP12, bus);

    expect(bus.getExtension(BindingFactoryManager.class)).andReturn(bfm);

    DestinationFactoryManager dfm = control.createMock(DestinationFactoryManager.class);
    expect(bus.getExtension(DestinationFactoryManager.class)).andStubReturn(dfm);

    control.replay();

    WSDLServiceBuilder builder = new WSDLServiceBuilder(bus);
    ServiceInfo serviceInfo = builder
        .buildServices(d, new QName("http://apache.org/hello_world_soap12_http", "SOAPService"))
        .get(0);

    BindingInfo bi = serviceInfo.getBindings().iterator().next();

    assertTrue(bi instanceof SoapBindingInfo);

    SoapBindingInfo sbi = (SoapBindingInfo)bi;
    assertEquals("document", sbi.getStyle());
    assertEquals(WSDLConstants.NS_SOAP_HTTP_TRANSPORT, sbi.getTransportURI());
    assertTrue(sbi.getSoapVersion() instanceof Soap12);

    BindingOperationInfo boi = sbi.getOperation(new QName("http://apache.org/hello_world_soap12_http",
                                                          "sayHi"));
    SoapOperationInfo sboi = boi.getExtensor(SoapOperationInfo.class);
    assertNotNull(sboi);
    assertEquals("document", sboi.getStyle());
    assertEquals("sayHiAction", sboi.getAction());

    BindingMessageInfo input = boi.getInput();
    SoapBodyInfo bodyInfo = input.getExtensor(SoapBodyInfo.class);
    assertEquals("literal", bodyInfo.getUse());

    List<MessagePartInfo> parts = bodyInfo.getParts();
    assertNotNull(parts);
    assertEquals(1, parts.size());

    boi = sbi.getOperation(new QName("http://apache.org/hello_world_soap12_http", "pingMe"));
    sboi = boi.getExtensor(SoapOperationInfo.class);
    assertNotNull(sboi);
    assertEquals("document", sboi.getStyle());
    assertEquals("", sboi.getAction());
    Collection<BindingFaultInfo> faults = boi.getFaults();
    assertEquals(1, faults.size());
    BindingFaultInfo faultInfo = boi.getFault(new QName("http://apache.org/hello_world_soap12_http",
                                                        "pingMeFault"));
    assertNotNull(faultInfo);
}