Java Code Examples for javax.wsdl.xml.WSDLReader#readWSDL()

The following examples show how to use javax.wsdl.xml.WSDLReader#readWSDL() . 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: Wsdl.java    From hop with 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 File: WSDL11ProcessorImpl.java    From carbon-apimgt with 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 4
Source File: WSDL11ProcessorImpl.java    From carbon-apimgt with 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 5
Source File: APIMWSDLReader.java    From carbon-apimgt with 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 6
Source File: BPELPlanContext.java    From container with 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 7
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 8
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 9
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 10
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 11
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 12
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 13
Source File: ServiceWSDLBuilderTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void setupWSDL(String wsdlPath, boolean doXsdImports) throws Exception {
    String wsdlUrl = getClass().getResource(wsdlPath).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);
    destinationFactory = control.createMock(DestinationFactory.class);
    wsdlServiceBuilder = new WSDLServiceBuilder(bus, false);

    for (Service serv : CastUtils.cast(def.getServices().values(), Service.class)) {
        if (serv != null) {
            service = serv;
            break;
        }
    }
    EasyMock.expect(bus.getExtension(WSDLManager.class)).andReturn(new WSDLManagerImpl()).anyTimes();

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

    EasyMock.expect(destinationFactoryManager
                    .getDestinationFactory("http://schemas.xmlsoap.org/wsdl/soap/"))
        .andReturn(destinationFactory);

    control.replay();

    serviceInfo = wsdlServiceBuilder.buildServices(def, service).get(0);
    ServiceWSDLBuilder builder = new ServiceWSDLBuilder(bus, serviceInfo);
    builder.setUseSchemaImports(doXsdImports);
    builder.setBaseFileName("HelloWorld");
    newDef = builder.build(new HashMap<String, SchemaInfo>());
}
 
Example 14
Source File: WSDLManagerImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
public Definition getDefinition(final Element el) throws WSDLException {
    synchronized (definitionsMap) {
        if (definitionsMap.containsKey(el)) {
            return definitionsMap.get(el);
        }
    }
    final WSDLReader reader = factory.newWSDLReader();
    reader.setFeature("javax.wsdl.verbose", false);
    reader.setExtensionRegistry(registry);

    final Definition def;

    // This is needed to avoid security exceptions when running with a security manager
    if (System.getSecurityManager() == null) {
        def = reader.readWSDL("", el);
    } else {
        try {
            def = AccessController.doPrivileged(
                    (PrivilegedExceptionAction<Definition>) () -> reader.readWSDL("", el));
        } catch (PrivilegedActionException paex) {
            throw new WSDLException(WSDLException.PARSER_ERROR, paex.getMessage(), paex);
        }
    }

    synchronized (definitionsMap) {
        definitionsMap.put(el, def);
    }
    return def;
}
 
Example 15
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 16
Source File: WsdlValidator.java    From carbon-commons with Apache License 2.0 4 votes vote down vote up
private WSDLValidationInfo validaWSDLFromURI(InputStream stream) throws Exception {
       InputStream inputStream = null;
       URL url;

       try {
           String sanitizedXMLString = sanitizeXMLFileData(stream);
           Document doc = secureParseXML(sanitizedXMLString);
           url = loadXMLToFile(doc);
           inputStream = url.openStream();

           ResourceBundle rb = ResourceBundle.getBundle("validatewsdl");
           MessageGenerator messagegenerator = new MessageGenerator(rb);
           WSDLReader reader = WSDLFactory.newInstance().newWSDLReader();
           reader.setFeature("javax.wsdl.importDocuments", true);
           Definition wsdlDefinition = reader.readWSDL(url.toString());
           ControllerValidationInfo validateInfo = new ValidationInfoImpl(url.toString(),
                   messagegenerator);

           URIResolver uriResolver = new URIResolver();
           ((ValidationInfoImpl) validateInfo).setURIResolver(uriResolver);
           /*java.util.Hashtable attributes = new java.util.Hashtable();
            ((ValidationInfoImpl) validateInfo).setAttributes(attributes);*/

           WSDL11ValidationInfoImpl info = new WSDL11ValidationInfoImpl(validateInfo);
           info.setElementLocations(new java.util.Hashtable());
           WSDL11BasicValidator validator = new WSDL11BasicValidator();
//           registerExtensionValidators(validator.getClass().getClassLoader());
           /*validator.setResourceBundle(rb);*/
           IValidationMessage[] messages;

           ExtendedWSDL11ValidatorController wsdl11ValidatorController =
                   new ExtendedWSDL11ValidatorController();
           WSDLDocument[] wsdlDocs = wsdl11ValidatorController.readWSDLDocument(doc,
                   validateInfo.getFileURI(),
                   messagegenerator,
                   info);
           WSDLDocument document = wsdlDocs[0];
           List schema = document.getSchemas();
           for (Object aSchema : schema) {
               info.addSchema((XSModel) aSchema);
           }
           // Set the element locations table.
           info.setElementLocations(document.getElementLocations());
           validator.validate(wsdlDefinition, new ArrayList(), info);
           messages = validateInfo.getValidationMessages();

           WSDLValidationInfo wsdlValidationInfo = new WSDLValidationInfo();
           if (messages.length > 0) {
               wsdlValidationInfo.setStatus(WSDL_INVALID);
           } else {
               wsdlValidationInfo.setStatus(WSDL_VALID);
           }
           for (IValidationMessage message : messages) {
               String messageString =
                       "[" + message.getLine() + "][" + message.getColumn() + "]"
                               + message.getMessage();
               wsdlValidationInfo.addValidationMessage(messageString);
           }
           return wsdlValidationInfo;
       } finally {
           if (inputStream != null) {
               inputStream.close();
           }
       }
   }
 
