Search in sources :

Example 16 with WSDLException

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

the class ReflectionServiceFactorBeanTest method testEmptyWsdlAndNoServiceClass.

@Test
public void testEmptyWsdlAndNoServiceClass() throws Exception {
    final String dummyWsdl = "target/dummy.wsdl";
    ReflectionServiceFactoryBean bean = new ReflectionServiceFactoryBean();
    Bus bus = control.createMock(Bus.class);
    WSDLManager wsdlmanager = control.createMock(WSDLManager.class);
    EasyMock.expect(bus.getExtension(WSDLManager.class)).andReturn(wsdlmanager);
    EasyMock.expect(wsdlmanager.getDefinition(dummyWsdl)).andThrow(new WSDLException("PARSER_ERROR", "Problem parsing '" + dummyWsdl + "'."));
    EasyMock.expect(bus.getExtension(FactoryBeanListenerManager.class)).andReturn(null);
    control.replay();
    bean.setWsdlURL(dummyWsdl);
    bean.setServiceName(new QName("http://cxf.apache.org/hello_world_soap_http", "GreeterService"));
    bean.setBus(bus);
    try {
        bean.create();
        fail("no valid wsdl nor service class specified");
    } catch (ServiceConstructionException e) {
    // ignore
    }
}
Also used : Bus(org.apache.cxf.Bus) WSDLException(javax.wsdl.WSDLException) QName(javax.xml.namespace.QName) WSDLManager(org.apache.cxf.wsdl.WSDLManager) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) Test(org.junit.Test)

Example 17 with WSDLException

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

the class OperationVisitor method generateBindingOperation.

private BindingOperation generateBindingOperation(Binding wsdlBinding, Operation op, String corbaOpName) {
    BindingOperation bindingOperation = definition.createBindingOperation();
    // OperationType operationType = null;
    try {
        corbaOperation = (OperationType) extReg.createExtension(BindingOperation.class, CorbaConstants.NE_CORBA_OPERATION);
    } catch (WSDLException ex) {
        throw new RuntimeException(ex);
    }
    corbaOperation.setName(corbaOpName);
    bindingOperation.addExtensibilityElement((ExtensibilityElement) corbaOperation);
    bindingOperation.setOperation(op);
    bindingOperation.setName(op.getName());
    binding.addBindingOperation(bindingOperation);
    return bindingOperation;
}
Also used : BindingOperation(javax.wsdl.BindingOperation) WSDLException(javax.wsdl.WSDLException)

Example 18 with WSDLException

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

the class PortTypeVisitor method createBinding.

public Binding createBinding(String scopedPortTypeName) {
    StringBuilder bname = new StringBuilder();
    bname.append(scopedPortTypeName).append("CORBABinding");
    QName bqname = new QName(rootDefinition.getTargetNamespace(), bname.toString());
    int count = 0;
    while (queryBinding(bqname)) {
        bname.append(count);
        bqname = new QName(rootDefinition.getTargetNamespace(), bname.toString());
    }
    Binding binding = rootDefinition.createBinding();
    binding.setPortType(portType);
    binding.setQName(bqname);
    try {
        BindingType bindingType = (BindingType) extReg.createExtension(Binding.class, CorbaConstants.NE_CORBA_BINDING);
        String pragmaPrefix = (this.getWsdlVisitor().getPragmaPrefix() != null && this.getWsdlVisitor().getPragmaPrefix().length() > 0) ? this.getWsdlVisitor().getPragmaPrefix() + "/" : "";
        bindingType.setRepositoryID(CorbaConstants.REPO_STRING + pragmaPrefix + scopedPortTypeName.replace('.', '/') + CorbaConstants.IDL_VERSION);
        binding.addExtensibilityElement((ExtensibilityElement) bindingType);
    } catch (WSDLException ex) {
        throw new RuntimeException(ex);
    }
    binding.setUndefined(false);
    rootDefinition.addBinding(binding);
    return binding;
}
Also used : Binding(javax.wsdl.Binding) WSDLException(javax.wsdl.WSDLException) QName(javax.xml.namespace.QName) BindingType(org.apache.cxf.binding.corba.wsdl.BindingType)

Example 19 with WSDLException

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

the class WSDL11Validator method isValid.

