Java Code Examples for javax.wsdl.factory.WSDLFactory#newInstance()

The following examples show how to use javax.wsdl.factory.WSDLFactory#newInstance() . 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: BesDAO.java    From development with Apache License 2.0 7 votes vote down vote up
void validateVersion(String wsdlUrl) {
    WSDLLocator locator = new BasicAuthWSDLLocator(wsdlUrl, null, null);
    WSDLFactory wsdlFactory;
    Definition serviceDefinition;
    try {
        wsdlFactory = WSDLFactory.newInstance();
        WSDLReader wsdlReader = wsdlFactory.newWSDLReader();
        // avoid importing external documents
        wsdlReader.setExtensionRegistry(new WSVersionExtensionRegistry());
        serviceDefinition = wsdlReader.readWSDL(locator);
        Element versionElement = serviceDefinition
                .getDocumentationElement();
        if (!CTMGApiVersion.version.equals(versionElement.getTextContent())) {
            LOGGER.warn("Web service mismatches and the version value, expected: "
                    + CTMGApiVersion.version
                    + " and the one got from wsdl: "
                    + versionElement.getTextContent());
        }
    } catch (WSDLException e) {
        LOGGER.warn("Remote wsdl cannot be retrieved from CT_MG. [Cause: "
                + e.getMessage() + "]", e);
    }

}
 
Example 2
Source File: OASISCatalogTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testWSDLLocatorWithoutCatalog() throws Exception {
    URL wsdl =
        getClass().getResource("/wsdl/catalog/hello_world_services.wsdl");
    assertNotNull(wsdl);

    WSDLFactory wsdlFactory = WSDLFactory.newInstance();
    WSDLReader wsdlReader = wsdlFactory.newWSDLReader();
    wsdlReader.setFeature("javax.wsdl.verbose", false);

    OASISCatalogManager catalog = new OASISCatalogManager();
    CatalogWSDLLocator wsdlLocator =
        new CatalogWSDLLocator(wsdl.toString(), catalog);
    try {
        wsdlReader.readWSDL(wsdlLocator);
        fail("Test did not fail as expected");
    } catch (WSDLException e) {
        // ignore
    }
}
 
Example 3
Source File: WSDLServiceBuilderTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void setUpDefinition(String wsdl, int serviceSeq) throws Exception {
    URL url = getClass().getResource(wsdl);
    assertNotNull("could not find wsdl " + wsdl, url);
    String wsdlUrl = url.toString();
    LOG.info("the path of wsdl file is " + wsdlUrl);
    WSDLFactory wsdlFactory = WSDLFactory.newInstance();
    WSDLReader wsdlReader = wsdlFactory.newWSDLReader();
    wsdlReader.setFeature("javax.wsdl.verbose", false);

    def = wsdlReader.readWSDL(new CatalogWSDLLocator(wsdlUrl));

    int seq = 0;
    for (Service serv : CastUtils.cast(def.getServices().values(), Service.class)) {
        if (serv != null) {
            service = serv;
            if (seq == serviceSeq) {
                break;
            }
            seq++;
        }
    }
}
 
Example 4
Source File: WSDLGenerationTester.java    From cxf with Apache License 2.0 6 votes vote down vote up
public File writeDefinition(File targetDir, File defnFile) throws Exception {
    WSDLManager wm = BusFactory.getThreadDefaultBus().getExtension(WSDLManager.class);
    File bkFile = new File(targetDir, "bk_" + defnFile.getName());
    FileWriter writer = new FileWriter(bkFile);
    WSDLFactory factory
        = WSDLFactory.newInstance("org.apache.cxf.tools.corba.utils.TestWSDLCorbaFactoryImpl");
    WSDLReader reader = factory.newWSDLReader();
    reader.setFeature("javax.wsdl.importDocuments", false);
    reader.setExtensionRegistry(wm.getExtensionRegistry());
    final String url = defnFile.toString();
    CatalogWSDLLocator locator = new CatalogWSDLLocator(url, (Bus)null);

    Definition wsdlDefn = reader.readWSDL(locator);

    WSDLWriter wsdlWriter = factory.newWSDLWriter();
    wsdlWriter.writeWSDL(wsdlDefn, writer);
    writer.close();
    writer = null;
    reader = null;
    return bkFile;
}
 
