Java Code Examples for javax.wsdl.Definition#getTargetNamespace()

The following examples show how to use javax.wsdl.Definition#getTargetNamespace() . 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: 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 2
Source File: WsdlTypes.java    From hop with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new for WsdlTypes instance for the specified WSDL definition.
 *
 * @param wsdlDefinition The WSDL definition.
 */
@SuppressWarnings( "unchecked" )
protected WsdlTypes( Definition wsdlDefinition ) {

  _types = wsdlDefinition.getTypes();
  _targetNamespace = wsdlDefinition.getTargetNamespace();
  _prefixMappings = wsdlDefinition.getNamespaces();
  _elementFormQualifiedNamespaces = new HashSet<String>( getElementFormQualifiedNamespaces() );
  _namedComplexTypes = new WsdlComplexTypes( this );
}
 
Example 3
Source File: BPEL_020_IntegrationTest.java    From juddi with Apache License 2.0 5 votes vote down vote up
@Test
public void parseWSDL_PortTypeTModels() throws WSDLException, Exception {

        Definition wsdlDefinition = rw.readWSDL("uddi_data/bpel/riftsaw/bpel-technote.wsdl");
        @SuppressWarnings("unchecked")
        Map<QName, PortType> portTypes = (Map<QName, PortType>) wsdlDefinition.getAllPortTypes();
        String ns = wsdlDefinition.getTargetNamespace();
        logger.info("Namespace: " + ns);

        boolean foundInterfaceOfTravelAgent=false;
        boolean foundInterfaceOfCustomer=false;
  
        Iterator<QName> iterator = portTypes.keySet().iterator();
        while (iterator.hasNext()) {
                QName qName = iterator.next();
                String nsp = qName.getNamespaceURI();
                String localpart = qName.getLocalPart();
                logger.info("Namespace: " + nsp);
                logger.info("LocalPart: " + localpart);
                if (localpart.equals("InterfaceOfTravelAgent"))
                        foundInterfaceOfTravelAgent=true;
                if (localpart.equals("InterfaceOfCustomer"))
                        foundInterfaceOfCustomer=true;
        }
        org.junit.Assert.assertTrue("InterfaceOfCustomer wasn't found, wsdl parsing error", foundInterfaceOfCustomer);
        org.junit.Assert.assertTrue("InterfaceOfTravelAgent wasn't found, wsdl parsing error", foundInterfaceOfTravelAgent);
}
 
Example 4
Source File: BPEL2UDDI.java    From juddi with Apache License 2.0 5 votes vote down vote up
/**
 * 1. Register PortType tModels
 * 2. Register WSDL BPEL4WS Process
 * 3. Register WSDL Port
 * 4. Register Process Service
 * 5. Register Binding
 * 
 * @param serviceName - QName of the service
 * @param portName - portName of the service
 * @param serviceUrl - URL at which the service can be invoked
 * @param wsdlDefinition - WSDL Definition of the Web Service
        * @return a binding template
 * @throws WSDLException 
 * @throws MalformedURLException 
 * @throws TransportException 
 * @throws ConfigurationException 
 * @throws RemoteException 
 */
@SuppressWarnings("unchecked")
public BindingTemplate register(QName serviceName, String portName, URL serviceUrl, Definition wsdlDefinition) 
	throws WSDLException, MalformedURLException, RemoteException, ConfigurationException, TransportException 
{
	String targetNamespace = wsdlDefinition.getTargetNamespace();
	String genericWSDLURL  = wsdlDefinition.getDocumentBaseURI();   //TODO maybe point to repository version
	String bpelOverviewURL = "http://localhost:8080/bpel-console/"; //TODO maybe point to bpel in console
	
	String serviceKey = UDDIKeyConvention.getServiceKey(properties, serviceName.getLocalPart());
	BusinessService service = lookupService(serviceKey);
	if (service==null) {
		List<TModel> tModels = new ArrayList<TModel>();
		// Create the PortType tModels
		Map<QName,PortType> portTypes = (Map<QName,PortType>) wsdlDefinition.getAllPortTypes();
		tModels.addAll(createWSDLPortTypeTModels(genericWSDLURL, portTypes));
		// Create the Binding tModels
		Map<QName,Binding> bindings = (Map<QName,Binding>) wsdlDefinition.getAllBindings();
		tModels.addAll(createWSDLBindingTModels(genericWSDLURL, bindings));
		// Create the BPEL4WS tModel
		TModel bpel4WSTModel = createBPEL4WSProcessTModel(serviceName, targetNamespace, portTypes, bpelOverviewURL);
	    tModels.add(bpel4WSTModel);
	    // Register these tModels
	    for (TModel tModel : tModels) {
			clerk.register(tModel);
		}
	    // BPEL Service
	    service = createBusinessService(serviceName, wsdlDefinition);
	    // Register this BPEL Service
	    clerk.register(service);
	}
	//Add the BindingTemplate to this Service
	BindingTemplate binding = createBPELBinding(serviceName, portName, serviceUrl, wsdlDefinition);
	// Register BindingTemplate
	clerk.register(binding);
	return binding;
}
 
