javax.wsdl.Service Java Examples

The following examples show how to use javax.wsdl.Service. 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: WSDLImporter.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * Imports the service from the WSDL service definition
 */
protected WSService importService(Service service) {
  String name = service.getQName().getLocalPart();
  Port port = (Port) service.getPorts().values().iterator().next();
  String location = "";

  List extensionElements = port.getExtensibilityElements();
  for (Object extension : extensionElements) {
    if (extension instanceof SOAPAddress) {
      SOAPAddress address = (SOAPAddress) extension;
      location = address.getLocationURI();
    }
  }

  WSService wsService = new WSService(this.namespace + name, location, this.wsdlLocation);
  return wsService;
}
 
Example #2
Source File: WSDLDefinitionBuilderTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testBuildSimpleWSDL() throws Exception {
    String qname = "http://apache.org/hello_world_soap_http";
    String wsdlUrl = getClass().getResource("hello_world.wsdl").toString();

    WSDLDefinitionBuilder builder = new WSDLDefinitionBuilder(BusFactory.getDefaultBus());
    Definition def = builder.build(wsdlUrl);
    assertNotNull(def);

    Map<?, ?> services = def.getServices();
    assertNotNull(services);
    assertEquals(1, services.size());
    Service service = (Service)services.get(new QName(qname, "SOAPService"));
    assertNotNull(service);

    Map<?, ?> ports = service.getPorts();
    assertNotNull(ports);
    assertEquals(1, ports.size());
    Port port = service.getPort("SoapPort");
    assertNotNull(port);
}
 
Example #3
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 #4
Source File: ODEEndpointUpdater.java    From container with Apache License 2.0 6 votes vote down vote up
private boolean updateProvidedWSDLAddresses(final QName portType, final File wsdlFile) throws WSDLException {
    boolean changed = false;
    final Definition wsdlDef = getWsdlReader().readWSDL(wsdlFile.getAbsolutePath());
    for (final Object o : wsdlDef.getAllServices().values()) {
        final Service service = (Service) o;
        for (final Object obj : service.getPorts().values()) {
            final Port port = (Port) obj;
            if (port.getBinding().getPortType().getQName().equals(portType)) {
                if (changePortAddressWithBpelEngineEndpoints(service, port)) {
                    changed = true;
                }
            }
        }
    }
    try {
        // if we changed something, rewrite the the wsdl
        if (changed) {
            this.factory.newWSDLWriter().writeWSDL(wsdlDef, new FileOutputStream(wsdlFile));
        }
    } catch (final FileNotFoundException e) {
        LOG.debug("Couldn't locate wsdl file", e);
        changed = false;
    }
    return changed;
}
 
Example #5
Source File: ODEEndpointUpdater.java    From container with Apache License 2.0 6 votes vote down vote up
/**
 * Checks whether the given Port is defined inside the given WSDL Definition
 *
 * @param port    the Port to check with as QName
 * @param wsdlDef the WSDL Definition to check in
 * @return true if the Port is found inside the given WSDL Definition, else false
 */
private boolean checkIfPortIsInWsdlDef(final QName port, final Definition wsdlDef) {
    for (final Object serviceObj : wsdlDef.getServices().values()) {
        final Service service = (Service) serviceObj;
        for (final Object portObj : service.getPorts().values()) {
            final Port wsdlPort = (Port) portObj;
            final String namespace = wsdlDef.getTargetNamespace();
            final String name = wsdlPort.getName();
            LOG.debug("Checking if port {} matches port with name {} and namespace {} ",
                port.toString(), name, namespace);
            if (name.equals(port.getLocalPart()) && namespace.equals(port.getNamespaceURI())) {
                return true;
            }
        }
    }
    return false;
}
 
