Search in sources :

Example 26 with Service

use of javax.wsdl.Service in project tesb-studio-se by Talend.

the class ServiceExportManager method createBlueprint.

@SuppressWarnings("unchecked")
public void createBlueprint(File outputFile, Map<ServicePort, Map<String, String>> ports, Map<String, String> additionalInfo, IFile wsdl, String studioServiceName) throws IOException, CoreException {
    // TODO: support multiport
    Entry<ServicePort, Map<String, String>> studioPort = ports.entrySet().iterator().next();
    Definition def = WSDLUtils.getDefinition(wsdl);
    QName serviceQName = null;
    String endpointAddress = null;
    String endpointName = null;
    Map<QName, Service> services = def.getServices();
    ServicePort servicePort = studioPort.getKey();
    for (Entry<QName, Service> serviceEntry : services.entrySet()) {
        // TODO: support multi-services
        Service service = serviceEntry.getValue();
        // TODO: support multi-ports
        Collection<Port> servicePorts = service.getPorts().values();
        for (Port port : servicePorts) {
            if (servicePort.getName().equals(port.getBinding().getPortType().getQName().getLocalPart())) {
                serviceQName = serviceEntry.getKey();
                endpointName = port.getName();
                endpointAddress = WSDLUtils.getPortAddress(port);
                if (null != endpointAddress) {
                    // http://jira.talendforge.org/browse/TESB-3638
                    final URI uri = URI.create(endpointAddress);
                    endpointAddress = uri.getPath();
                    if (endpointAddress == null) {
                        endpointAddress = uri.getRawSchemeSpecificPart();
                        int interrogationMark = endpointAddress.indexOf('?');
                        if (interrogationMark > 0) {
                            endpointAddress = endpointAddress.substring(0, interrogationMark);
                        }
                    }
                    if (endpointAddress.equals("/services/") || endpointAddress.equals("/services")) {
                        // pass as is
                        endpointAddress = endpointAddress;
                    } else if (endpointAddress.startsWith("/services/")) {
                        // remove forwarding "/services/" context as required by runtime
                        // leave
                        endpointAddress = endpointAddress.substring("/services/".length() - 1);
                    // forwarding
                    // slash
                    } else if (endpointAddress.length() == 1) {
                        // empty path
                        endpointAddress += studioServiceName;
                    }
                }
                break;
            }
        }
    }
    Map<String, Object> endpointInfo = new HashMap<String, Object>();
    // $NON-NLS-1$
    endpointInfo.put("namespace", serviceQName.getNamespaceURI());
    // $NON-NLS-1$
    endpointInfo.put("service", serviceQName.getLocalPart());
    // $NON-NLS-1$
    endpointInfo.put("port", endpointName);
    // $NON-NLS-1$
    endpointInfo.put("address", endpointAddress);
    // $NON-NLS-1$
    endpointInfo.put("studioName", studioServiceName);
    // $NON-NLS-1$
    endpointInfo.put("wsdlLocation", wsdl.getName());
    Map<String, String> operation2job = new HashMap<String, String>();
    for (Map.Entry<ServicePort, Map<String, String>> port : ports.entrySet()) {
        // TODO: actual port work
        for (Map.Entry<String, String> operation : port.getValue().entrySet()) {
            operation2job.put(operation.getKey(), operation.getValue());
        }
    }
    // $NON-NLS-1$
    endpointInfo.put("operation2job", operation2job);
    boolean isStudioEEVersion = isStudioEEVersion();
    boolean useRegistry = isStudioEEVersion && Boolean.valueOf(additionalInfo.get(ServiceMetadataDialog.USE_SERVICE_REGISTRY));
    boolean useSL = Boolean.valueOf(additionalInfo.get(ServiceMetadataDialog.USE_SL));
    boolean useSAM = !useRegistry && Boolean.valueOf(additionalInfo.get(ServiceMetadataDialog.USE_SAM));
    boolean useSecurityToken = !useRegistry && Boolean.valueOf(additionalInfo.get(ServiceMetadataDialog.SECURITY_BASIC));
    boolean useSecuritySAML = !useRegistry && Boolean.valueOf(additionalInfo.get(ServiceMetadataDialog.SECURITY_SAML));
    boolean useAuthorization = !useRegistry && isStudioEEVersion && useSecuritySAML && Boolean.valueOf(additionalInfo.get(ServiceMetadataDialog.AUTHORIZATION));
    boolean useEncryption = !useRegistry && isStudioEEVersion && useSecuritySAML && Boolean.valueOf(additionalInfo.get(ServiceMetadataDialog.ENCRYPTION));
    boolean logMessages = Boolean.valueOf(additionalInfo.get(ServiceMetadataDialog.LOG_MESSAGES));
    boolean wsdlSchemaValidation = isStudioEEVersion && Boolean.valueOf(additionalInfo.get(ServiceMetadataDialog.WSDL_SCHEMA_VALIDATION));
    boolean useBusinessCorrelation = !useRegistry && Boolean.valueOf(additionalInfo.get(ServiceMetadataDialog.USE_BUSINESS_CORRELATION));
    // $NON-NLS-1$
    endpointInfo.put("useSL", useSL);
    // $NON-NLS-1$
    endpointInfo.put("useSAM", useSAM);
    // $NON-NLS-1$
    endpointInfo.put("useSecurityToken", useSecurityToken);
    // $NON-NLS-1$
    endpointInfo.put("useSecuritySAML", useSecuritySAML);
    // $NON-NLS-1$
    endpointInfo.put("useAuthorization", useAuthorization);
    // $NON-NLS-1$
    endpointInfo.put("useEncryption", useEncryption);
    // $NON-NLS-1$
    endpointInfo.put("useServiceRegistry", useRegistry);
    // $NON-NLS-1$
    endpointInfo.put("logMessages", logMessages);
    // $NON-NLS-1$
    endpointInfo.put("useWsdlSchemaValidation", wsdlSchemaValidation);
    // $NON-NLS-1$
    endpointInfo.put("useBusinessCorrelation", useBusinessCorrelation);
    Map<String, String> slCustomProperties = new HashMap<String, String>();
    if (useSL) /* && !useRegistry */
    {
        for (Map.Entry<String, String> prop : additionalInfo.entrySet()) {
            if (prop.getKey().startsWith(ServiceMetadataDialog.SL_CUSTOM_PROP_PREFIX)) {
                slCustomProperties.put(prop.getKey().substring(ServiceMetadataDialog.SL_CUSTOM_PROP_PREFIX.length()), prop.getValue());
            }
        }
    }
    // $NON-NLS-1$
    endpointInfo.put("slCustomProps", slCustomProperties);
    // $NON-NLS-1$
    endpointInfo.put(// $NON-NLS-1$
    "samlConfig", // $NON-NLS-1$
    serviceQName.toString().replaceAll("\\W+", "_").substring(1));
    // $NON-NLS-1$
    TemplateProcessor.processTemplate(// $NON-NLS-1$
    "DATA_SERVICE_BLUEPRINT_CONFIG", endpointInfo, outputFile, getClass().getResourceAsStream(TEMPLATE_BLUEPRINT));
}
Also used : ServicePort(org.talend.repository.services.model.services.ServicePort) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) ServicePort(org.talend.repository.services.model.services.ServicePort) Port(javax.wsdl.Port) Definition(javax.wsdl.Definition) IBrandingService(org.talend.core.ui.branding.IBrandingService) Service(javax.wsdl.Service) URI(java.net.URI) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) HashMap(java.util.HashMap) Map(java.util.Map) EnumMap(java.util.EnumMap)