public boolean isValid() throws ToolException {
    // boolean isValid = true;
    String schemaDir = getSchemaDir();
    String[] schemas = (String[]) env.get(ToolConstants.CFG_SCHEMA_URL);
    // Tool will use the following sequence to find the schema files
    // 1.ToolConstants.CFG_SCHEMA_DIR from ToolContext
    // 2.ToolConstants.CXF_SCHEMA_DIR from System property
    // 3.If 1 and 2 is null , then load these schema files from jar file
    String wsdl = (String) env.get(ToolConstants.CFG_WSDLURL);
    Document doc = getWSDLDoc(wsdl);
    if (doc == null) {
        return true;
    }
    if (this.def == null) {
        try {
            this.def = getBus().getExtension(WSDLManager.class).getDefinition(wsdl);
        } catch (WSDLException e) {
            throw new ToolException(e);
        }
    }
    WSDLRefValidator wsdlRefValidator = new WSDLRefValidator(this.def, doc, getBus());
    wsdlRefValidator.setSuppressWarnings(env.optionSet(ToolConstants.CFG_SUPPRESS_WARNINGS));
    validators.add(wsdlRefValidator);
    if (env.fullValidateWSDL()) {
        validators.add(new UniqueBodyPartsValidator(this.def));
        validators.add(new WSIBPValidator(this.def));
        validators.add(new MIMEBindingValidator(this.def));
    }
    boolean notValid = false;
    for (AbstractValidator validator : validators) {
        if (!validator.isValid()) {
            notValid = true;
            addErrorMessage(validator.getErrorMessage());
        }
    }
    if (notValid) {
        throw new ToolException(this.getErrorMessage());
    }
    // By default just use WsdlRefValidator
    if (!env.fullValidateWSDL()) {
        return true;
    }
    final SchemaValidator schemaValidator;
    if (!StringUtils.isEmpty(schemaDir)) {
        schemaValidator = new SchemaValidator(schemaDir, wsdl, schemas);
    } else {
        try {
            schemaValidator = new SchemaValidator(getDefaultSchemas(), wsdl, schemas);
        } catch (IOException e) {
            throw new ToolException("Schemas can not be loaded before validating wsdl", e);
        }
    }
    if (!schemaValidator.isValid()) {
        this.addErrorMessage(schemaValidator.getErrorMessage());
        throw new ToolException(this.getErrorMessage());
    }
    return true;
}
Also used : WSDLException(javax.wsdl.WSDLException) AbstractValidator(org.apache.cxf.tools.validator.AbstractValidator) IOException(java.io.IOException) Document(org.w3c.dom.Document) ToolException(org.apache.cxf.tools.common.ToolException)

Example 20 with WSDLException

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

the class Wsdl11AttachmentPolicyProviderTest method oneTimeSetUp.

@BeforeClass
public static void oneTimeSetUp() throws Exception {
    IMocksControl control = EasyMock.createNiceControl();
    Bus bus = control.createMock(Bus.class);
    WSDLManager manager = new WSDLManagerImpl();
    WSDLServiceBuilder builder = new WSDLServiceBuilder(bus);
    DestinationFactoryManager dfm = control.createMock(DestinationFactoryManager.class);
    EasyMock.expect(bus.getExtension(DestinationFactoryManager.class)).andReturn(dfm).anyTimes();
    EasyMock.expect(dfm.getDestinationFactory(EasyMock.isA(String.class))).andReturn(null).anyTimes();
    BindingFactoryManager bfm = control.createMock(BindingFactoryManager.class);
    EasyMock.expect(bus.getExtension(BindingFactoryManager.class)).andReturn(bfm).anyTimes();
    EasyMock.expect(bfm.getBindingFactory(EasyMock.isA(String.class))).andReturn(null).anyTimes();
    control.replay();
    int n = 19;
    services = new ServiceInfo[n];
    endpoints = new EndpointInfo[n];
    for (int i = 0; i < n; i++) {
        String resourceName = "/attachment/wsdl11/test" + i + ".wsdl";
        URL url = Wsdl11AttachmentPolicyProviderTest.class.getResource(resourceName);
        try {
            services[i] = builder.buildServices(manager.getDefinition(url.toString())).get(0);
        } catch (WSDLException ex) {
            ex.printStackTrace();
            fail("Failed to build service from resource " + resourceName);
        }
        assertNotNull(services[i]);
        endpoints[i] = services[i].getEndpoints().iterator().next();
        assertNotNull(endpoints[i]);
    }
    control.verify();
}
Also used : IMocksControl(org.easymock.IMocksControl) Bus(org.apache.cxf.Bus) DestinationFactoryManager(org.apache.cxf.transport.DestinationFactoryManager) WSDLException(javax.wsdl.WSDLException) WSDLServiceBuilder(org.apache.cxf.wsdl11.WSDLServiceBuilder) WSDLManager(org.apache.cxf.wsdl.WSDLManager) WSDLManagerImpl(org.apache.cxf.wsdl11.WSDLManagerImpl) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) URL(java.net.URL) BeforeClass(org.junit.BeforeClass)

Aggregations

WSDLException (javax.wsdl.WSDLException)56 ToolException (org.apache.cxf.tools.common.ToolException)18 WSDLReader (javax.wsdl.xml.WSDLReader)14 IOException (java.io.IOException)13 Definition (javax.wsdl.Definition)12 Message (org.apache.cxf.common.i18n.Message)12 QName (javax.xml.namespace.QName)11 WSDLWriter (javax.wsdl.xml.WSDLWriter)10 APIMgtWSDLException (org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException)7 File (java.io.File)6 Writer (java.io.Writer)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)6 Document (org.w3c.dom.Document)6 URL (java.net.URL)5 WSDLManager (org.apache.cxf.wsdl.WSDLManager)5 XMLStreamException (javax.xml.stream.XMLStreamException)4 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3