Java Code Examples for javax.wsdl.xml.WSDLReader

The following examples show how to use javax.wsdl.xml.WSDLReader. 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: development   Source File: BesDAO.java    License: 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 Project: hop   Source File: Wsdl.java    License: Apache License 2.0 6 votes vote down vote up
private Definition readWsdl( WSDLReader wsdlReader, String uri, String username, String password ) throws WSDLException, HopException, AuthenticationException {

    try {
      HttpProtocol http = new HttpProtocol();
      Document doc = XmlHandler.loadXmlString( http.get( wsdlURI.toString(), username, password ), true, false );
      if ( doc != null ) {
        return ( wsdlReader.readWSDL( doc.getBaseURI(), doc ) );
      } else {
        throw new HopException( "Unable to get document." );
      }
    } catch ( MalformedURLException mue ) {
      throw new HopException( mue );
    } catch ( AuthenticationException ae ) {
      // re-throw this. If not IOException seems to catch it
      throw ae;
    } catch ( IOException ioe ) {
      throw new HopException( ioe );
    }
  }
 
Example 3
Source Project: container   Source File: BPELPlanContext.java    License: 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 4
Source Project: container   Source File: BPELPlanContext.java    License: 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 5
Source Project: container   Source File: BPELPlanContext.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns the Services inside the given WSDL file which implement the given portType
 *
 * @param portType the portType to search with
 * @param wsdlFile the WSDL file to look in
 * @return a List of Service which implement the given portType
 * @throws WSDLException is thrown when the WSDLFactory to read the WSDL can't be initialized
 */
private List<Service> getServicesInWSDLFile(final Path wsdlFile, final QName portType) throws WSDLException {
    final List<Service> servicesInWsdl = new ArrayList<>();

    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 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())) {
                servicesInWsdl.add(service);
            }
        }
    }

    return servicesInWsdl;
}
 
Example 6
Source Project: carbon-apimgt   Source File: APIMWSDLReader.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns WSDL definition from a byte content of the WSDL
 *
 * @param wsdl byte content of the WSDL document
 * @return {@link Definition} - WSDL4j definition constructed form the wsdl
 * @throws APIManagementException
 */
public Definition getWSDLDefinitionFromByteContent(byte[] wsdl, boolean readDependencies) throws APIManagementException {
    try {
        WSDLReader wsdlReader = getWsdlFactoryInstance().newWSDLReader();
        // switch off the verbose mode
        wsdlReader.setFeature(JAVAX_WSDL_VERBOSE_MODE, false);
        wsdlReader.setFeature(JAVAX_WSDL_IMPORT_DOCUMENTS, false);

        if (!readDependencies) {
            if (wsdlReader instanceof WSDLReaderImpl) {
                ((WSDLReaderImpl) wsdlReader).setIgnoreSchemaContent(true);
            }
        }

        return wsdlReader.readWSDL(null, getSecuredParsedDocumentFromContent(wsdl));
    } catch (Exception e) {
        String msg = " Error occurs when updating WSDL ";
        throw new APIManagementException(msg, e);
    }
}
 
Example 7
Source Project: carbon-apimgt   Source File: APIMWSDLReader.java    License: Apache License 2.0 6 votes vote down vote up
@Deprecated
private org.apache.woden.wsdl20.Description readWSDL2File() throws APIManagementException, WSDLException {
    WSDLReader reader = getWsdlFactoryInstance().newWSDLReader();
    reader.setFeature(JAVAX_WSDL_VERBOSE_MODE, false);
    reader.setFeature(JAVAX_WSDL_IMPORT_DOCUMENTS, false);
    try {
        org.apache.woden.WSDLFactory wFactory = org.apache.woden.WSDLFactory.newInstance();
        org.apache.woden.WSDLReader wReader = wFactory.newWSDLReader();
        wReader.setFeature(org.apache.woden.WSDLReader.FEATURE_VALIDATION, true);
        Document document = getSecuredParsedDocumentFromURL(baseURI);
        Element domElement = document.getDocumentElement();
        WSDLSource wsdlSource = wReader.createWSDLSource();
        wsdlSource.setSource(domElement);
        return wReader.readWSDL(wsdlSource);
    } catch (org.apache.woden.WSDLException e) {
        String error = "Error occurred reading wsdl document.";
        log.error(error, e);
    }
    if (log.isDebugEnabled()) {
        log.debug("Reading  the WSDL. Base uri is " + baseURI);
    }
    return null;
}
 