Example 27 with Service

use of javax.wsdl.Service in project Activiti by Activiti.

the class WSDLImporter method importServicesAndOperations.

/**
   * Imports services and operations from the WSDL definition
   */
private 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);
        }
    }
}
Also used : BindingOperation(javax.wsdl.BindingOperation) Port(javax.wsdl.Port) Service(javax.wsdl.Service)

Example 28 with Service

use of javax.wsdl.Service in project cxf by apache.

the class JAXBExtensionHelperTest method checkTestExt.

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);
}
Also used : QName(javax.xml.namespace.QName) Port(javax.wsdl.Port) UnknownExtensibilityElement(javax.wsdl.extensions.UnknownExtensibilityElement) AnotherPolicyType(org.apache.cxf.abc.test.AnotherPolicyType) Service(javax.wsdl.Service) TestPolicyType(org.apache.cxf.abc.test.TestPolicyType)

Example 29 with Service

use of javax.wsdl.Service in project cxf by apache.

the class ServiceWSDLBuilderTest method setupWSDL.

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>());
}
Also used : Bus(org.apache.cxf.Bus) DestinationFactory(org.apache.cxf.transport.DestinationFactory) DestinationFactoryManager(org.apache.cxf.transport.DestinationFactoryManager) HashMap(java.util.HashMap) Service(javax.wsdl.Service) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) WSDLFactory(javax.wsdl.factory.WSDLFactory) WSDLManager(org.apache.cxf.wsdl.WSDLManager) WSDLReader(javax.wsdl.xml.WSDLReader)

Example 30 with Service

use of javax.wsdl.Service in project cxf by apache.

the class ServiceWSDLBuilderTest method testDefinition.

@Test
public void testDefinition() throws Exception {
    setupWSDL(WSDL_PATH);
    assertEquals(newDef.getTargetNamespace(), "http://apache.org/hello_world_soap_http");
    Service serv = newDef.getService(new QName("http://apache.org/hello_world_soap_http", "SOAPService"));
    assertNotNull(serv);
    assertNotNull(serv.getPort("SoapPort"));
}
Also used : QName(javax.xml.namespace.QName) Service(javax.wsdl.Service) Test(org.junit.Test)

Aggregations

Service (javax.wsdl.Service)53 Port (javax.wsdl.Port)37 QName (javax.xml.namespace.QName)28 Definition (javax.wsdl.Definition)21 Test (org.junit.Test)16 Binding (javax.wsdl.Binding)12 File (java.io.File)10 HashMap (java.util.HashMap)10 Map (java.util.Map)8 BindingOperation (javax.wsdl.BindingOperation)8 WSDLReader (javax.wsdl.xml.WSDLReader)8 SOAPAddress (javax.wsdl.extensions.soap.SOAPAddress)7 ToolException (org.apache.cxf.tools.common.ToolException)6 List (java.util.List)5 Operation (javax.wsdl.Operation)5 Part (javax.wsdl.Part)5 PortType (javax.wsdl.PortType)5 WSDLFactory (javax.wsdl.factory.WSDLFactory)5 Bus (org.apache.cxf.Bus)5 URI (java.net.URI)4