Search in sources :

Example 11 with Fault

use of javax.wsdl.Fault in project cxf by apache.

the class WSIBPValidator method checkR2205.

// TODO: Should also check SoapHeader/SoapHeaderFault
public boolean checkR2205() {
    Collection<Binding> bindings = CastUtils.cast(def.getBindings().values());
    for (Binding binding : bindings) {
        if (!SOAPBindingUtil.isSOAPBinding(binding)) {
            System.err.println("WSIBP Validator found <" + binding.getQName() + "> is NOT a SOAP binding");
            continue;
        }
        if (binding.getPortType() == null) {
            // will error later
            continue;
        }
        for (Iterator<?> ite2 = binding.getPortType().getOperations().iterator(); ite2.hasNext(); ) {
            Operation operation = (Operation) ite2.next();
            Collection<Fault> faults = CastUtils.cast(operation.getFaults().values());
            if (CollectionUtils.isEmpty(faults)) {
                continue;
            }
            for (Fault fault : faults) {
                Message message = fault.getMessage();
                Collection<Part> parts = CastUtils.cast(message.getParts().values());
                for (Part part : parts) {
                    if (part.getElementName() == null) {
                        addErrorMessage(getErrorPrefix("WSI-BP-1.0 R2205") + "In Message " + message.getQName() + ", part " + part.getName() + " must specify a 'element' attribute");
                        return false;
                    }
                }
            }
        }
    }
    return true;
}
Also used : SOAPBinding(javax.jws.soap.SOAPBinding) Binding(javax.wsdl.Binding) Message(javax.wsdl.Message) Part(javax.wsdl.Part) MIMEPart(javax.wsdl.extensions.mime.MIMEPart) Fault(javax.wsdl.Fault) SoapFault(org.apache.cxf.binding.soap.wsdl.extensions.SoapFault) Operation(javax.wsdl.Operation) BindingOperation(javax.wsdl.BindingOperation)

Example 12 with Fault

use of javax.wsdl.Fault in project cxf by apache.

the class WSDLToCorbaBinding method addBindingOperations.

private void addBindingOperations(Definition definition, PortType portType, Binding binding) throws Exception {
    List<Operation> ops = CastUtils.cast(portType.getOperations());
    for (Operation op : ops) {
        try {
            BindingOperation bindingOperation = definition.createBindingOperation();
            addCorbaOperationExtElement(bindingOperation, op);
            bindingOperation.setName(op.getName());
            if (op.getInput() != null) {
                BindingInput bindingInput = definition.createBindingInput();
                bindingInput.setName(op.getInput().getName());
                bindingOperation.setBindingInput(bindingInput);
            }
            if (op.getOutput() != null) {
                BindingOutput bindingOutput = definition.createBindingOutput();
                bindingOutput.setName(op.getOutput().getName());
                bindingOperation.setBindingOutput(bindingOutput);
            }
            // add Faults
            if (op.getFaults() != null && op.getFaults().size() > 0) {
                Collection<Fault> faults = CastUtils.cast(op.getFaults().values());
                for (Fault fault : faults) {
                    BindingFault bindingFault = definition.createBindingFault();
                    bindingFault.setName(fault.getName());
                    bindingOperation.addBindingFault(bindingFault);
                }
            }
            bindingOperation.setOperation(op);
            binding.addBindingOperation(bindingOperation);
        } catch (Exception ex) {
            LOG.warning("Operation " + op.getName() + " not mapped to CORBA binding.");
        }
    }
}
Also used : BindingOperation(javax.wsdl.BindingOperation) BindingOutput(javax.wsdl.BindingOutput) BindingFault(javax.wsdl.BindingFault) Fault(javax.wsdl.Fault) BindingFault(javax.wsdl.BindingFault) Operation(javax.wsdl.Operation) BindingOperation(javax.wsdl.BindingOperation) BindingInput(javax.wsdl.BindingInput) WSDLException(javax.wsdl.WSDLException) ToolException(org.apache.cxf.tools.common.ToolException)

Example 13 with Fault

use of javax.wsdl.Fault in project cxf by apache.

the class WSDLToCorbaBinding method addCorbaOperationExtElement.