Example 5
Source File: PortTypeVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private PortType findPortType(Scope intfScope) {
    String tns = mapper.map(intfScope.getParent());
    String intfName = intfScope.toString();
    Definition defn = definition;
    if (tns != null) {
        defn = manager.getWSDLDefinition(tns);
        intfName = intfScope.tail();
    }
    if (defn != null) {
        tns = defn.getTargetNamespace();
        QName name = new QName(tns, intfName);
        return defn.getPortType(name);
    }
    return null;
}
 
Example 6
Source File: WSDLToCorbaBinding.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void setIdlNamespace(Definition definition) {

        if (idlNamespace == null) {
            String tns = definition.getTargetNamespace();
            if (!tns.endsWith("/")) {
                tns += "/";
            }

            idlNamespace = tns + "corba/typemap/";
        }
        setNamespace(idlNamespace);
    }
 
Example 7
Source File: WsdlTypes.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new for WsdlTypes instance for the specified WSDL definition.
 *
 * @param wsdlDefinition
 *          The WSDL definition.
 */
@SuppressWarnings( "unchecked" )
protected WsdlTypes( Definition wsdlDefinition ) {

  _types = wsdlDefinition.getTypes();
  _targetNamespace = wsdlDefinition.getTargetNamespace();
  _prefixMappings = wsdlDefinition.getNamespaces();
  _elementFormQualifiedNamespaces = new HashSet<String>( getElementFormQualifiedNamespaces() );
  _namedComplexTypes = new WsdlComplexTypes( this );
}
 
Example 8
Source File: WSPortConnector.java    From development with Apache License 2.0 4 votes vote down vote up
/**
 * Reads the WSDL and determines the target namespace.
 * 
 * @param locator
 *            The URL of the WSDL.
 * @param host
 *            optional the host to be used when the one from the wsdl must
 *            not be used
 * @return The service's target namespace.
 * @throws WSDLException
 *             Thrown in case the WSDL could not be evaluated.
 */
private WSPortDescription getServiceDetails(WSDLLocator locator, String host)
        throws WSDLException {
    WSDLFactory wsdlFactory = WSDLFactory.newInstance();

    WSDLReader wsdlReader = wsdlFactory.newWSDLReader();
    Definition serviceDefinition = wsdlReader.readWSDL(locator);
    String tns = serviceDefinition.getTargetNamespace();
    // read the port name
    String endpointURL = null;
    final Map<?, ?> services = serviceDefinition.getServices();
    if (services != null) {
        for (Object serviceValue : services.values()) {
            javax.wsdl.Service service = (javax.wsdl.Service) serviceValue;
            Map<?, ?> ports = service.getPorts();
            if (ports != null) {
                for (Object portValue : ports.values()) {
                    Port port = (Port) portValue;
                    List<?> extensibilityElements = port
                            .getExtensibilityElements();
                    for (Object ex : extensibilityElements) {
                        ExtensibilityElement ext = (ExtensibilityElement) ex;
                        if (ext instanceof SOAPAddress) {
                            SOAPAddress address = (SOAPAddress) ext;
                            endpointURL = address.getLocationURI();
                            if (host != null) {
                                int idx = endpointURL.indexOf("//") + 2;
                                String tmp = endpointURL.substring(0, idx)
                                        + host
                                        + endpointURL.substring(endpointURL
                                                .indexOf(':', idx));
                                endpointURL = tmp;
                            }
                        }
                    }
                }
            }
        }
    }

    WSPortDescription result = new WSPortDescription();
    result.setTargetNamespace(tns);
    result.setEndpointURL(endpointURL);
    Element versionElement = serviceDefinition.getDocumentationElement();
    if (versionElement != null) {
        result.setVersion(versionElement.getTextContent());
    }
    return result;
}
 
