Search in sources :

Example 1 with Service

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

the class ServiceExportForESBRuntimeManager method createBlueprint.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.repository.services.ui.scriptmanager.ServiceExportManager#createBlueprint(java.io.File,
     * java.util.Map, java.util.Map, org.eclipse.core.resources.IFile, java.lang.String)
     */
@Override
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();
    // TODO: do this in looooooooop!!!
    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, ServiceExportManager.class.getResourceAsStream("/resources/blueprint-template.xml"));
}
Also used : ServicePort(org.talend.repository.services.model.services.ServicePort) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) ServiceExportManager(org.talend.repository.services.ui.scriptmanager.ServiceExportManager) ServicePort(org.talend.repository.services.model.services.ServicePort) Port(javax.wsdl.Port) Definition(javax.wsdl.Definition) Service(javax.wsdl.Service) URI(java.net.URI) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with Service

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

the class DynamicInvoker method invokeMethod.

/**
     * Method invokeMethod
     * 
     * @param wsdlLocation
     * @param operationName
     * @param inputName
     * @param outputName
     * @param portName
     * @param args
     * 
     * @return
     * 
     * @throws Exception
     */
public HashMap invokeMethod(String operationName, String portName, String[] args) throws Exception {
    String serviceNS = null;
    String serviceName = null;
    String operationQName = null;
    // System.out.println("Preparing Axis dynamic invocation");
    Service service = selectService(serviceNS, serviceName);
    Operation operation = null;
    org.apache.axis.client.Service dpf = new org.apache.axis.client.Service(wsdlParser, service.getQName());
    if (needWINAuth) {
        EngineConfiguration defaultConfig = EngineConfigurationFactoryFinder.newFactory().getClientEngineConfig();
        SimpleProvider config = new SimpleProvider(defaultConfig);
        config.deployTransport(HTTPTransport.DEFAULT_TRANSPORT_NAME, new CommonsHTTPSender());
        AxisClient axisClient = new AxisClient(config);
        dpf.setEngine(axisClient);
    }
    Vector inputs = new Vector();
    Port port = selectPort(service.getPorts(), portName);
    if (portName == null) {
        portName = port.getName();
    }
    Binding binding = port.getBinding();
    Call call = dpf.createCall(QName.valueOf(portName), QName.valueOf(operationName));
    ((org.apache.axis.client.Call) call).setTimeout(new Integer(timeout * 1000));
    ((org.apache.axis.client.Call) call).setProperty(ElementDeserializer.DESERIALIZE_CURRENT_ELEMENT, Boolean.TRUE);
    if (needAuth) {
        // authentication way1:
        // for calling webservice in deploy.wsdd:
        // <handler type="java:org.apache.axis.handlers.SimpleAuthorizationHandler"/>
        ((org.apache.axis.client.Call) call).setUsername(username);
        ((org.apache.axis.client.Call) call).setPassword(password);
        // authentication way2:
        // for bug:8403, in order to call webservice on "basic HTTP authentication"
        ((org.apache.axis.client.Call) call).setProperty(Stub.USERNAME_PROPERTY, username);
        ((org.apache.axis.client.Call) call).setProperty(Stub.PASSWORD_PROPERTY, password);
    }
    if (needWINAuth) {
        ((org.apache.axis.client.Call) call).setUsername(username);
        ((org.apache.axis.client.Call) call).setPassword(password);
    }
    if (useProxy) {
        AxisProperties.setProperty("http.proxyHost", proxyHost);
        AxisProperties.setProperty("http.proxyPort", proxyPort);
        AxisProperties.setProperty("http.proxyUser", proxyUser);
        AxisProperties.setProperty("http.proxyPassword", proxyPassword);
    }
    // Output types and names
    Vector outNames = new Vector();
    // Input types and names
    Vector inNames = new Vector();
    Vector inTypes = new Vector();
    SymbolTable symbolTable = wsdlParser.getSymbolTable();
    BindingEntry bEntry = symbolTable.getBindingEntry(binding.getQName());
    Parameters parameters = null;
    Iterator i = bEntry.getParameters().keySet().iterator();
    while (i.hasNext()) {
        Operation o = (Operation) i.next();
        if (o.getName().equals(operationName)) {
            operation = o;
            parameters = (Parameters) bEntry.getParameters().get(o);
            break;
        }
    }
    if ((operation == null) || (parameters == null)) {
        throw new RuntimeException(operationName + " was not found.");
    }
    // loop over paramters and set up in/out params
    for (int j = 0; j < parameters.list.size(); ++j) {
        Parameter p = (Parameter) parameters.list.get(j);
        if (p.getMode() == 1) {
            // IN
            inNames.add(p.getQName().getLocalPart());
            inTypes.add(p);
        } else if (p.getMode() == 2) {
            // OUT
            outNames.add(p.getQName().getLocalPart());
        } else if (p.getMode() == 3) {
            // INOUT
            inNames.add(p.getQName().getLocalPart());
            inTypes.add(p);
            outNames.add(p.getQName().getLocalPart());
        }
    }
    // set output type
    if (parameters.returnParam != null) {
        if (!parameters.returnParam.getType().isBaseType()) {
            ((org.apache.axis.client.Call) call).registerTypeMapping(org.w3c.dom.Element.class, parameters.returnParam.getType().getQName(), new ElementSerializerFactory(), new ElementDeserializerFactory());
        }
        // Get the QName for the return Type
        QName returnType = org.apache.axis.wsdl.toJava.Utils.getXSIType(parameters.returnParam);
        QName returnQName = parameters.returnParam.getQName();
        outNames.add(returnQName.getLocalPart());
    }
    if (inNames.size() != args.length - 2)
        throw new RuntimeException("Need " + inNames.size() + " arguments!!!");
    for (int pos = 0; pos < inNames.size(); ++pos) {
        String arg = args[pos + 2];
        Parameter p = (Parameter) inTypes.get(pos);
        inputs.add(getParamData((org.apache.axis.client.Call) call, p, arg));
    }
    // System.out.println("Executing operation " + operationName + " with parameters:");
    for (int j = 0; j < inputs.size(); j++) {
    // System.out.println(inNames.get(j) + "=" + inputs.get(j));
    }
    Object ret = call.invoke(inputs.toArray());
    Map outputs = call.getOutputParams();
    HashMap map = new HashMap();
    String name = null;
    Object value = null;
    if (outNames.size() > 0) {
        name = (String) outNames.get(0);
        value = outputs.get(name);
    }
    if ((value == null) && (ret != null)) {
        map.put(name, ret);
    } else {
        map.put(outNames, outputs);
    }
    return map;
}
Also used : HashMap(java.util.HashMap) Port(javax.wsdl.Port) Operation(javax.wsdl.Operation) AxisClient(org.apache.axis.client.AxisClient) EngineConfiguration(org.apache.axis.EngineConfiguration) Iterator(java.util.Iterator) ElementDeserializerFactory(org.apache.axis.encoding.ser.ElementDeserializerFactory) Vector(java.util.Vector) Binding(javax.wsdl.Binding) Call(javax.xml.rpc.Call) CommonsHTTPSender(org.apache.axis.transport.http.CommonsHTTPSender) Parameters(org.apache.axis.wsdl.symbolTable.Parameters) ElementSerializerFactory(org.apache.axis.encoding.ser.ElementSerializerFactory) QName(javax.xml.namespace.QName) Service(javax.wsdl.Service) SymbolTable(org.apache.axis.wsdl.symbolTable.SymbolTable) SimpleProvider(org.apache.axis.configuration.SimpleProvider) Parameter(org.apache.axis.wsdl.symbolTable.Parameter) BindingEntry(org.apache.axis.wsdl.symbolTable.BindingEntry) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with Service

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

