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

The following examples show how to use org.apache.cxf.service.model.OperationInfo#getFaults() . 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 File: AegisDatabinding.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void initializeOperation(Service s, TypeMapping serviceTM, OperationInfo opInfo,
                                 Set<AegisType> deps) {
    try {
        initializeMessage(s, serviceTM, opInfo.getInput(), IN_PARAM, deps);

        if (opInfo.hasOutput()) {
            initializeMessage(s, serviceTM, opInfo.getOutput(), OUT_PARAM, deps);
        }

        for (FaultInfo info : opInfo.getFaults()) {
            initializeMessage(s, serviceTM, info, FAULT_PARAM, deps);
        }

    } catch (DatabindingException e) {
        e.prepend("Error initializing parameters for operation " + opInfo.getName());
        throw e;
    }
}
 
Example 2
Source File: AegisDatabinding.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void initializeOperationTypes(ServiceInfo s, OperationInfo opInfo) {
    try {
        initializeMessageTypes(s, opInfo.getInput(), IN_PARAM);

        if (opInfo.hasOutput()) {
            initializeMessageTypes(s, opInfo.getOutput(), OUT_PARAM);
        }

        for (FaultInfo info : opInfo.getFaults()) {
            initializeMessageTypes(s, info, FAULT_PARAM);
        }

    } catch (DatabindingException e) {
        e.prepend("Error initializing parameters for operation " + opInfo.getName());
        throw e;
    }
}
 
Example 3
Source File: WebFaultOutInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
private MessagePartInfo getFaultMessagePart(QName qname, OperationInfo op) {
    for (FaultInfo faultInfo : op.getFaults()) {
        for (MessagePartInfo mpi : faultInfo.getMessageParts()) {
            String ns = null;
            if (mpi.isElement()) {
                ns = mpi.getElementQName().getNamespaceURI();
            } else {
                ns = mpi.getTypeQName().getNamespaceURI();
            }
            if (qname.getLocalPart().equals(mpi.getConcreteName().getLocalPart())
                    && qname.getNamespaceURI().equals(ns)) {
                return mpi;
            }
        }

    }
    return null;
}
 
Example 4
Source File: MAPAggregatorImpl.java    From cxf with Apache License 2.0 6 votes vote down vote up
private String getActionFromFaultMessage(final OperationInfo operation, final String faultName) {
    if (operation.getFaults() != null) {
        for (FaultInfo faultInfo : operation.getFaults()) {
            if (isSameFault(faultInfo, faultName)) {
                if (faultInfo.getExtensionAttributes() != null) {
                    String faultAction = InternalContextUtils.getAction(faultInfo);
                    if (!StringUtils.isEmpty(faultAction)) {
                        return faultAction;
                    }
                }
                return addPath(addPath(addPath(getActionBaseUri(operation),
                                               operation.getName().getLocalPart()),
                                       "Fault"),
                               faultInfo.getFaultName().getLocalPart());
            }
        }
    }
    return addPath(addPath(addPath(getActionBaseUri(operation),
                                   operation.getName().getLocalPart()), "Fault"), faultName);
}
 
Example 5
Source File: WebFaultInInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
private MessagePartInfo getFaultMessagePart(QName qname, OperationInfo op) {
    if (op.isUnwrapped() && (op instanceof UnwrappedOperationInfo)) {
        op = ((UnwrappedOperationInfo)op).getWrappedOperation();
    }

    for (FaultInfo faultInfo : op.getFaults()) {
        for (MessagePartInfo mpi : faultInfo.getMessageParts()) {
            String ns = null;
            if (mpi.isElement()) {
                ns = mpi.getElementQName().getNamespaceURI();
            } else {
                ns = mpi.getTypeQName().getNamespaceURI();
            }
            if (qname.getLocalPart().equals(mpi.getConcreteName().getLocalPart())
                    && qname.getNamespaceURI().equals(ns)) {
                return mpi;
            }
        }

    }
    return null;
}
 
Example 6
Source File: OperationProcessor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void process(JavaInterface intf, OperationInfo operation) throws ToolException {
    JavaMethod method = new MethodMapper().map(operation);
    method.setInterface(intf);

    processMethod(method, operation);

    Collection<FaultInfo> faults = operation.getFaults();
    FaultProcessor faultProcessor = new FaultProcessor(context);
    faultProcessor.process(method, faults);

    method.annotate(new WSActionAnnotator(operation));

    intf.addMethod(method);
}
 