Example 8
Source Project: carbon-apimgt   Source File: APIMWSDLReader.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Create the WSDL definition <javax.wsdl.Definition> from the baseURI of
 * the WSDL
 *
 * @return {@link Definition} - WSDL4j definition constructed form the wsdl
 *         original baseuri
 * @throws APIManagementException
 * @throws WSDLException
 */
   @Deprecated
private Definition readWSDLFile() throws APIManagementException, WSDLException {
	WSDLReader reader = getWsdlFactoryInstance().newWSDLReader();
	// switch off the verbose mode
	reader.setFeature(JAVAX_WSDL_VERBOSE_MODE, false);
	reader.setFeature(JAVAX_WSDL_IMPORT_DOCUMENTS, false);

	if (reader instanceof WSDLReaderImpl) {
		((WSDLReaderImpl) reader).setIgnoreSchemaContent(true);
	}

	if (log.isDebugEnabled()) {
		log.debug("Reading  the WSDL. Base uri is " + baseURI);
	}
	return reader.readWSDL(null, getSecuredParsedDocumentFromURL(baseURI));
   }
 
Example 9
Source Project: carbon-apimgt   Source File: WSDL11ProcessorImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean init(byte[] wsdlContent) throws APIMgtWSDLException {
    setMode(Mode.SINGLE);
    WSDLReader wsdlReader = getWsdlFactoryInstance().newWSDLReader();

    // switch off the verbose mode
    wsdlReader.setFeature(JAVAX_WSDL_VERBOSE_MODE, false);
    wsdlReader.setFeature(JAVAX_WSDL_IMPORT_DOCUMENTS, false);
    try {
        wsdlDefinition = wsdlReader.readWSDL(null, getSecuredParsedDocumentFromContent(wsdlContent));
        if (log.isDebugEnabled()) {
            log.debug("Successfully initialized an instance of " + this.getClass().getSimpleName()
                    + " with a single WSDL.");
        }
    } catch (WSDLException | APIManagementException e) {
        //This implementation class cannot process the WSDL.
        log.debug("Cannot process the WSDL by " + this.getClass().getName(), e);
        setError(new ErrorItem(ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getErrorMessage(), e.getMessage(),
                ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getErrorCode(),
                ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getHttpStatusCode()));
    }
    return !hasError;
}
 
Example 10
Source Project: carbon-apimgt   Source File: WSDL11ProcessorImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean init(URL url) throws APIMgtWSDLException {
    setMode(Mode.SINGLE);
    WSDLReader wsdlReader = getWsdlFactoryInstance().newWSDLReader();

    // switch off the verbose mode
    wsdlReader.setFeature(JAVAX_WSDL_VERBOSE_MODE, false);
    wsdlReader.setFeature(JAVAX_WSDL_IMPORT_DOCUMENTS, false);
    try {
        wsdlDefinition = wsdlReader.readWSDL(url.toString(), getSecuredParsedDocumentFromURL(url));
        if (log.isDebugEnabled()) {
            log.debug("Successfully initialized an instance of " + this.getClass().getSimpleName()
                    + " with a single WSDL.");
        }
    } catch (WSDLException | APIManagementException e) {
        //This implementation class cannot process the WSDL.
        log.debug("Cannot process the WSDL by " + this.getClass().getName(), e);
        setError(new ErrorItem(ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getErrorMessage(), e.getMessage(),
                ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getErrorCode(),
                ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getHttpStatusCode()));
    }
    return !hasError;
}
 