Example #6
Source File: WSDLDefinitionBuilderTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testBuildImportedWSDLSpacesInPath() throws Exception {
    WSDLDefinitionBuilder builder = new WSDLDefinitionBuilder(BusFactory.getDefaultBus());
    String wsdlUrl = getClass().getResource("/folder with spaces/import_test.wsdl").toString();

    Definition def = builder.build(wsdlUrl);
    assertNotNull(def);

    Map<?, ?> services = def.getServices();
    assertNotNull(services);
    assertEquals(1, services.size());

    String serviceQName = "urn:S1importS2S3/resources/wsdl/S1importsS2S3Test1";
    Service service = (Service)services.get(new QName(serviceQName, "S1importsS2S3TestService"));
    assertNotNull(service);

    Map<?, ?> ports = service.getPorts();
    assertNotNull(ports);
    assertEquals(1, ports.size());
    Port port = service.getPort("S1importsS2S3TestPort");
    assertNotNull(port);
}
 
Example #7
Source File: ManagementBusInvocationPluginSoapHttp.java    From container with Apache License 2.0 6 votes vote down vote up
private String getPortName(Definition wsdl, BindingOperation operation) {
    Binding binding = null;
    final Map<QName, ?> bindings = wsdl.getBindings();
    for (Map.Entry<QName, ?> entry : bindings.entrySet()) {
        Binding examined = wsdl.getBinding((QName) entry.getKey());
        if (examined.getBindingOperations().contains(operation)) {
            binding = examined;
            break;
        }
    }
    Map<QName, Service> services = wsdl.getServices();
    for (Service service : services.values()) {
        Map<QName, Port> ports = service.getPorts();
        for (Port port : ports.values()) {
            if (port.getBinding().equals(binding)) {
                return port.getName();
            }
        }
    }
    return "";
}
 
Example #8
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 #9
Source File: WSDL2UDDI.java    From juddi with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a business service based off of a WSDL definition<Br>No
 * changes are made to the UDDI endpoints using this method
 * <br>
 * Example Code:
 * <pre>
 * URL url = new URL("http://graphical.weather.gov/xml/SOAP_server/ndfdXMLserver.php?wsdl");
 * String domain = url.getHost();
 * ReadWSDL rw = new ReadWSDL();
 * Definition wsdlDefinition = rw.readWSDL(url);
 * properties.put("keyDomain", domain);
 * properties.put("businessName", domain);
 * properties.put("serverName", url.getHost());
 * properties.put("serverPort", url.getPort());
 * wsdlURL = wsdlDefinition.getDocumentBaseURI();
 * WSDL2UDDI wsdl2UDDI = new WSDL2UDDI(null, new URLLocalizerDefaultImpl(), properties);
 * BusinessServices businessServices = wsdl2UDDI.createBusinessServices(wsdlDefinition);
 * </pre>
 *
 * @param wsdlDefinition must not be null
 * @return a business service
 * @throws MalformedURLException
 * @throws IllegalArgumentException if the wsdlDefinition is null
 */
public BusinessServices createBusinessServices(Definition wsdlDefinition) throws MalformedURLException {
        if (wsdlDefinition == null) {
                throw new IllegalArgumentException();
        }
        BusinessServices businessServices = new BusinessServices();
        for (Object serviceName : wsdlDefinition.getAllServices().keySet()) {
                QName serviceQName = (QName) serviceName;
                Service service = wsdlDefinition.getService(serviceQName);
                BusinessService businessService = createBusinessService(serviceQName, wsdlDefinition);
    //service.getExtensibilityElements().
                //add the bindingTemplates
                URL serviceUrl = null;
                if (service.getPorts() != null && service.getPorts().size() > 0) {
                        businessService.setBindingTemplates(new BindingTemplates());
                        for (Object portName : service.getPorts().keySet()) {
                                BindingTemplate bindingTemplate = createWSDLBinding(serviceQName, (String) portName, serviceUrl, wsdlDefinition);
                                businessService.getBindingTemplates().getBindingTemplate().add(bindingTemplate);
                        }
                }
                businessServices.getBusinessService().add(businessService);
        }

        return businessServices;
}
 
Example #10
Source File: WSDL2UDDI.java    From juddi with Apache License 2.0 6 votes vote down vote up
public BusinessServices registerBusinessServices(Definition wsdlDefinition) throws RemoteException, ConfigurationException, TransportException, WSDLException, MalformedURLException {

                BusinessServices businessServices = new BusinessServices();

                for (Object serviceName : wsdlDefinition.getAllServices().keySet()) {
                        QName serviceQName = (QName) serviceName;
                        Service service = wsdlDefinition.getService(serviceQName);
                        BusinessService businessService = null;
                        //add service
                        URL serviceUrl = null;
                        if (service.getPorts() != null && service.getPorts().size() > 0) {
                                for (Object portName : service.getPorts().keySet()) {
                                        businessService = registerBusinessService(serviceQName, (String) portName, serviceUrl, wsdlDefinition).getBusinessService();
                                }
                        }
                        if (businessService != null) {
                                businessServices.getBusinessService().add(businessService);
                        }
                }

                return businessServices;

        }
 