Example 5
Source File: BPELPlanContext.java    From container with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a List of Port which implement the given portType inside the given WSDL File
 *
 * @param portType the portType to use
 * @param wsdlFile the WSDL File to look in
 * @return a List of Port which implement the given PortType
 * @throws WSDLException is thrown when the given File is not a WSDL File or initializing the WSDL Factory failed
 */
public List<Port> getPortsInWSDLFileForPortType(final QName portType, final File wsdlFile) throws WSDLException {
    final List<Port> wsdlPorts = new ArrayList<>();
    // taken from http://www.java.happycodings.com/Other/code24.html
    final WSDLFactory factory = WSDLFactory.newInstance();
    final WSDLReader reader = factory.newWSDLReader();
    reader.setFeature("javax.wsdl.verbose", false);
    final Definition wsdlInstance = reader.readWSDL(wsdlFile.getAbsolutePath());
    final Map services = wsdlInstance.getAllServices();
    for (final Object key : services.keySet()) {
        final Service service = (Service) services.get(key);
        final Map ports = service.getPorts();
        for (final Object portKey : ports.keySet()) {
            final Port port = (Port) ports.get(portKey);
            if (port.getBinding().getPortType().getQName().getNamespaceURI().equals(portType.getNamespaceURI())
                && port.getBinding().getPortType().getQName().getLocalPart().equals(portType.getLocalPart())) {
                wsdlPorts.add(port);
            }
        }
    }
    return wsdlPorts;
}
 
Example 6
Source File: WSDLDocCreator.java    From jolie with GNU Lesser General Public License v2.1 6 votes vote down vote up
public Definition initWsdl( String serviceName, String filename ) {
	try {
		wsdlFactory = WSDLFactory.newInstance();
		localDef = wsdlFactory.newDefinition();
		extensionRegistry = wsdlFactory.newPopulatedExtensionRegistry();
		if( serviceName != null ) {
			QName servDefQN = new QName( serviceName );
			localDef.setQName( servDefQN );
		}
		localDef.addNamespace( NameSpacesEnum.WSDL.getNameSpacePrefix(), NameSpacesEnum.WSDL.getNameSpaceURI() );
		localDef.addNamespace( NameSpacesEnum.SOAP.getNameSpacePrefix(), NameSpacesEnum.SOAP.getNameSpaceURI() );
		localDef.addNamespace( "tns", tns );
		localDef.addNamespace( NameSpacesEnum.XML_SCH.getNameSpacePrefix(),
			NameSpacesEnum.XML_SCH.getNameSpaceURI() );
		localDef.setTargetNamespace( tns );
		localDef.addNamespace( "xsd1", tnsSchema );
	} catch( WSDLException ex ) {
		Logger.getLogger( WSDLDocCreator.class.getName() ).log( Level.SEVERE, null, ex );
	}

	return localDef;
}
 
Example 7
Source File: BPELPlanContext.java    From container with Apache License 2.0 6 votes vote down vote up
/**
 * Checks whether the given portType is declared in the given WSDL File
 *
 * @param portType the portType to check with
 * @param wsdlFile the WSDL File to check in
 * @return true if the portType is declared in the given WSDL file
 * @throws WSDLException is thrown when either the given File is not a WSDL File or initializing the WSDL Factory
 *                       failed
 */