Example 11
Source Project: cxf   Source File: OASISCatalogTest.java    License: 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 12
Source Project: cxf   Source File: CXFServletTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGetWSDLWithMultiplePublishedEndpointUrl() throws Exception {
    ServletUnitClient client = newClient();
    client.setExceptionsThrownOnErrorStatus(true);

    WebRequest req = new GetMethodQueryWebRequest(CONTEXT_URL + "/services/greeter5?wsdl");

    WebResponse res = client.getResponse(req);
    assertEquals(200, res.getResponseCode());
    assertEquals("text/xml", res.getContentType());
    Document doc = StaxUtils.read(res.getInputStream());
    assertNotNull(doc);
    WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader();
    wsdlReader.setFeature("javax.wsdl.verbose", false);


    assertValid("//wsdl:service[@name='SOAPService']/wsdl:port[@name='SoapPort']/wsdlsoap:address[@location='"
        + "http://cxf.apache.org/publishedEndpointUrl1']", doc);
    assertValid("//wsdl:service[@name='SOAPService']/wsdl:port[@name='SoapPort1']/wsdlsoap:address[@location='"
        + "http://cxf.apache.org/publishedEndpointUrl2']", doc);

}
 
Example 13
Source Project: cxf   Source File: WSDLGenerationTester.java    License: 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 14
Source Project: cxf   Source File: AegisTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testAegisBasic() throws Exception {
    final String sei = org.apache.cxf.tools.fortest.aegis2ws.TestAegisSEI.class.getName();
    String[] args = new String[] {"-wsdl", "-o", output.getPath() + "/aegis.wsdl", "-verbose", "-d",
                                  output.getPath(), "-s", output.getPath(),
                                  "-frontend", "jaxws", "-databinding", "aegis",
                                  "-client", "-server", sei};
    File wsdlFile = null;
    wsdlFile = outputFile("aegis.wsdl");
    JavaToWS.main(args);
    assertTrue("wsdl is not generated", wsdlFile.exists());

    WSDLReader reader = WSDLFactory.newInstance().newWSDLReader();
    reader.setFeature("javax.wsdl.verbose", false);
    Definition def = reader.readWSDL(wsdlFile.toURI().toURL().toString());
    Document wsdl = WSDLFactory.newInstance().newWSDLWriter().getDocument(def);
    assertValid("//xsd:element[@type='ns0:Something']", wsdl);
}
 
Example 15
Source Project: cxf   Source File: WSDLServiceBuilderTest.java    License: 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 16
Source Project: iaf   Source File: WsdlXmlValidator.java    License: Apache License 2.0 6 votes vote down vote up
@IbisDoc({"the wsdl to read the xsd's from", " "})
public void setWsdl(String wsdl) throws ConfigurationException {
	this.wsdl = wsdl;
	WSDLReader reader  = FACTORY.newWSDLReader();
	reader.setFeature("javax.wsdl.verbose", false);
	reader.setFeature("javax.wsdl.importDocuments", true);
	ClassLoaderWSDLLocator wsdlLocator = new ClassLoaderWSDLLocator(getConfigurationClassLoader(), wsdl);
	URL url = wsdlLocator.getUrl();
	if (wsdlLocator.getUrl() == null) {
		throw new ConfigurationException("Could not find WSDL: " + wsdl);
	}
	try {
		definition = reader.readWSDL(wsdlLocator);
	} catch (WSDLException e) {
		throw new ConfigurationException("WSDLException reading WSDL or import from url: " + url, e);
	}
	if (wsdlLocator.getIOException() != null) {
		throw new ConfigurationException("IOException reading WSDL or import from url: " + url,
				wsdlLocator.getIOException());
	}
}
 