Example #11
Source File: WSDLGetUtils.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected void updatePublishedEndpointUrl(String publishingUrl,
                                          Definition def,
                                          QName name) {
    Collection<Service> services = CastUtils.cast(def.getAllServices().values());
    for (Service service : services) {
        Collection<Port> ports = CastUtils.cast(service.getPorts().values());
        if (ports.isEmpty()) {
            continue;
        }

        if (name == null) {
            setSoapAddressLocationOn(ports.iterator().next(), publishingUrl);
            break; // only update the first port since we don't target any specific port
        }
        for (Port port : ports) {
            if (name.getLocalPart().equals(port.getName())) {
                setSoapAddressLocationOn(port, publishingUrl);
            }
        }
    }
}
 
Example #12
Source File: JavaToProcessorTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimpleClass() throws Exception {
    env.put(ToolConstants.CFG_OUTPUTFILE, output.getPath() + "/doc_wrapped_bare.wsdl");
    env.put(ToolConstants.CFG_CLASSNAME, "org.apache.cxf.tools.fortest.simple.Hello");
    processor.setEnvironment(env);
    processor.process();

    File wsdlFile = new File(output, "doc_wrapped_bare.wsdl");
    assertTrue("Fail to generate wsdl file: " + wsdlFile.toString(), wsdlFile.exists());

    String tns = "http://simple.fortest.tools.cxf.apache.org/";

    Definition def = getDefinition(wsdlFile.getPath());
    assertNotNull(def);
    Service wsdlService = def.getService(new QName(tns, "Hello"));
    assertNotNull("Generate WSDL Service Error", wsdlService);
}
 
Example #13
Source File: APIMWSDLReader.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
private void setServiceDefinitionForWSDL2(org.apache.woden.wsdl20.Description definition, API api)
        throws APIManagementException {
    org.apache.woden.wsdl20.Service[] serviceMap = definition.getServices();
    // URL addressURI;
    try {
        for (org.apache.woden.wsdl20.Service svc : serviceMap) {
            Endpoint[] portMap = svc.getEndpoints();
            for (Endpoint endpoint : portMap) {
                EndpointElement element = endpoint.toElement();
                // addressURI = endpoint.getAddress().toURL();
                // if (addressURI == null) {
                //    break;
                // } else {
                String endpointTransport = determineURLTransport(endpoint.getAddress().getScheme(),
                                                                 api.getTransports());
                setAddressUrl(element, new URI(APIUtil.getGatewayendpoint(endpointTransport) +
                                               api.getContext() + '/' + api.getId().getVersion()));
                //}
            }
        }
    } catch (Exception e) {
        String errorMsg = "Error occurred while getting the wsdl address location";
        log.error(errorMsg, e);
        throw new APIManagementException(errorMsg, e);
    }
}
 
Example #14
Source File: WSDL11ProcessorImpl.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
/**
 * Get endpoints defined in the provided WSDL definition.
 *
 * @param definition WSDL Definition
 * @return a Map of endpoint names and their URIs.
 * @throws APIMgtWSDLException if error occurs while reading endpoints
 */
private Map<String, String> getEndpoints(Definition definition) throws APIMgtWSDLException {
    Map serviceMap = definition.getAllServices();
    Iterator serviceItr = serviceMap.entrySet().iterator();
    Map<String, String> serviceEndpointMap = new HashMap<>();
    while (serviceItr.hasNext()) {
        Map.Entry svcEntry = (Map.Entry) serviceItr.next();
        Service svc = (Service) svcEntry.getValue();
        Map portMap = svc.getPorts();
        for (Object o : portMap.entrySet()) {
            Map.Entry portEntry = (Map.Entry) o;
            Port port = (Port) portEntry.getValue();
            List extensibilityElementList = port.getExtensibilityElements();
            for (Object extensibilityElement : extensibilityElementList) {
                String addressURI = getAddressUrl(extensibilityElement);
                serviceEndpointMap.put(port.getName(), addressURI);
            }
        }
    }
    return serviceEndpointMap;
}
 