public boolean containsPortType(final QName portType, final Path wsdlFile) throws WSDLException {
    final WSDLFactory factory = WSDLFactory.newInstance();
    final WSDLReader reader = factory.newWSDLReader();
    reader.setFeature("javax.wsdl.verbose", false);
    final Definition wsdlInstance = reader.readWSDL(wsdlFile.toAbsolutePath().toString());
    final Map portTypes = wsdlInstance.getAllPortTypes();
    for (final Object key : portTypes.keySet()) {
        final PortType portTypeInWsdl = (PortType) portTypes.get(key);
        if (portTypeInWsdl.getQName().getNamespaceURI().equals(portType.getNamespaceURI())
            && portTypeInWsdl.getQName().getLocalPart().equals(portType.getLocalPart())) {
            return true;
        }
    }
    return false;
}
 
Example 8
Source File: WSDLHelper.java    From tesb-studio-se with Apache License 2.0 5 votes vote down vote up
public static Definition load(String wsdlLocation, String filenamePrefix) throws InvocationTargetException, WSDLException {
    WSDLFactory wsdlFactory = WSDLFactory.newInstance();
    WSDLReader newWSDLReader = wsdlFactory.newWSDLReader();

    newWSDLReader.setExtensionRegistry(wsdlFactory.newPopulatedExtensionRegistry());
    newWSDLReader.setFeature(com.ibm.wsdl.Constants.FEATURE_VERBOSE, false);
    return newWSDLReader.readWSDL(new InMemoryWSDLLocator(wsdlLocation, new WSDLLoader().load(wsdlLocation, filenamePrefix
            + "%d.wsdl")));
}
 
Example 9
Source File: JAXBDataBindingTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    jaxbDataBinding = new JAXBDataBinding();
    String wsdlUrl = getClass().getResource(WSDL_PATH).toString();
    LOG.info("the path of wsdl file is " + wsdlUrl);
    WSDLFactory wsdlFactory = WSDLFactory.newInstance();
    WSDLReader wsdlReader = wsdlFactory.newWSDLReader();
    wsdlReader.setFeature("javax.wsdl.verbose", false);
    def = wsdlReader.readWSDL(wsdlUrl);


    control = EasyMock.createNiceControl();
    bus = control.createMock(Bus.class);
    bindingFactoryManager = control.createMock(BindingFactoryManager.class);
    destinationFactoryManager = control.createMock(DestinationFactoryManager.class);

    EasyMock.expect(bus.getExtension(BindingFactoryManager.class)).andStubReturn(bindingFactoryManager);
    EasyMock.expect(bus.getExtension(DestinationFactoryManager.class))
        .andStubReturn(destinationFactoryManager);

    control.replay();

    WSDLServiceBuilder wsdlServiceBuilder = new WSDLServiceBuilder(bus);
    for (Service serv : CastUtils.cast(def.getServices().values(), Service.class)) {
        if (serv != null) {
            service = serv;
            break;
        }
    }

    wsdlServiceBuilder.buildServices(def, service);
}
 
Example 10
Source File: Wsdl.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Get a WSDLReader.
 *
 * @return WSDLReader.
 * @throws WSDLException
 *           on error.
 */
private WSDLReader getReader() throws WSDLException {

  WSDLFactory wsdlFactory = WSDLFactory.newInstance();
  WSDLReader wsdlReader = wsdlFactory.newWSDLReader();
  ExtensionRegistry registry = wsdlFactory.newPopulatedExtensionRegistry();
  wsdlReader.setExtensionRegistry( registry );
  wsdlReader.setFeature( "javax.wsdl.verbose", true );
  wsdlReader.setFeature( "javax.wsdl.importDocuments", true );
  return wsdlReader;
}
 
Example 11
Source File: ODEEndpointUpdater.java    From container with Apache License 2.0 5 votes vote down vote up
/**
 * Contructor *
 *
 * @throws WSDLException if no instance of WSDLFactory was found
 */
public ODEEndpointUpdater(final String servicesRoot, final String engineType, ICoreEndpointService endpointService) throws WSDLException {
    this.factory = WSDLFactory.newInstance();
    this.servicesRoot = servicesRoot;
    this.engineType = engineType;
    this.endpointService = endpointService;
}
 