Example 7
Source File: JaxWsServiceFactoryBean.java    From cxf with Apache License 2.0 5 votes vote down vote up
private FaultInfo getFaultInfo(final OperationInfo operation, final Class<?> expClass) {
    for (FaultInfo fault : operation.getFaults()) {
        if (fault.getProperty(Class.class.getName()) == expClass) {
            return fault;
        }
    }
    return null;
}
 
Example 8
Source File: JaxWsServiceFactoryBeanTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testEndpoint() throws Exception {
    ReflectionServiceFactoryBean bean = new JaxWsServiceFactoryBean();

    URL resource = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(resource);
    bean.setWsdlURL(resource.toString());
    Bus bus = getBus();
    bean.setBus(bus);
    bean.setServiceClass(GreeterImpl.class);

    BeanInvoker invoker = new BeanInvoker(new GreeterImpl());
    bean.setInvoker(invoker);

    Service service = bean.create();

    String ns = "http://apache.org/hello_world_soap_http";
    assertEquals("SOAPService", service.getName().getLocalPart());
    assertEquals(ns, service.getName().getNamespaceURI());

    InterfaceInfo intf = service.getServiceInfos().get(0).getInterface();

    OperationInfo op = intf.getOperation(new QName(ns, "sayHi"));

    Class<?> wrapper = op.getInput().getMessageParts().get(0).getTypeClass();
    assertNotNull(wrapper);

    wrapper = op.getOutput().getMessageParts().get(0).getTypeClass();
    assertNotNull(wrapper);

    assertEquals(invoker, service.getInvoker());

    op = intf.getOperation(new QName(ns, "testDocLitFault"));
    Collection<FaultInfo> faults = op.getFaults();
    assertEquals(2, faults.size());

    FaultInfo f = op.getFault(new QName(ns, "BadRecordLitFault"));
    assertNotNull(f);
    Class<?> c = f.getProperty(Class.class.getName(), Class.class);
    assertNotNull(c);

    assertEquals(1, f.getMessageParts().size());
    MessagePartInfo mpi = f.getMessagePartByIndex(0);
    assertNotNull(mpi.getTypeClass());
}
 
Example 9
Source File: PolicyAnnotationListener.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void addPolicies(AbstractServiceFactoryBean factory, OperationInfo inf, Method m) {
    if (m == null) {
        return;
    }

    Policy p = m.getAnnotation(Policy.class);
    Policies ps = m.getAnnotation(Policies.class);
    if (p != null || ps != null) {
        List<Policy> list = new ArrayList<>();
        if (p != null) {
            list.add(p);
        }
        if (ps != null) {
            Collections.addAll(list, ps.value());
        }
        ListIterator<Policy> it = list.listIterator();
        while (it.hasNext()) {
            p = it.next();
            Policy.Placement place = p.placement();
            if (place == Policy.Placement.DEFAULT) {
                place = Policy.Placement.BINDING_OPERATION;
            }
            ServiceInfo service = inf.getInterface().getService();
            Class<?> cls = m.getDeclaringClass();
            switch (place) {
            case PORT_TYPE_OPERATION:
                addPolicy(inf, service, p, cls,
                          inf.getName().getLocalPart() + "PortTypeOpPolicy");
                it.remove();
                break;
            case PORT_TYPE_OPERATION_INPUT:
                addPolicy(inf.getInput(), service, p, cls,
                          inf.getName().getLocalPart() + "PortTypeOpInputPolicy");
                it.remove();
                break;
            case PORT_TYPE_OPERATION_OUTPUT:
                addPolicy(inf.getOutput(), service, p, cls,
                          inf.getName().getLocalPart() + "PortTypeOpOutputPolicy");
                it.remove();
                break;
            case PORT_TYPE_OPERATION_FAULT: {
                for (FaultInfo f : inf.getFaults()) {
                    if (p.faultClass().equals(f.getProperty(Class.class.getName()))) {
                        addPolicy(f, service, p, cls,
                                  f.getName().getLocalPart() + "PortTypeOpFaultPolicy");
                        it.remove();
                    }
                }
                break;
            }
            default:
                //nothing
            }
        }

        if (!list.isEmpty()) {
            List<Policy> stuff = CastUtils.cast((List<?>)inf.getProperty(EXTRA_POLICIES));
            if (stuff != null) {
                for (Policy p2 : list) {
                    if (!stuff.contains(p2)) {
                        stuff.add(p2);
                    }
                }
            } else {
                inf.setProperty(EXTRA_POLICIES, list);
            }
        }
    }
}
 