Example #15
Source File: WSDLDocCreator.java    From jolie with GNU Lesser General Public License v2.1 6 votes vote down vote up
public Service createService( Definition localdef, String serviceName, Binding bind, String mySOAPAddress ) {
	Port p = localDef.createPort();
	p.setName( serviceName + "Port" );
	try {

		SOAPAddress soapAddress = (SOAPAddress) extensionRegistry.createExtension( Port.class,
			new QName( NameSpacesEnum.SOAP.getNameSpaceURI(), "address" ) );
		soapAddress.setLocationURI( mySOAPAddress );
		p.addExtensibilityElement( soapAddress );
	} catch( WSDLException ex ) {
		ex.printStackTrace();
	}
	p.setBinding( bind );
	Service s = new ServiceImpl();
	QName serviceQName = new QName( serviceName );
	s.setQName( serviceQName );
	s.addPort( p );
	localDef.addService( s );
	return s;
}
 
Example #16
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 #17
Source File: WSDLManagerImplTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testBuildSimpleWSDL() throws Exception {
    String qname = "http://apache.org/hello_world_soap_http";
    String wsdlUrl = getClass().getResource("hello_world.wsdl").toString();

    WSDLManager builder = new WSDLManagerImpl();
    Definition def = builder.getDefinition(wsdlUrl);
    assertNotNull(def);

    Map<?, ?> services = def.getServices();
    assertNotNull(services);
    assertEquals(1, services.size());
    Service service = (Service)services.get(new QName(qname, "SOAPService"));
    assertNotNull(service);

    Map<?, ?> ports = service.getPorts();
    assertNotNull(ports);
    assertEquals(1, ports.size());
    Port port = service.getPort("SoapPort");
    assertNotNull(port);
}
 
Example #18
Source File: SoapProtocol.java    From jolie with GNU Lesser General Public License v2.1 6 votes vote down vote up
private Port getWSDLPort()
	throws IOException {
	Port port = wsdlPort;
	if( port == null && hasParameter( "wsdl" ) && getParameterFirstValue( "wsdl" ).hasChildren( "port" ) ) {
		String portName = getParameterFirstValue( "wsdl" ).getFirstChild( "port" ).strValue();
		Definition definition = getWSDLDefinition();
		if( definition != null ) {
			Map< QName, Service > services = definition.getServices();
			Iterator< Entry< QName, Service > > it = services.entrySet().iterator();
			while( port == null && it.hasNext() ) {
				port = it.next().getValue().getPort( portName );
			}
		}
		if( port != null ) {
			wsdlPort = port;
		}
	}
	return port;
}
 
Example #19
Source File: WSDLImporter.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Imports the service from the WSDL service definition
 */
protected WSService importService(Service service) {
    String name = service.getQName().getLocalPart();
    Port port = (Port) service.getPorts().values().iterator().next();
    String location = "";

    List extensionElements = port.getExtensibilityElements();
    for (Object extension : extensionElements) {
        if (extension instanceof SOAPAddress) {
            SOAPAddress address = (SOAPAddress) extension;
            location = address.getLocationURI();
        }
    }

    WSService wsService = new WSService(this.namespace + name, location, this.wsdlLocation);
    return wsService;
}
 
Example #20
Source File: WSDLImporter.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Imports services and operations from the WSDL definition
 */
protected void importServicesAndOperations(Definition definition) {
    for (Object serviceObject : definition.getServices().values()) {
        Service service = (Service) serviceObject;
        WSService wsService = this.importService(service);
        this.wsServices.put(this.namespace + wsService.getName(), wsService);

        Port port = (Port) service.getPorts().values().iterator().next();
        for (Object bindOperationObject : port.getBinding().getBindingOperations()) {
            BindingOperation bindOperation = (BindingOperation) bindOperationObject;
            WSOperation operation = this.processOperation(bindOperation.getOperation(), wsService);
            wsService.addOperation(operation);

            this.wsOperations.put(this.namespace + operation.getName(), operation);
        }
    }
}
 