Example 17
Source Project: pentaho-kettle   Source File: Wsdl.java    License: Apache License 2.0 6 votes vote down vote up
private Definition readWsdl( WSDLReader wsdlReader, String uri, String username, String password ) throws WSDLException, KettleException, AuthenticationException {

    try {
      HTTPProtocol http = new HTTPProtocol();
      Document doc = XMLHandler.loadXMLString( http.get( wsdlURI.toString(), username, password ), true, false );
      if ( doc != null ) {
        return ( wsdlReader.readWSDL( doc.getBaseURI(), doc ) );
      } else {
        throw new KettleException( "Unable to get document." );
      }
    } catch ( MalformedURLException mue ) {
      throw new KettleException( mue );
    } catch ( AuthenticationException ae ) {
      // re-throw this. If not IOException seems to catch it
      throw ae;
    } catch ( IOException ioe ) {
      throw new KettleException( ioe );
    }
  }
 
Example 18
Source Project: apicurio-registry   Source File: WSDLReaderAccessor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected WSDLReader initialValue() {
    WSDLReader wsdlReader = null;
    try {
        WSDLFactory wsdlFactory = WSDLFactory.newInstance();
        wsdlReader = wsdlFactory.newWSDLReader();
    } catch (WSDLException e) {
        throw new RuntimeException(e);
    }
    return wsdlReader;
}
 
Example 19
Source Project: hop   Source File: Wsdl.java    License: 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 20
Source Project: hop   Source File: Wsdl.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Load and parse the WSDL file using the wsdlLocator.
 *
 * @param wsdlLocator A WSDLLocator instance.
 * @param username    to use for authentication
 * @param password    to use for authentication
 * @return wsdl Definition.
 * @throws WSDLException on error.
 */
private Definition parse(WSDLLocator wsdlLocator, String username, String password ) throws WSDLException,
  HopException, AuthenticationException {

  WSDLReader wsdlReader = getReader();
  try {

    return wsdlReader.readWSDL( wsdlLocator );
  } catch ( WSDLException we ) {
    readWsdl( wsdlReader, wsdlURI.toString(), username, password );
    return null;
  }
}
 
Example 21
Source Project: activiti6-boot2   Source File: WSDLImporter.java    License: 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 22
Source Project: syndesis   Source File: SoapApiModelParser.java    License: Apache License 2.0 5 votes vote down vote up
private static WSDLReader getWsdlReader() throws BusException {
    WSDLManager wsdlManager = new WSDLManagerImpl();
    // this is similar to what WSDLManager does,
    // but we need to read and store WSDL specification, so we create the reader ourselves
    final WSDLFactory wsdlFactory = wsdlManager.getWSDLFactory();
    final WSDLReader wsdlReader = wsdlFactory.newWSDLReader();
    wsdlReader.setFeature("javax.wsdl.verbose", false);
    wsdlReader.setFeature("javax.wsdl.importDocuments", true);
    wsdlReader.setExtensionRegistry(wsdlManager.getExtensionRegistry());
    return wsdlReader;
}
 
Example 23
Source Project: flowable-engine   Source File: WSDLImporter.java    License: 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 24
Source Project: jolie   Source File: WSDLCache.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
public synchronized Definition get( String url )
	throws WSDLException {
	Definition definition = cache.get( url );
	if( definition == null ) {
		WSDLReader reader = factory.newWSDLReader();
		reader.setFeature( "javax.wsdl.verbose", false );
		definition = reader.readWSDL( url );
		cache.put( url, definition );
	}
	return definition;
}
 
Example 25
Source Project: tesb-studio-se   Source File: WSDLUtils.java    License: 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 26
Source Project: tesb-studio-se   Source File: WSDLHelper.java    License: 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 27
Source Project: juddi   Source File: ReadWSDL.java    License: Apache License 2.0 5 votes vote down vote up
public Definition readWSDL(String fileName) throws WSDLException  {
               Definition wsdlDefinition = null;
               WSDLFactory factory = WSDLFactoryImpl.newInstance();
               WSDLReader reader = factory.newWSDLReader();

               try {
                       File f = new File(fileName);
                       URL url = null;
                       if (f.exists()) {
                               log.info(fileName + " as a local file doesn't exist.");
                               url = f.toURI().toURL();
                       } else {
                               url = ClassUtil.getResource(fileName, this.getClass());
                       }
                       if (url==null){
                               log.info(fileName + " as a class path resource doesn't exist.");
                               throw new WSDLException("null input", fileName);
                       }
                       URI uri = url.toURI();
                       WSDLLocator locator = new WSDLLocatorImpl(uri);
                       wsdlDefinition = reader.readWSDL(locator);
               } catch (URISyntaxException e) {
                       log.error(e.getMessage(), e);
               } catch (MalformedURLException ex) {
                       log.error(ex.getMessage(), ex);
               }
               return wsdlDefinition;
}
 