Example 10
Source File: ServiceWSDLBuilder.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected void buildPortTypeOperation(PortType portType,
                                      Collection<OperationInfo> operationInfos,
                                      final Definition def) {
    for (OperationInfo operationInfo : operationInfos) {
        Operation operation = null;
        try {
            operation = operationInfo.getProperty(
                WSDLServiceBuilder.WSDL_OPERATION, Operation.class);
        } catch (ClassCastException e) {
            // do nothing
        }

        if (operation == null) {
            operation = def.createOperation();
            addDocumentation(operation, operationInfo.getDocumentation());
            operation.setUndefined(false);
            operation.setName(operationInfo.getName().getLocalPart());
            addNamespace(operationInfo.getName().getNamespaceURI(), def);
            if (operationInfo.isOneWay()) {
                operation.setStyle(OperationType.ONE_WAY);
            }
            addExtensibilityElements(def, operation, getWSDL11Extensors(operationInfo));
            Input input = def.createInput();
            addDocumentation(input, operationInfo.getInput().getDocumentation());
            input.setName(operationInfo.getInputName());
            Message message = def.createMessage();
            buildMessage(message, operationInfo.getInput(), def);
            this.addExtensibilityAttributes(def, input, getInputExtensionAttributes(operationInfo));
            this.addExtensibilityElements(def, input, getWSDL11Extensors(operationInfo.getInput()));
            input.setMessage(message);
            operation.setInput(input);
            operation.setParameterOrdering(operationInfo.getParameterOrdering());

            if (operationInfo.getOutput() != null) {
                Output output = def.createOutput();
                addDocumentation(output, operationInfo.getOutput().getDocumentation());
                output.setName(operationInfo.getOutputName());
                message = def.createMessage();
                buildMessage(message, operationInfo.getOutput(), def);
                this.addExtensibilityAttributes(def, output, getOutputExtensionAttributes(operationInfo));
                this.addExtensibilityElements(def, output, getWSDL11Extensors(operationInfo.getOutput()));
                output.setMessage(message);
                operation.setOutput(output);
            }
            //loop to add fault
            Collection<FaultInfo> faults = operationInfo.getFaults();
            Fault fault = null;
            for (FaultInfo faultInfo : faults) {
                fault = def.createFault();
                addDocumentation(fault, faultInfo.getDocumentation());
                fault.setName(faultInfo.getFaultName().getLocalPart());
                message = def.createMessage();
                buildMessage(message, faultInfo, def);
                this.addExtensibilityAttributes(def, fault, faultInfo.getExtensionAttributes());
                this.addExtensibilityElements(def, fault, getWSDL11Extensors(faultInfo));
                fault.setMessage(message);
                operation.addFault(fault);
            }
        }
        portType.addOperation(operation);
    }
}
 