Example #21
Source File: WSDLRefValidator.java    From cxf with Apache License 2.0 6 votes vote down vote up
private Map<QName, XNode> getBindings(Service service) {
    Map<QName, XNode> bindings = new HashMap<>();

    if (service.getPorts().values().isEmpty()) {
        throw new ToolException("Service " + service.getQName() + " does not contain any usable ports");
    }
    Collection<Port> ports = CastUtils.cast(service.getPorts().values());
    for (Port port : ports) {
        Binding binding = port.getBinding();
        bindings.put(binding.getQName(), getXNode(service, port));
        if (WSDLConstants.NS_WSDL11.equals(binding.getQName().getNamespaceURI())) {
            throw new ToolException("Binding "
                                    + binding.getQName().getLocalPart()
                                    + " namespace set improperly.");
        }
    }

    return bindings;
}
 
Example #22
Source File: WSDLImporter.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * Imports services and operations from the WSDL definition
 */
protected void importServicesAndOperations(Definition definition) {
  for (Object serviceObject : definition.getServices().values()) {
    Service service = (Service) serviceObject;
    WSService wsService = this.importService(service);
    this.wsServices.put(this.namespace + wsService.getName(), wsService);

    Port port = (Port) service.getPorts().values().iterator().next();
    for (Object bindOperationObject : port.getBinding().getBindingOperations()) {
      BindingOperation bindOperation = (BindingOperation) bindOperationObject;
      WSOperation operation = this.processOperation(bindOperation.getOperation(), wsService);
      wsService.addOperation(operation);

      this.wsOperations.put(this.namespace + operation.getName(), operation);
    }
  }
}
 
Example #23
Source File: JAXBExtensionHelperTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void checkTestExt() throws Exception {
    Service s = wsdlDefinition.getService(new QName("http://cxf.apache.org/test/hello_world",
        "HelloWorldService"));
    Port p = s.getPort("HelloWorldPort");
    List<?> extPortList = p.getExtensibilityElements();

    TestPolicyType tp = null;
    AnotherPolicyType ap = null;
    for (Object ext : extPortList) {
        if (ext instanceof TestPolicyType) {
            tp = (TestPolicyType) ext;
        } else if (ext instanceof AnotherPolicyType) {
            ap = (AnotherPolicyType) ext;
        } else if (ext instanceof UnknownExtensibilityElement) {
            UnknownExtensibilityElement e = (UnknownExtensibilityElement)ext;
            System.out.println(e.getElementType());
        }
    }
    assertNotNull("Could not find extension element TestPolicyType", tp);
    assertNotNull("Could not find extension element AnotherPolicyType", ap);

    assertEquals("Unexpected value for TestPolicyType intAttr", 30, tp.getIntAttr());
    assertEquals("Unexpected value for TestPolicyType stringAttr", "hello", tp.getStringAttr());
    assertTrue("Unexpected value for AnotherPolicyType floatAttr",
               Math.abs(0.1F - ap.getFloatAttr()) < 0.5E-5);
}
 
Example #24
Source File: WSDLToCorbaBindingTypeTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetCorbaAddressFile() throws Exception {

    try {
        URI fileName = getClass().getResource("/wsdl/datetime.wsdl").toURI();
        generator.setWsdlFile(new File(fileName).getAbsolutePath());
        generator.addInterfaceName("BasePortType");

        Definition model = generator.generateCORBABinding();
        QName name = new QName("http://schemas.apache.org/idl/datetime.idl",
                                 "BaseCORBAService", "tns");
        Service service = model.getService(name);
        Port port = service.getPort("BaseCORBAPort");
        AddressType addressType = (AddressType)port.getExtensibilityElements().get(0);
        String address = addressType.getLocation();
        assertEquals("file:./Base.ref", address);

        URL idl = getClass().getResource("/wsdl/addressfile.txt");
        String filename = new File(idl.toURI()).getAbsolutePath();
        generator.setAddressFile(filename);
        model = generator.generateCORBABinding();
        service = model.getService(name);
        port = service.getPort("BaseCORBAPort");
        addressType = (AddressType)port.getExtensibilityElements().get(0);
        address = addressType.getLocation();
        assertEquals("corbaloc::localhost:60000/hw", address);
    } finally {
        new File("datetime-corba.wsdl").deleteOnExit();
    }
}
 
