Java Code Examples for javax.wsdl.Service#getPort()

The following examples show how to use javax.wsdl.Service#getPort() . 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: 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 2
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 3
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 4
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 5
Source File: SoapApiModelParser.java    From syndesis with Apache License 2.0 5 votes vote down vote up
private static Port getPort(Service service, String portName) throws ParserException {
    final Port port = service.getPort(portName);
    if (port == null) {
        throw new ParserException("Missing Port " + portName, "portName");
    }
    return port;
}
 
Example 6
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 7
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 8
Source File: WSDLDefinitionBuilderTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testBuildImportedWSDL() throws Exception {
    String wsdlUrl = getClass().getResource("hello_world_services.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());

    String serviceQName = "http://apache.org/hello_world/services";
    Service service = (Service)services.get(new QName(serviceQName, "SOAPService"));
    assertNotNull(service);

    Map<?, ?> ports = service.getPorts();
    assertNotNull(ports);
    assertEquals(1, ports.size());
    Port port = service.getPort("SoapPort");
    assertNotNull(port);

    Binding binding = port.getBinding();
    assertNotNull(binding);
    QName bindingQName = new QName("http://apache.org/hello_world/bindings", "SOAPBinding");
    assertEquals(bindingQName, binding.getQName());
    PortType portType = binding.getPortType();
    assertNotNull(portType);
    QName portTypeQName = new QName("http://apache.org/hello_world", "Greeter");
    assertEquals(portTypeQName, portType.getQName());
    Operation op1 = portType.getOperation("sayHi", "sayHiRequest", "sayHiResponse");
    assertNotNull(op1);
    QName messageQName = new QName("http://apache.org/hello_world/messages", "sayHiRequest");
    assertEquals(messageQName, op1.getInput().getMessage().getQName());

    Part part = op1.getInput().getMessage().getPart("in");
    assertNotNull(part);
    assertEquals(new QName("http://apache.org/hello_world/types", "sayHi"), part.getElementName());
}
 
Example 9
Source File: WSDLManagerImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testBuildImportedWSDL() throws Exception {
    String wsdlUrl = getClass().getResource("hello_world_services.wsdl").toString();

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

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

    String serviceQName = "http://apache.org/hello_world/services";
    Service service = (Service)services.get(new QName(serviceQName, "SOAPService"));
    assertNotNull(service);

    Map<?, ?> ports = service.getPorts();
    assertNotNull(ports);
    assertEquals(1, ports.size());
    Port port = service.getPort("SoapPort");
    assertNotNull(port);

    Binding binding = port.getBinding();
    assertNotNull(binding);
    QName bindingQName = new QName("http://apache.org/hello_world/bindings", "SOAPBinding");
    assertEquals(bindingQName, binding.getQName());
    PortType portType = binding.getPortType();
    assertNotNull(portType);
    QName portTypeQName = new QName("http://apache.org/hello_world", "Greeter");
    assertEquals(portTypeQName, portType.getQName());
    Operation op1 = portType.getOperation("sayHi", "sayHiRequest", "sayHiResponse");
    assertNotNull(op1);
    QName messageQName = new QName("http://apache.org/hello_world/messages", "sayHiRequest");
    assertEquals(messageQName, op1.getInput().getMessage().getQName());

    Part part = op1.getInput().getMessage().getPart("in");
    assertNotNull(part);
    assertEquals(new QName("http://apache.org/hello_world/types", "sayHi"), part.getElementName());
}
 
Example 10
Source File: SoapApiConnectorGenerator.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private Connector createConnector(ConnectorTemplate connectorTemplate, ConnectorSettings connectorSettings,
                                  SoapApiModelInfo modelInfo) {

    final Definition definition = modelInfo.getModel().
            orElseThrow(() -> new IllegalArgumentException("Unable to parse WSDL, or missing SOAP Service and Port in specification"));

    // get service and port
    final Map<String, String> configuredProperties = connectorSettings.getConfiguredProperties();
    final QName serviceName = getService(modelInfo, configuredProperties)
            .orElseThrow(() -> new IllegalArgumentException("Missing property " + SERVICE_NAME_PROPERTY));
    final String portName = getPortName(modelInfo, configuredProperties)
            .orElseThrow(() -> new IllegalArgumentException("Missing property " + PORT_NAME_PROPERTY));

    // get SOAP Version from Service and Port
    final Service service = definition.getService(serviceName);
    final Port port = service.getPort(portName);
    final Binding binding = port.getBinding();
    double soapVersion = 1.1;
    for (Object element : binding.getExtensibilityElements()) {
        if (element instanceof SOAP12Binding) {
            soapVersion = 1.2;
            break;
        }
    }

    // add actions
    try {

        final Connector configuredConnector = configuredConnector(connectorTemplate, connectorSettings);

        final List<ConnectorAction> actions = SoapApiModelParser.parseActions(definition,
                serviceName, new QName(serviceName.getNamespaceURI(), portName),
                configuredConnector.getId().get());
        final ActionsSummary actionsSummary = SoapApiModelParser.parseActionsSummary(definition, serviceName, portName);

        final Connector.Builder builder = new Connector.Builder()
                .createFrom(configuredConnector)
                .putConfiguredProperty(SOAP_VERSION_PROPERTY, String.valueOf(soapVersion))
                .addAllActions(actions)
                .actionsSummary(actionsSummary);

        return builder.build();

    } catch (ParserException e) {
        throw new IllegalArgumentException("Error getting actions from WSDL: " + e.getMessage(), e);
    }
}
 
Example 11
Source File: BPEL2UDDI.java    From juddi with Apache License 2.0 4 votes vote down vote up
public BindingTemplate createBPELBinding(QName serviceName, String portName, URL serviceUrl, Definition wsdlDefinition) {
	
   	BindingTemplate bindingTemplate = new BindingTemplate();
	// Set BusinessService Key
	bindingTemplate.setServiceKey(UDDIKeyConvention.getServiceKey(properties, serviceName.getLocalPart()));
	// Set Binding Key
	String bindingKey = UDDIKeyConvention.getBindingKey(properties, serviceName, portName, serviceUrl);
	bindingTemplate.setBindingKey(bindingKey);
	// Set AccessPoint
	AccessPoint accessPoint = new AccessPoint();
	accessPoint.setUseType(AccessPointType.END_POINT.toString());
	accessPoint.setValue(urlLocalizer.rewrite(serviceUrl));
	bindingTemplate.setAccessPoint(accessPoint);
	
	Service service =  wsdlDefinition.getService(serviceName);
	
	if (service!=null) {
		TModelInstanceDetails tModelInstanceDetails = new TModelInstanceDetails();
		
		Port port = service.getPort(portName);
		if (port!=null) {
			Binding binding = port.getBinding();
			// Set the Binding Description
			String bindingDescription = properties.getProperty(Property.BINDING_DESCRIPTION, Property.DEFAULT_BINDING_DESCRIPTION);
			// Override with the service description from the WSDL if present
			Element docElement = binding.getDocumentationElement();
			if (docElement!=null && docElement.getTextContent()!=null) {
				bindingDescription = docElement.getTextContent();
			}
			
			bindingTemplate.getDescription().addAll(Common2UDDI.mapDescription(bindingDescription, lang));
			
			// reference wsdl:binding tModel
			TModelInstanceInfo tModelInstanceInfoBinding = new TModelInstanceInfo();
			tModelInstanceInfoBinding.setTModelKey(keyDomainURI + binding.getQName().getLocalPart());
			InstanceDetails instanceDetails = new InstanceDetails();
			instanceDetails.setInstanceParms(portName);  
			tModelInstanceInfoBinding.setInstanceDetails(instanceDetails);
			
			tModelInstanceInfoBinding.getDescription().addAll(Common2UDDI.mapDescription("The wsdl:binding that this wsdl:port implements. " + bindingDescription +
					" The instanceParms specifies the port local name.", lang));
			tModelInstanceDetails.getTModelInstanceInfo().add(tModelInstanceInfoBinding);
			
			// reference wsdl:portType tModel
			PortType portType = binding.getPortType();
			TModelInstanceInfo tModelInstanceInfoPortType = new TModelInstanceInfo();
			tModelInstanceInfoPortType.setTModelKey(keyDomainURI + portType.getQName().getLocalPart());
			String portTypeDescription = "";
			docElement = portType.getDocumentationElement();
			if (docElement!=null && docElement.getTextContent()!=null) {
				portTypeDescription = docElement.getTextContent();
			}
			
			tModelInstanceInfoPortType.getDescription().addAll(Common2UDDI.mapDescription("The wsdl:portType that this wsdl:port implements." + portTypeDescription, lang));
			tModelInstanceDetails.getTModelInstanceInfo().add(tModelInstanceInfoPortType);
			
			//reference bpel:process tModel
			TModelInstanceInfo tModelInstanceInfoBPEL = new TModelInstanceInfo();
			tModelInstanceInfoBPEL.setTModelKey(keyDomainURI + service.getQName().getLocalPart() + "Process");
			
			// Description
			String serviceDescription = properties.getProperty(Property.SERVICE_DESCRIPTION, Property.DEFAULT_SERVICE_DESCRIPTION);
			// Override with the service description from the WSDL if present
			docElement = wsdlDefinition.getService(serviceName).getDocumentationElement();
			if (docElement!=null && docElement.getTextContent()!=null) {
				serviceDescription = docElement.getTextContent();
			}
			
			tModelInstanceInfoBPEL.getDescription().addAll(Common2UDDI.mapDescription("The bpel:process this wsdl:port supports." + serviceDescription, lang));
			tModelInstanceDetails.getTModelInstanceInfo().add(tModelInstanceInfoBPEL);
			
			bindingTemplate.setTModelInstanceDetails(tModelInstanceDetails);
		} else {
			log.error("Could not find Port with portName: " + portName);
		}
	} else {
		log.error("Could not find Service with serviceName: " + serviceName.getLocalPart());
	}
	
	if (log.isDebugEnabled()) {
   		log.debug(new PrintUDDI<BindingTemplate>().print(bindingTemplate));
   	}
	
	return bindingTemplate;
}
 
Example 12
Source File: JavaToProcessorTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testDocLitUseClassPathFlag() throws Exception {
    File classFile = new java.io.File(output.getCanonicalPath() + "/classes");
    classFile.mkdir();

    if (JavaUtils.isJava9Compatible()) {
        System.setProperty("org.apache.cxf.common.util.Compiler-fork", "true");
        String java9PlusFolder = output.getParent() + java.io.File.separator + "java9";
        System.setProperty("java.class.path", System.getProperty("java.class.path")
                           + java.io.File.pathSeparator + java9PlusFolder + java.io.File.separator + "*");
    }

    env.put(ToolConstants.CFG_COMPILE, ToolConstants.CFG_COMPILE);
    env.put(ToolConstants.CFG_CLASSDIR, output.getCanonicalPath() + "/classes");
    env.put(FrontEndProfile.class, PluginLoader.getInstance().getFrontEndProfile("jaxws"));
    env.put(DataBindingProfile.class, PluginLoader.getInstance().getDataBindingProfile("jaxb"));
    env.put(ToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
    env.put(ToolConstants.CFG_PACKAGENAME, "org.apache.cxf.classpath");
    env.put(ToolConstants.CFG_CLASSDIR, output.getCanonicalPath() + "/classes");
    env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl/hello_world_doc_lit.wsdl"));
    JAXWSContainer w2jProcessor = new JAXWSContainer(null);
    w2jProcessor.setContext(env);
    w2jProcessor.execute();


    String tns = "http://apache.org/sepecifiedTns";
    String serviceName = "cxfService";
    String portName = "cxfPort";

    System.setProperty("java.class.path", "");

    //      test flag
    String[] args = new String[] {"-o",
                                  "java2wsdl.wsdl",
                                  "-cp",
                                  classFile.getCanonicalPath(),
                                  "-t",
                                  tns,
                                  "-servicename",
                                  serviceName,
                                  "-portname",
                                  portName,
                                  "-soap12",
                                  "-d",
                                  output.getPath(),
                                  "-wsdl",
                                  "org.apache.cxf.classpath.Greeter"};
    JavaToWS.main(args);
    File wsdlFile = new File(output, "java2wsdl.wsdl");
    assertTrue("Generate Wsdl Fail", wsdlFile.exists());
    Definition def = getDefinition(wsdlFile.getPath());
    Service wsdlService = def.getService(new QName(tns, serviceName));
    assertNotNull("Generate WSDL Service Error", wsdlService);

    Port wsdlPort = wsdlService.getPort(portName);
    assertNotNull("Generate service port error ", wsdlPort);

}
 
Example 13
Source File: JAXWSDefinitionBuilderTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testBuildDefinitionWithXMLBinding() {
    String qname = "http://apache.org/hello_world_xml_http/bare";
    String wsdlUrl = getClass().getResource("resources/hello_world_xml_bare.wsdl").toString();

    JAXWSDefinitionBuilder builder = new JAXWSDefinitionBuilder();
    builder.setBus(BusFactory.getDefaultBus());
    builder.setContext(env);
    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, "XMLService"));
    assertNotNull(service);

    Map<?, ?> ports = service.getPorts();
    assertNotNull(ports);
    assertEquals(1, ports.size());
    Port port = service.getPort("XMLPort");
    assertNotNull(port);

    assertEquals(1, port.getExtensibilityElements().size());
    Object obj = port.getExtensibilityElements().get(0);
    if (obj instanceof JAXBExtensibilityElement) {
        obj = ((JAXBExtensibilityElement)obj).getValue();
    }
    assertTrue(obj.getClass().getName() + " is not an AddressType",
               obj instanceof AddressType);

    Binding binding = port.getBinding();
    assertNotNull(binding);
    assertEquals(new QName(qname, "Greeter_XMLBinding"), binding.getQName());

    BindingOperation operation = binding.getBindingOperation("sayHi", null, null);
    assertNotNull(operation);

    BindingInput input = operation.getBindingInput();
    assertNotNull(input);
    assertEquals(1, input.getExtensibilityElements().size());
    obj = input.getExtensibilityElements().get(0);
    if (obj instanceof JAXBExtensibilityElement) {
        obj = ((JAXBExtensibilityElement)obj).getValue();
    }
    assertTrue(obj.getClass().getName() + " is not an XMLBindingMessageFormat",
               obj instanceof XMLBindingMessageFormat);
}