the class WSDLServiceFactoryBean method getDefinition.

protected Definition getDefinition(String url) {
    if (definition == null) {
        try {
            definition = getBus().getExtension(WSDLManager.class).getDefinition(url);
        } catch (Exception ex) {
            throw new RuntimeCamelException(ex);
        }
    }
    if (this.getServiceQName(false) == null) {
        Map<QName, ?> services = CastUtils.cast(definition.getServices());
        if (services.size() == 0) {
            throw new IllegalArgumentException("There is no service in the WSDL" + url);
        }
        if (services.size() > 1) {
            throw new IllegalArgumentException("service name must be specified, there is more than one service in the WSDL" + url);
        }
        QName serviceQName = services.keySet().iterator().next();
        this.setServiceName(serviceQName);
    }
    if (this.getEndpointName(false) == null) {
        Service service = definition.getService(getServiceQName(false));
        Map<String, ?> ports = CastUtils.cast(service.getPorts());
        if (ports.size() == 0) {
            throw new IllegalArgumentException("There is no port/endpoint in the service " + getServiceQName() + "of WSDL" + url);
        }
        if (ports.size() > 1) {
            throw new IllegalArgumentException("Port/endpoint name must be specified, There is more than one port in the service" + service.getQName() + " of the WSDL" + url);
        }
        QName endpointQName = new QName(service.getQName().getNamespaceURI(), ports.keySet().iterator().next());
        setEndpointName(endpointQName);
    }
    return definition;
}
Also used : QName(javax.xml.namespace.QName) Service(javax.wsdl.Service) RuntimeCamelException(org.apache.camel.RuntimeCamelException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) EndpointException(org.apache.cxf.endpoint.EndpointException)

Example 4 with Service

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

the class FailoverTest method updateWsdlExtensors.

/**
 * Exchange the port number in all service addresses on the bus.
 * @param port1 current port
 * @param port2 new port
 */
private void updateWsdlExtensors(String port1, String port2) {
    try {
        Definition def = bus.getExtension(WSDLManager.class).getDefinition(wsdlLocation);
        Map<?, ?> map = def.getAllServices();
        for (Object o : map.values()) {
            Service service = (Service) o;
            Map<?, ?> ports = service.getPorts();
            for (Object p : ports.values()) {
                Port port = (Port) p;
                List<?> l = port.getExtensibilityElements();
                for (Object e : l) {
                    if (e instanceof SOAPAddress) {
                        String add = ((SOAPAddress) e).getLocationURI();
                        int idx = add.indexOf(":" + port1);
                        if (idx != -1) {
                            add = add.substring(0, idx) + ":" + port2 + add.substring(idx + port1.length() + 1);
                            ((SOAPAddress) e).setLocationURI(add);
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Port(javax.wsdl.Port) SOAPAddress(javax.wsdl.extensions.soap.SOAPAddress) Definition(javax.wsdl.Definition) WSDLManager(org.apache.cxf.wsdl.WSDLManager) ClusteredGreeterService(org.apache.cxf.greeter_control.ClusteredGreeterService) Service(javax.wsdl.Service) ControlService(org.apache.cxf.greeter_control.ControlService) Endpoint(org.apache.cxf.endpoint.Endpoint) ConnectException(java.net.ConnectException) HTTPException(org.apache.cxf.transport.http.HTTPException)

Example 5 with Service

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

the class WSDLASTVisitor method getPhysicalDefinition.

// Write the physical definitions to a file.
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;
}
Also used : Binding(javax.wsdl.Binding) Definition(javax.wsdl.Definition) Service(javax.wsdl.Service) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement)

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