Example 9
Source File: WSDLUtils.java    From tesb-studio-se with Apache License 2.0 4 votes vote down vote up
public static Map<String, String> getServiceOperationParameters(IFile wsdlURI, String operationName, String portTypeName)
        throws CoreException {
    // NOTE: all below in assuming standalone (no another WSDL's imports) WS-I complaint WSDL !
    Map<String, String> map = new HashMap<String, String>();
    if (null == wsdlURI) { // no WSDL provided
        return map;
    }

    Definition wsdl = getDefinition(wsdlURI);

    for (Object serviceObject : wsdl.getServices().values()) {
        Service service = (Service) serviceObject;
        for (Object portObject : service.getPorts().values()) {
            Port port = (Port) portObject;
            try {
                port.getBinding().getPortType().getQName().getLocalPart();
            } catch (NullPointerException npe) {
                throw getCoreException(
                        "WSDL is not consistent. Can not find portType operation description for current service.", npe);
            }
            if (portTypeName.equals(port.getBinding().getPortType().getQName().getLocalPart())) {
                final String targetNs = wsdl.getTargetNamespace();
                map.put(SERVICE_NAME, service.getQName().getLocalPart());
                map.put(SERVICE_NS, targetNs);
                map.put(PORT_NAME, port.getName());
                map.put(PORT_NS, targetNs);
                map.put(OPERATION_NAME, operationName);
                map.put(WSDL_LOCATION, wsdlURI.getLocation().toPortableString());

                BindingOperation bindingOperation = port.getBinding().getBindingOperation(operationName, null, null);
                if (null == bindingOperation) {
                    throw getCoreException("Operation '" + operationName + "' not found in binding", null);
                }
                map.put(COMMUNICATION_STYLE, null == bindingOperation.getBindingOutput() && bindingOperation
                        .getBindingFaults().isEmpty() ? ONE_WAY : REQUEST_RESPONSE);

                String faults = null;
                for (Object fault : bindingOperation.getBindingFaults().keySet()) {
                    if (faults == null) {
                        faults = (String) fault;
                    } else {
                        faults += ',' + (String) fault;
                    }
                }
                map.put(FAULTS, faults);

                // map.put(OPERATION_NS, targetNs);
                map.put(ENDPOINT_URI, getPortAddress(port));

                break;
            }
        }
    }

    return map;
}
 
Example 10
Source File: IDLToWSDLProcessor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void generateCORBAService(Definition def,
                                 Binding[] bindings,
                                 boolean isDefaultMapping)
    throws Exception {
    Map<String, Service> serviceMap = new HashMap<>();
    Map<String, String> serviceNames = getServiceNames(bindings, isDefaultMapping);
    for (int i = 0; i < bindings.length; i++) {
        QName portTypeName = bindings[i].getPortType().getQName();
        Service service;
        if (isDefaultMapping) {
            service = def.createService();
            service.setQName(new QName(def.getTargetNamespace(),
                                       portTypeName.getLocalPart() + "CORBAService"));
            def.addService(service);
        } else {
            String ns = portTypeName.getNamespaceURI();
            String serviceName = serviceNames.get(ns);
            service = serviceMap.get(ns);
            if (service == null) {
                service = def.createService();
                serviceMap.put(ns, service);
                String[] serviceTokens = serviceName.split("\\.");
                String serviceToken = serviceTokens[serviceTokens.length - 1];
                QName serviceQName = new QName(def.getTargetNamespace(), serviceToken);
                Service existingService = def.getService(serviceQName);
                if (existingService != null) {
                    String existingServiceNS =
                        ((Port) existingService.getPorts().values().iterator().next())
                        .getBinding().getPortType().getQName().getNamespaceURI();
                    existingService.setQName(new QName(def.getTargetNamespace(),
                                                       serviceNames.get(existingServiceNS)));
                    serviceMap.put(existingServiceNS, existingService);
                    service.setQName(new QName(def.getTargetNamespace(),
                                               serviceName));
                } else {
                    service.setQName(serviceQName);
                }
                def.addService(service);
            }
        }
        Port port = def.createPort();
        port.setName(portTypeName.getLocalPart() + "CORBAPort");
        AddressType address =
            (AddressType) def.getExtensionRegistry().createExtension(Port.class,
                                                                     CorbaConstants.NE_CORBA_ADDRESS);

        String addr = null;
        String addrFileName = (String) env.get(ToolCorbaConstants.CFG_ADDRESSFILE);
        if (addrFileName != null) {
            File addrFile = new File(addrFileName);
            try {
                FileReader fileReader = new FileReader(addrFile);
                try (BufferedReader bufferedReader = new BufferedReader(fileReader)) {
                    addr = bufferedReader.readLine();
                }
            } catch (Exception ex) {
                throw new ToolException(ex.getMessage(), ex);
            }
        } else {
            addr = (String) env.get(ToolCorbaConstants.CFG_ADDRESS);
        }
        if (addr == null) {
            addr = "IOR:";
        }
        address.setLocation(addr);
        port.addExtensibilityElement((ExtensibilityElement)address);
        service.addPort(port);
        port.setBinding(bindings[i]);
    }
}