private void addCorbaOperationExtElement(BindingOperation bo, Operation op) throws Exception {
    final OperationType operationType;
    try {
        operationType = (OperationType) extReg.createExtension(BindingOperation.class, CorbaConstants.NE_CORBA_OPERATION);
    } catch (WSDLException wse) {
        LOG.log(Level.SEVERE, "Failed to create a Binding Operation extension", wse);
        throw new Exception(LOG.toString(), wse);
    }
    operationType.setName(op.getName());
    List<ParamType> params = new ArrayList<>();
    List<ArgType> returns = new ArrayList<>();
    wsdlParameter.processParameters(this, op, def, xmlSchemaList, params, returns, true);
    for (ParamType paramtype : params) {
        operationType.getParam().add(paramtype);
    }
    for (ArgType retType : returns) {
        operationType.setReturn(retType);
    }
    Collection<Fault> faults = CastUtils.cast(op.getFaults().values());
    for (Fault fault : faults) {
        RaisesType raisestype = new RaisesType();
        CorbaType extype = convertFaultToCorbaType(xmlSchemaType, fault);
        if (extype != null) {
            raisestype.setException(helper.createQNameCorbaNamespace(extype.getName()));
            operationType.getRaises().add(raisestype);
        }
    }
    bo.addExtensibilityElement((ExtensibilityElement) operationType);
}
Also used : ArgType(org.apache.cxf.binding.corba.wsdl.ArgType) RaisesType(org.apache.cxf.binding.corba.wsdl.RaisesType) CorbaType(org.apache.cxf.binding.corba.wsdl.CorbaType) WSDLException(javax.wsdl.WSDLException) ArrayList(java.util.ArrayList) Fault(javax.wsdl.Fault) BindingFault(javax.wsdl.BindingFault) OperationType(org.apache.cxf.binding.corba.wsdl.OperationType) WSDLException(javax.wsdl.WSDLException) ToolException(org.apache.cxf.tools.common.ToolException) ParamType(org.apache.cxf.binding.corba.wsdl.ParamType)

Example 14 with Fault

use of javax.wsdl.Fault in project cxf by apache.

the class PortTypeVisitor method visitInterfaceInheritanceSpec.

private AST visitInterfaceInheritanceSpec(AST interfaceInheritanceSpecNode, Binding binding, Scope childScope) {
    // <interface_inheritance_spec> ::= ":" <interface_name> { "," <interface_name> }*
    AST interfaceNameNode = interfaceInheritanceSpecNode.getFirstChild();
    BindingType corbaBinding = findCorbaBinding(binding);
    List<Scope> inheritedScopes = new ArrayList<>();
    while (interfaceNameNode != null) {
        // check for porttypes in current & parent scopes
        Scope interfaceScope = null;
        PortType intf = null;
        if (ScopedNameVisitor.isFullyScopedName(interfaceNameNode)) {
            interfaceScope = ScopedNameVisitor.getFullyScopedName(new Scope(), interfaceNameNode);
            intf = findPortType(interfaceScope);
        }
        Scope currentScope = getScope();
        while (intf == null && currentScope != currentScope.getParent()) {
            if (ScopedNameVisitor.isFullyScopedName(interfaceNameNode)) {
                interfaceScope = ScopedNameVisitor.getFullyScopedName(currentScope, interfaceNameNode);
            } else {
                interfaceScope = new Scope(currentScope, interfaceNameNode.toString());
            }
            intf = findPortType(interfaceScope);
            currentScope = currentScope.getParent();
        }
        if (intf == null) {
            if (ScopedNameVisitor.isFullyScopedName(interfaceNameNode)) {
                interfaceScope = ScopedNameVisitor.getFullyScopedName(new Scope(), interfaceNameNode);
            } else {
                interfaceScope = new Scope(new Scope(), interfaceNameNode);
            }
            intf = findPortType(interfaceScope);
        }
        if (intf == null) {
            throw new RuntimeException("[InterfaceVisitor] Unknown Interface: " + interfaceNameNode.toString());
        }
        Scope defnScope = interfaceScope.getParent();
        Definition defn = manager.getWSDLDefinition(mapper.map(defnScope));
        inheritedScopes.add(interfaceScope);
        if (defn != null && !defn.getTargetNamespace().equals(definition.getTargetNamespace())) {
            String key = defnScope.toString("_");
            String fileName = getWsdlVisitor().getOutputDir() + System.getProperty("file.separator") + key;
            manager.addWSDLDefinitionImport(definition, defn, key, fileName);
        }
        Binding inheritedBinding = findBinding(intf);
        BindingType inheritedCorbaBinding = findCorbaBinding(inheritedBinding);
        corbaBinding.getBases().add(inheritedCorbaBinding.getRepositoryID());
        // add all the operations of the inherited port type.
        for (Operation op : CastUtils.cast(intf.getOperations(), Operation.class)) {
            // check to see all the inherited namespaces are added.
            String inputNS = op.getInput().getMessage().getQName().getNamespaceURI();
            manager.addWSDLDefinitionNamespace(definition, mapper.mapNSToPrefix(inputNS), inputNS);
            // Make sure we import the wsdl for the input namespace
            if (definition.getImports().get(inputNS) == null && !mapper.isDefaultMapping() && !definition.getTargetNamespace().equals(inputNS)) {
                manager.addWSDLDefinitionImport(definition, manager.getWSDLDefinition(inputNS), mapper.mapNSToPrefix(inputNS), manager.getImportedWSDLDefinitionFile(inputNS));
            }
            if (op.getOutput() != null) {
                String outputNS = op.getOutput().getMessage().getQName().getNamespaceURI();
                manager.addWSDLDefinitionNamespace(definition, mapper.mapNSToPrefix(outputNS), outputNS);
                // Make sure we import the wsdl for the output namespace
                if (definition.getImports().get(outputNS) == null && !mapper.isDefaultMapping() && !definition.getTargetNamespace().equals(outputNS)) {
                    manager.addWSDLDefinitionImport(definition, manager.getWSDLDefinition(outputNS), mapper.mapNSToPrefix(outputNS), manager.getImportedWSDLDefinitionFile(outputNS));
                }
            }
            for (Iterator<Fault> faults = CastUtils.cast(op.getFaults().values().iterator()); faults.hasNext(); ) {
                String faultNS = faults.next().getMessage().getQName().getNamespaceURI();
                manager.addWSDLDefinitionNamespace(definition, mapper.mapNSToPrefix(faultNS), faultNS);
                // Make sure we import the wsdl for the fault namespace
                if (definition.getImports().get(faultNS) == null && !mapper.isDefaultMapping() && !definition.getTargetNamespace().equals(faultNS)) {
                    manager.addWSDLDefinitionImport(definition, manager.getWSDLDefinition(faultNS), mapper.mapNSToPrefix(faultNS), manager.getImportedWSDLDefinitionFile(faultNS));
                }
            }
            portType.addOperation(op);
        }
        // add all the binding extensions of the inherited corba binding
        for (Iterator<BindingOperation> it = CastUtils.cast(inheritedBinding.getBindingOperations().iterator()); it.hasNext(); ) {
            binding.addBindingOperation(it.next());
        }
        interfaceNameNode = interfaceNameNode.getNextSibling();
    }
    if ((!inheritedScopes.isEmpty()) && (wsdlVisitor.getInheritedScopeMap() != null)) {
        wsdlVisitor.getInheritedScopeMap().put(childScope, inheritedScopes);
    }
    return interfaceInheritanceSpecNode.getNextSibling();
}
Also used : Binding(javax.wsdl.Binding) AST(antlr.collections.AST) ArrayList(java.util.ArrayList) Definition(javax.wsdl.Definition) Fault(javax.wsdl.Fault) Operation(javax.wsdl.Operation) BindingOperation(javax.wsdl.BindingOperation) BindingOperation(javax.wsdl.BindingOperation) BindingType(org.apache.cxf.binding.corba.wsdl.BindingType) PortType(javax.wsdl.PortType)