Example 12
Source File: ManagementBusInvocationPluginSoapHttp.java    From container with Apache License 2.0 5 votes vote down vote up
private Definition pullWsdlDefinitions(String endpoint) {
    if (!endpoint.endsWith("?wsdl")) {
        endpoint = endpoint + "?wsdl";
    }
    LOG.info("Parsing WSDL at: {}.", endpoint);
    WSDLFactory wsdlFactory = null;
    try {
        wsdlFactory = WSDLFactory.newInstance();
        WSDLReader wsdlDefinitionReader = wsdlFactory.newWSDLReader();
        return wsdlDefinitionReader.readWSDL(endpoint);
    } catch (WSDLException e) {
        LOG.warn("Could not read WSDL definitions from endpoint {} due to WSDLException", endpoint, e);
    }
    return null;
}
 
Example 13
Source File: XSDToWSDLProcessor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void initWSDL() throws ToolException {
    try {
        wsdlFactory = WSDLFactory.newInstance();
        wsdlDefinition = wsdlFactory.newDefinition();
    } catch (WSDLException we) {
        Message msg = new Message("FAIL_TO_CREATE_WSDL_DEFINITION", LOG);
        throw new ToolException(msg, we);
    }
}
 
Example 14
Source File: WSDLUtils.java    From tesb-studio-se with Apache License 2.0 5 votes vote down vote up
public static Definition getDefinition(IFile pathToWsdl) throws CoreException {
    try {
        WSDLFactory wsdlFactory = WSDLFactory.newInstance();
        WSDLReader newWSDLReader = wsdlFactory.newWSDLReader();

        newWSDLReader.setExtensionRegistry(wsdlFactory.newPopulatedExtensionRegistry());
        newWSDLReader.setFeature(com.ibm.wsdl.Constants.FEATURE_VERBOSE, false);
        return newWSDLReader.readWSDL(pathToWsdl.getLocationURI().toString());
    } catch (WSDLException e) {
        throw getCoreException(null, e);
    }
}
 
Example 15
Source File: WSDLImporter.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * Parse the WSDL definition using WSDL4J.
 */
protected Definition parseWSDLDefinition() throws WSDLException {
    WSDLFactory wsdlFactory = WSDLFactory.newInstance();
    WSDLReader reader = wsdlFactory.newWSDLReader();
    reader.setFeature("javax.wsdl.verbose", false);
    reader.setFeature("javax.wsdl.importDocuments", true);
    Definition definition = reader.readWSDL(this.wsdlLocation);
    return definition;
}
 
Example 16
Source File: JAXBExtensionHelperTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {

    wsdlFactory = WSDLFactory.newInstance();
    wsdlReader = wsdlFactory.newWSDLReader();
    wsdlReader.setFeature("javax.wsdl.verbose", false);
    registry = wsdlReader.getExtensionRegistry();
    if (registry == null) {
        registry = wsdlFactory.newPopulatedExtensionRegistry();
    }
}
 
Example 17
Source File: WSDLImporter.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Parse the WSDL definition using WSDL4J.
 */
protected Definition parseWSDLDefinition() throws WSDLException {
  WSDLFactory wsdlFactory = WSDLFactory.newInstance();
  WSDLReader reader = wsdlFactory.newWSDLReader();
  reader.setFeature("javax.wsdl.verbose", false);
  reader.setFeature("javax.wsdl.importDocuments", true);
  Definition definition = reader.readWSDL(this.wsdlLocation);
  return definition;
}
 
Example 18
Source File: WSDLCache.java    From jolie with GNU Lesser General Public License v2.1 4 votes vote down vote up
private WSDLCache()
	throws WSDLException {
	cache = new HashMap<>();
	factory = WSDLFactory.newInstance();
}
 