Example #25
Source File: WSDLToCorbaBindingTypeTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetCorbaAddress() throws Exception {

    try {
        String fileName = getClass().getResource("/wsdl/datetime.wsdl").toString();
        generator.setWsdlFile(fileName);
        generator.addInterfaceName("BasePortType");

        Definition model = generator.generateCORBABinding();
        QName name = new QName("http://schemas.apache.org/idl/datetime.idl",
                                 "BaseCORBAService", "tns");
        Service service = model.getService(name);
        Port port = service.getPort("BaseCORBAPort");
        AddressType addressType = (AddressType)port.getExtensibilityElements().get(0);
        String address = addressType.getLocation();
        assertEquals("file:./Base.ref", address);

        generator.setAddress("corbaloc::localhost:40000/hw");
        model = generator.generateCORBABinding();
        service = model.getService(name);
        port = service.getPort("BaseCORBAPort");
        addressType = (AddressType)port.getExtensibilityElements().get(0);
        address = addressType.getLocation();
        assertEquals("corbaloc::localhost:40000/hw", address);
    } finally {
        new File("datetime-corba.wsdl").deleteOnExit();
    }
}
 
Example #26
Source File: WSDLRefValidator.java    From cxf with Apache License 2.0 5 votes vote down vote up
private XNode getXNode(Service service) {
    XDef xdef = new XDef();
    xdef.setTargetNamespace(service.getQName().getNamespaceURI());

    XService sNode = new XService();
    sNode.setName(service.getQName().getLocalPart());
    sNode.setParentNode(xdef);
    return sNode;
}
 
Example #27
Source File: WSDLASTVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Definition getPhysicalDefinition(Definition logicalDef, boolean schemaOnly)
    throws WSDLException, JAXBException {

    Definition def = null;
    if (schemaOnly) {
        def = logicalDef;
    } else {
        def = manager.createWSDLDefinition(targetNamespace);
    }

    Collection<String> namespaces = CastUtils.cast(definition.getNamespaces().values());
    for (String namespace : namespaces) {
        String prefix = definition.getPrefix(namespace);
        def.addNamespace(prefix, namespace);
    }
    Collection<Binding> bindings = CastUtils.cast(definition.getAllBindings().values());
    for (Binding binding : bindings) {
        def.addBinding(binding);
    }
    Collection<Service> services = CastUtils.cast(definition.getAllServices().values());
    for (Service service : services) {
        def.addService(service);
    }
    Collection<ExtensibilityElement> extns = CastUtils.cast(definition.getExtensibilityElements());
    for (ExtensibilityElement ext : extns) {
        def.addExtensibilityElement(ext);
    }

    def.setExtensionRegistry(definition.getExtensionRegistry());

    return def;
}
 
Example #28
Source File: JAXWSDefinitionBuilder.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void registerJaxwsExtension(ExtensionRegistry registry) {
    registerJAXWSBinding(registry, Definition.class);
    registerJAXWSBinding(registry, Service.class);
    registerJAXWSBinding(registry, Fault.class);
    registerJAXWSBinding(registry, PortType.class);
    registerJAXWSBinding(registry, Port.class);
    registerJAXWSBinding(registry, Operation.class);
    registerJAXWSBinding(registry, Binding.class);
    registerJAXWSBinding(registry, BindingOperation.class);
}
 
Example #29
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 #30
Source File: WSDLServiceBuilder.java    From cxf with Apache License 2.0 5 votes vote down vote up
private List<ServiceInfo> buildServices(Definition d,
                                        QName name,
                                        QName endpointName,
                                        DescriptionInfo description) {
    Service service = d.getService(name);
    if (service == null) {
        org.apache.cxf.common.i18n.Message msg =
            new org.apache.cxf.common.i18n.Message("MISSING_SERVICE",
                                                   LOG,
                                                   name);
        throw new WSDLRuntimeException(msg);
    }
    return buildServices(d, service, endpointName, description);
}