Example 15 with Fault

use of javax.wsdl.Fault in project cxf by apache.

the class ServiceWSDLBuilderTest method testPingMeOperation.

@Test
public void testPingMeOperation() throws Exception {
    setupWSDL(WSDL_PATH);
    PortType portType = newDef.getPortType(new QName(newDef.getTargetNamespace(), "Greeter"));
    Operation pingMe = portType.getOperation("pingMe", "pingMeRequest", "pingMeResponse");
    assertNotNull(pingMe);
    assertEquals("pingMe", pingMe.getName());
    Input input = pingMe.getInput();
    assertNotNull(input);
    assertEquals("pingMeRequest", input.getName());
    Message message = input.getMessage();
    assertNotNull(message);
    assertEquals("pingMeRequest", message.getQName().getLocalPart());
    assertEquals(newDef.getTargetNamespace(), message.getQName().getNamespaceURI());
    assertEquals(1, message.getParts().size());
    assertEquals("in", message.getPart("in").getName());
    Output output = pingMe.getOutput();
    assertNotNull(output);
    assertEquals("pingMeResponse", output.getName());
    message = output.getMessage();
    assertNotNull(message);
    assertEquals("pingMeResponse", message.getQName().getLocalPart());
    assertEquals(newDef.getTargetNamespace(), message.getQName().getNamespaceURI());
    assertEquals(message.getParts().size(), 1);
    assertEquals("out", message.getPart("out").getName());
    assertEquals(1, pingMe.getFaults().size());
    Fault fault = pingMe.getFault("pingMeFault");
    assertNotNull(fault);
    assertEquals("pingMeFault", fault.getName());
    message = fault.getMessage();
    assertNotNull(message);
    assertEquals("pingMeFault", message.getQName().getLocalPart());
    assertEquals(newDef.getTargetNamespace(), message.getQName().getNamespaceURI());
    assertEquals(1, message.getParts().size());
    assertEquals("faultDetail", message.getPart("faultDetail").getName());
    assertNull(message.getPart("faultDetail").getTypeName());
}
Also used : Input(javax.wsdl.Input) Message(javax.wsdl.Message) QName(javax.xml.namespace.QName) Output(javax.wsdl.Output) Fault(javax.wsdl.Fault) Operation(javax.wsdl.Operation) PortType(javax.wsdl.PortType) Test(org.junit.Test)

Aggregations

Fault (javax.wsdl.Fault)18 Operation (javax.wsdl.Operation)10 BindingOperation (javax.wsdl.BindingOperation)9 QName (javax.xml.namespace.QName)9 BindingFault (javax.wsdl.BindingFault)8 Message (javax.wsdl.Message)7 Input (javax.wsdl.Input)6 Output (javax.wsdl.Output)6 Binding (javax.wsdl.Binding)5 Part (javax.wsdl.Part)5 PortType (javax.wsdl.PortType)4 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 BindingInput (javax.wsdl.BindingInput)3 BindingOutput (javax.wsdl.BindingOutput)3 SOAPFault (org.apache.axiom.soap.SOAPFault)3 AxisFault (org.apache.axis2.AxisFault)3 Definition (javax.wsdl.Definition)2