Example 17
Source File: WSDL11ProcessorImpl.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
@Override
public boolean initPath(String path) throws APIMgtWSDLException {
    setMode(Mode.ARCHIVE);
    pathToDefinitionMap = new HashMap<>();
    wsdlArchiveExtractedPath = path;
    WSDLReader wsdlReader = getWsdlFactoryInstance().newWSDLReader();

    try {
        // switch off the verbose mode
        wsdlReader.setFeature(JAVAX_WSDL_VERBOSE_MODE, false);
        wsdlReader.setFeature(JAVAX_WSDL_IMPORT_DOCUMENTS, false);
        File folderToImport = new File(path);
        Collection<File> foundWSDLFiles = APIFileUtil.searchFilesWithMatchingExtension(folderToImport, "wsdl");
        if (log.isDebugEnabled()) {
            log.debug("Found " + foundWSDLFiles.size() + " WSDL file(s) in path " + path);
        }
        for (File file : foundWSDLFiles) {
            String absWSDLPath = file.getAbsolutePath();
            if (log.isDebugEnabled()) {
                log.debug("Processing WSDL file: " + absWSDLPath);
            }
            Definition definition = wsdlReader.readWSDL(path, getSecuredParsedDocumentFromPath(absWSDLPath));
            pathToDefinitionMap.put(absWSDLPath, definition);

            // set the first found WSDL as wsdlDefinition variable assuming that it is the root WSDL
            if (wsdlDefinition == null) {
                wsdlDefinition = definition;
            }
        }
        if (foundWSDLFiles.isEmpty()) {
            setError(ExceptionCodes.NO_WSDL_FOUND_IN_WSDL_ARCHIVE);
        }
        if (log.isDebugEnabled()) {
            log.debug("Successfully processed all WSDL files in path " + path);
        }
    } catch (WSDLException | APIManagementException e) {
        //This implementation class cannot process the WSDL. Continuing after setting canProcess = false
        log.debug(this.getClass().getName() + " was unable to process the WSDL Files for the path: " + path, 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 18
Source File: SimpleFileExporter.java    From container with Apache License 2.0 4 votes vote down vote up
private void rewriteServices(final Set<Mapping> servicesToRewrite, final WSDLWriter writer, final WSDLReader reader,
                             final List<Path> referencedFiles) throws WSDLException, IOException {

    LOG.debug("Rewriting service names:");
    LOG.debug("Files referenced:" + referencedFiles);
    LOG.debug("Services to rewrite:" + servicesToRewrite);

    for (final Mapping service : servicesToRewrite) {
        final QName serviceName = service.key;
        for (final Path file : referencedFiles) {
            if (!file.getFileName().toString().endsWith(".wsdl")) {
                continue;
            }

            final Definition def = reader.readWSDL(file.toAbsolutePath().toString());

            final List<QName> servicesToRemove = new ArrayList<>();

            boolean foundMatch = false;
            // fetch defined services
            for (final Object obj : def.getAllServices().values()) {
                final Service serviceA = (Service) obj;

                if (serviceName.equals(serviceA.getQName())) {
                    // found wsdl with service we have to rewrite
                    servicesToRemove.add(serviceA.getQName());

                    final Service newService = new ServiceImpl();

                    for (final Object o : serviceA.getPorts().values()) {
                        final Port port = (Port) o;
                        newService.addPort(port);
                    }

                    newService.setQName(service.val);

                    def.addService(newService);
                    foundMatch = true;
                }
            }

            if (foundMatch) {
                for (final QName serviceToRemove : servicesToRemove) {
                    def.removeService(serviceToRemove);
                }

                writer.writeWSDL(def, Files.newOutputStream(file));
                break;
            }
        }
    }
}
 
Example 19
Source File: PublishedEndpointUrlTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testPublishedEndpointUrl() throws Exception {

    Greeter implementor = new org.apache.hello_world_soap_http.GreeterImpl();
    String publishedEndpointUrl = "http://cxf.apache.org/publishedEndpointUrl";
    Bus bus = BusFactory.getDefaultBus();
    JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
    svrFactory.setBus(bus);
    svrFactory.setServiceClass(Greeter.class);
    svrFactory.setAddress("http://localhost:" + PORT + "/publishedEndpointUrl");
    svrFactory.setPublishedEndpointUrl(publishedEndpointUrl);
    svrFactory.setServiceBean(implementor);

    Server server = svrFactory.create();

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

    URL url = new URL(svrFactory.getAddress() + "?wsdl=1");
    HttpURLConnection connect = (HttpURLConnection)url.openConnection();
    assertEquals(500, connect.getResponseCode());

    Definition wsdl = wsdlReader.readWSDL(svrFactory.getAddress() + "?wsdl");
    assertNotNull(wsdl);

    Collection<Service> services = CastUtils.cast(wsdl.getAllServices().values());
    final String failMesg = "WSDL provided incorrect soap:address location";

    for (Service service : services) {
        Collection<Port> ports = CastUtils.cast(service.getPorts().values());
        for (Port port : ports) {
            List<?> extensions = port.getExtensibilityElements();
            for (Object extension : extensions) {
                String actualUrl = null;
                if (extension instanceof SOAP12Address) {
                    actualUrl = ((SOAP12Address)extension).getLocationURI();
                } else if (extension instanceof SOAPAddress) {
                    actualUrl = ((SOAPAddress)extension).getLocationURI();
                }

                //System.out.println("Checking url: " + actualUrl + " against " + publishedEndpointUrl);
                assertEquals(failMesg, publishedEndpointUrl, actualUrl);
            }
        }
    }
    server.stop();
    server.destroy();
    bus.shutdown(true);
}
 
Example 20
Source File: Wsdl.java    From hop with Apache License 2.0 4 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;
  }
}