Example 28
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 29
Source Project: carbon-apimgt   Source File: APIMWSDLReader.java    License: Apache License 2.0 5 votes vote down vote up
/**
    * Update WSDL 1.0 service definitions saved in registry
    *
    * @param wsdl 	byte array of registry content
 * @param api 	API object
 * @return 		the OMElemnt of the new WSDL content
 * @throws APIManagementException
    */
public OMElement updateWSDL(byte[] wsdl, API api) throws APIManagementException {

	try {
		// Generate wsdl document from registry data
		WSDLReader wsdlReader = getWsdlFactoryInstance().newWSDLReader();
		// switch off the verbose mode
		wsdlReader.setFeature(JAVAX_WSDL_VERBOSE_MODE, false);
		wsdlReader.setFeature(JAVAX_WSDL_IMPORT_DOCUMENTS, false);

		if (wsdlReader instanceof WSDLReaderImpl) {
		    ((WSDLReaderImpl) wsdlReader).setIgnoreSchemaContent(true);
		}

		Definition wsdlDefinition = wsdlReader.readWSDL(null, getSecuredParsedDocumentFromContent(wsdl));

		// Update transports
		setServiceDefinition(wsdlDefinition, api);

		WSDLWriter writer = getWsdlFactoryInstance().newWSDLWriter();
		ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
		writer.writeWSDL(wsdlDefinition, byteArrayOutputStream);
		ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( byteArrayOutputStream.toByteArray());
		return APIUtil.buildOMElement(byteArrayInputStream);

	} catch (Exception e) {
		String msg = " Error occurs when updating WSDL ";
		log.error(msg);
		throw new APIManagementException(msg, e);
	}
}
 
Example 30
Source Project: carbon-apimgt   Source File: APIMWSDLReader.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Update WSDL 2.0 service definitions saved in registry
 *
 * @param wsdl 	byte array of wsdl definition saved in registry
 * @param api 	API object
 * @return 		the OMElemnt of the new WSDL content
 * @throws APIManagementException
 */
public OMElement updateWSDL2(byte[] wsdl, API api) throws APIManagementException {

	try {
		// Generate wsdl document from registry data
		DocumentBuilderFactory factory = getSecuredDocumentBuilder();
		DocumentBuilder builder = factory.newDocumentBuilder();
		org.apache.woden.WSDLFactory wsdlFactory = org.apache.woden.WSDLFactory.newInstance();
		org.apache.woden.WSDLReader reader = wsdlFactory.newWSDLReader();
		reader.setFeature(org.apache.woden.WSDLReader.FEATURE_VALIDATION, false);
		Document dom = builder.parse(new ByteArrayInputStream(wsdl));
		Element domElement = dom.getDocumentElement();
		WSDLSource wsdlSource = reader.createWSDLSource();
		wsdlSource.setSource(domElement);
		org.apache.woden.wsdl20.Description wsdlDefinition = reader.readWSDL(wsdlSource);

		// Update transports
		setServiceDefinitionForWSDL2(wsdlDefinition, api);

		org.apache.woden.WSDLWriter writer = org.apache.woden.WSDLFactory.newInstance().newWSDLWriter();
		ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
		writer.writeWSDL(wsdlDefinition.toElement(), byteArrayOutputStream);
		ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
		return APIUtil.buildOMElement(byteArrayInputStream);

	} catch (Exception e) {
		String msg = " Error occurs when updating WSDL ";
		log.error(msg, e);
		throw new APIManagementException(msg, e);
	}
}