Example 11
Source File: ReflectionServiceFactoryBean.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected void buildServiceFromClass() {
    Object o = getBus().getProperty("requireExplicitContractLocation");
    if (o != null
        && ("true".equals(o) || Boolean.TRUE.equals(o))) {
        throw new ServiceConstructionException(new Message("NO_WSDL_PROVIDED", LOG,
                                                           getServiceClass().getName()));
    }
    if (LOG.isLoggable(Level.INFO)) {
        LOG.info("Creating Service " + getServiceQName() + " from class " + getServiceClass().getName());
    }
    populateFromClass = true;

    if (Proxy.isProxyClass(this.getServiceClass())) {
        LOG.log(Level.WARNING, "USING_PROXY_FOR_SERVICE", getServiceClass());
    }

    sendEvent(Event.CREATE_FROM_CLASS, getServiceClass());

    ServiceInfo serviceInfo = new ServiceInfo();
    SchemaCollection col = serviceInfo.getXmlSchemaCollection();
    col.getXmlSchemaCollection().setSchemaResolver(new CatalogXmlSchemaURIResolver(this.getBus()));
    col.getExtReg().registerSerializer(MimeAttribute.class, new MimeSerializer());

    ServiceImpl service = new ServiceImpl(serviceInfo);
    setService(service);
    setServiceProperties();

    serviceInfo.setName(getServiceQName());
    serviceInfo.setTargetNamespace(serviceInfo.getName().getNamespaceURI());

    sendEvent(Event.SERVICE_SET, getService());

    createInterface(serviceInfo);


    Set<?> wrapperClasses = this.getExtraClass();
    for (ServiceInfo si : getService().getServiceInfos()) {
        if (wrapperClasses != null && !wrapperClasses.isEmpty()) {
            si.setProperty(EXTRA_CLASS, wrapperClasses);
        }
    }
    initializeDataBindings();

    boolean isWrapped = isWrapped() || hasWrappedMethods(serviceInfo.getInterface());
    if (isWrapped) {
        initializeWrappedSchema(serviceInfo);
    }

    for (OperationInfo opInfo : serviceInfo.getInterface().getOperations()) {
        Method m = (Method)opInfo.getProperty(METHOD);
        if (!isWrapped(m) && !isRPC(m) && opInfo.getInput() != null) {
            createBareMessage(serviceInfo, opInfo, false);
        }

        if (!isWrapped(m) && !isRPC(m) && opInfo.getOutput() != null) {
            createBareMessage(serviceInfo, opInfo, true);
        }

        if (opInfo.hasFaults()) {
            // check to make sure the faults are elements
            for (FaultInfo fault : opInfo.getFaults()) {
                QName qn = (QName)fault.getProperty("elementName");
                MessagePartInfo part = fault.getFirstMessagePart();
                if (!part.isElement()) {
                    part.setElement(true);
                    part.setElementQName(qn);
                    checkForElement(serviceInfo, part);
                }
            }
        }
    }
    if (LOG.isLoggable(Level.FINE) || isValidate()) {
        ServiceModelSchemaValidator validator = new ServiceModelSchemaValidator(serviceInfo);
        validator.walk();
        String validationComplaints = validator.getComplaints();
        if (!"".equals(validationComplaints)) {
            if (isValidate()) {
                LOG.warning(validationComplaints);
            } else {
                LOG.fine(validationComplaints);
            }
        }
    }
}
 
Example 12
Source File: AnnotationsFactoryBeanListener.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void addDocumentation(OperationInfo inf, Placement defPlace, WSDLDocumentation ... values) {
    List<WSDLDocumentation> later = new ArrayList<>();
    for (WSDLDocumentation doc : values) {
        WSDLDocumentation.Placement p = doc.placement();
        if (p == WSDLDocumentation.Placement.DEFAULT) {
            p = defPlace;
        }
        switch (p) {
        case PORT_TYPE_OPERATION:
            inf.setDocumentation(doc.value());
            break;
        case PORT_TYPE_OPERATION_INPUT:
            inf.getInput().setDocumentation(doc.value());
            break;
        case PORT_TYPE_OPERATION_OUTPUT:
            inf.getOutput().setDocumentation(doc.value());
            break;
        case FAULT_MESSAGE:
        case PORT_TYPE_OPERATION_FAULT: {
            for (FaultInfo f : inf.getFaults()) {
                if (doc.faultClass().equals(f.getProperty(Class.class.getName()))) {
                    if (p == Placement.FAULT_MESSAGE) {
                        f.setMessageDocumentation(doc.value());
                    } else {
                        f.setDocumentation(doc.value());
                    }
                }
            }
            break;
        }
        case INPUT_MESSAGE:
            inf.getInput().setMessageDocumentation(doc.value());
            break;
        case OUTPUT_MESSAGE:
            inf.getOutput().setMessageDocumentation(doc.value());
            break;
        default:
            later.add(doc);
        }
    }
    if (!later.isEmpty()) {
        List<WSDLDocumentation> stuff = CastUtils.cast((List<?>)inf
                                                           .getProperty(EXTRA_DOCUMENTATION));
        if (stuff != null) {
            stuff.addAll(later);
        } else {
            inf.setProperty(EXTRA_DOCUMENTATION, later);
        }
    }
}