Example 19
Source File: WSPortConnector.java    From development with Apache License 2.0 4 votes vote down vote up
/**
 * Reads the WSDL and determines the target namespace.
 * 
 * @param locator
 *            The URL of the WSDL.
 * @param host
 *            optional the host to be used when the one from the wsdl must
 *            not be used
 * @return The service's target namespace.
 * @throws WSDLException
 *             Thrown in case the WSDL could not be evaluated.
 */
private WSPortDescription getServiceDetails(WSDLLocator locator, String host)
        throws WSDLException {
    WSDLFactory wsdlFactory = WSDLFactory.newInstance();

    WSDLReader wsdlReader = wsdlFactory.newWSDLReader();
    Definition serviceDefinition = wsdlReader.readWSDL(locator);
    String tns = serviceDefinition.getTargetNamespace();
    // read the port name
    String endpointURL = null;
    final Map<?, ?> services = serviceDefinition.getServices();
    if (services != null) {
        for (Object serviceValue : services.values()) {
            javax.wsdl.Service service = (javax.wsdl.Service) serviceValue;
            Map<?, ?> ports = service.getPorts();
            if (ports != null) {
                for (Object portValue : ports.values()) {
                    Port port = (Port) portValue;
                    List<?> extensibilityElements = port
                            .getExtensibilityElements();
                    for (Object ex : extensibilityElements) {
                        ExtensibilityElement ext = (ExtensibilityElement) ex;
                        if (ext instanceof SOAPAddress) {
                            SOAPAddress address = (SOAPAddress) ext;
                            endpointURL = address.getLocationURI();
                            if (host != null) {
                                int idx = endpointURL.indexOf("//") + 2;
                                String tmp = endpointURL.substring(0, idx)
                                        + host
                                        + endpointURL.substring(endpointURL
                                                .indexOf(':', idx));
                                endpointURL = tmp;
                            }
                        }
                    }
                }
            }
        }
    }

    WSPortDescription result = new WSPortDescription();
    result.setTargetNamespace(tns);
    result.setEndpointURL(endpointURL);
    Element versionElement = serviceDefinition.getDocumentationElement();
    if (versionElement != null) {
        result.setVersion(versionElement.getTextContent());
    }
    return result;
}
 
Example 20
Source File: WSDLManagerImpl.java    From cxf with Apache License 2.0 4 votes vote down vote up
private WSDLManagerImpl(Bus b) throws BusException {
    try {
        // This is needed to avoid security exceptions when running with a security manager
        if (System.getSecurityManager() == null) {
            factory = WSDLFactory.newInstance();
        } else {
            try {
                factory = AccessController.doPrivileged(
                        (PrivilegedExceptionAction<WSDLFactory>) WSDLFactory::newInstance);
            } catch (PrivilegedActionException paex) {
                throw new BusException(paex);
            }
        }
        registry = factory.newPopulatedExtensionRegistry();
        registry.registerSerializer(Types.class,
                                    WSDLConstants.QNAME_SCHEMA,
                                    new SchemaSerializer());
        // these will replace whatever may have already been registered
        // in these places, but there's no good way to check what was
        // there before.
        QName header = new QName(WSDLConstants.NS_SOAP, "header");
        registry.registerDeserializer(MIMEPart.class,
                                      header,
                                      registry.queryDeserializer(BindingInput.class, header));
        registry.registerSerializer(MIMEPart.class,
                                    header,
                                    registry.querySerializer(BindingInput.class, header));
        // get the original classname of the SOAPHeader
        // implementation that was stored in the registry.
        Class<? extends ExtensibilityElement> clazz =
            registry.createExtension(BindingInput.class, header).getClass();
        registry.mapExtensionTypes(MIMEPart.class, header, clazz);
        // register some known extension attribute types that are not recognized by the default registry
        addExtensionAttributeTypes(registry);
    } catch (WSDLException e) {
        throw new BusException(e);
    }
    definitionsMap = new CacheMap<>();
    schemaCacheMap = new CacheMap<>();

    setBus(b);
}