javax.wsdl.extensions.soap.SOAPAddress Java Examples

The following examples show how to use javax.wsdl.extensions.soap.SOAPAddress. 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: 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 #3
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 #4
Source File: WSDL2UDDI.java    From juddi with Apache License 2.0 6 votes vote down vote up
/**
 * Obtains the accessUrl from the WSDL
 *
 * @param port
 * @return a string url
 * @throws MalformedURLException
 */
private String getBindingURL(Port port) throws MalformedURLException {

        String bindingUrl = null;
        for (Object element : port.getExtensibilityElements()) {
                if (element instanceof SOAPAddress) {
                        SOAPAddress address = (SOAPAddress) element;
                        URL locationURI = new URL(address.getLocationURI());
                        if (locationURI != null) {
                                bindingUrl = urlLocalizer.rewrite(locationURI);
                                break;
                        }
                }
        }
        return bindingUrl;
}
 
Example #5
Source File: WsdlUtils.java    From hop with Apache License 2.0 5 votes vote down vote up
/**
 * Get the SOAP address location for the specified port.
 *
 * @param p A WSDL Port instance.
 * @return The SOAP address URI.
 */
protected static String getSOAPAddress( Port p ) {
  ExtensibilityElement e = findExtensibilityElement( (ElementExtensible) p, SOAP_PORT_ADDRESS_NAME );
  if ( e instanceof SOAP12Address ) {
    return ( (SOAP12Address) e ).getLocationURI();
  } else if ( e instanceof SOAPAddress ) {
    return ( (SOAPAddress) e ).getLocationURI();
  }

  return null;
}
 
Example #6
Source File: WsdlUtils.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Get the SOAP address location for the specified port.
 *
 * @param p
 *          A WSDL Port instance.
 * @return The SOAP address URI.
 */
protected static String getSOAPAddress( Port p ) {
  ExtensibilityElement e = findExtensibilityElement( p, SOAP_PORT_ADDRESS_NAME );
  if ( e instanceof SOAP12Address ) {
    return ( (SOAP12Address) e ).getLocationURI();
  } else if ( e instanceof SOAPAddress ) {
    return ( (SOAPAddress) e ).getLocationURI();
  }

  return null;
}
 
Example #7
Source File: PartialWSDLProcessor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static javax.wsdl.Service doAppendService(Definition wsdlDefinition,
                                                 String existPortName, ExtensionRegistry
                                                 extReg, Binding binding) throws Exception {
    javax.wsdl.Service wsdlService = wsdlDefinition.createService();
    wsdlService.setQName(new QName(wsdlDefinition.getTargetNamespace(), existPortName + serviceName));
    Port port = wsdlDefinition.createPort();
    port.setName(existPortName + portName);
    port.setBinding(binding);
    SOAPAddress address = PartialWSDLProcessor.setAddrElement(wsdlDefinition, port, extReg);
    port.addExtensibilityElement(address);
    wsdlService.addPort(port);
    return wsdlService;
}
 
Example #8
Source File: SOAPBindingUtil.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static SOAPAddress createSoapAddress(ExtensionRegistry extReg, boolean isSOAP12)
    throws WSDLException {
    ExtensibilityElement extElement = null;
    if (isSOAP12) {
        extElement = extReg.createExtension(Port.class,
                                                           WSDLConstants.QNAME_SOAP12_BINDING_ADDRESS);
    } else {
        extElement = extReg.createExtension(Port.class,
                                                         WSDLConstants.QNAME_SOAP_BINDING_ADDRESS);
    }
    return getSoapAddress(extElement);
}
 
Example #9
Source File: WSDLGetUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void setSoapAddressLocationOn(Port port, String url) {
    List<?> extensions = port.getExtensibilityElements();
    for (Object extension : extensions) {
        if (extension instanceof SOAP12Address) {
            ((SOAP12Address)extension).setLocationURI(url);
        } else if (extension instanceof SOAPAddress) {
            ((SOAPAddress)extension).setLocationURI(url);
        }
    }
}
 
Example #10
Source File: WSDLUtils.java    From tesb-studio-se with Apache License 2.0 5 votes vote down vote up
public static String getPortAddress(final Port port) {
    final Collection<?> extensibilityElements = port.getExtensibilityElements();
    SOAPAddress soapAddress = findExtensibilityElement(extensibilityElements, SOAPAddress.class);
    if (null != soapAddress) {
        return soapAddress.getLocationURI();
    }
    SOAP12Address soap12Address = findExtensibilityElement(extensibilityElements, SOAP12Address.class);
    if (null != soap12Address) {
        return soap12Address.getLocationURI();
    }
    return null;
}
 
Example #11
Source File: ServiceRefFactory.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * @param port analyzed port
 * @return Returns the endpoint URL of the given Port
 */
private String getSOAPLocation(Port port) {
    String endpoint = null;
    @SuppressWarnings("unchecked") // Can't change the API
    List<ExtensibilityElement> extensions = port.getExtensibilityElements();
    for (Iterator<ExtensibilityElement> i = extensions.iterator();
            i.hasNext();) {
        ExtensibilityElement ext = i.next();
        if (ext instanceof SOAPAddress) {
            SOAPAddress addr = (SOAPAddress) ext;
            endpoint = addr.getLocationURI();
        }
    }
    return endpoint;
}
 
Example #12
Source File: ServiceRefFactory.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * @param port analyzed port
 * @return Returns the endpoint URL of the given Port
 */
private String getSOAPLocation(Port port) {
    String endpoint = null;
    @SuppressWarnings("unchecked") // Can't change the API
    List<ExtensibilityElement> extensions = port.getExtensibilityElements();
    for (Iterator<ExtensibilityElement> i = extensions.iterator();
            i.hasNext();) {
        ExtensibilityElement ext = i.next();
        if (ext instanceof SOAPAddress) {
            SOAPAddress addr = (SOAPAddress) ext;
            endpoint = addr.getLocationURI();
        }
    }
    return endpoint;
}
 
Example #13
Source File: ServiceRefFactory.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * @param port analyzed port
 * @return Returns the endpoint URL of the given Port
 */
private String getSOAPLocation(Port port) {
    String endpoint = null;
    @SuppressWarnings("unchecked") // Can't change the API
    List<ExtensibilityElement> extensions = port.getExtensibilityElements();
    for (ExtensibilityElement ext : extensions) {
        if (ext instanceof SOAPAddress) {
            SOAPAddress addr = (SOAPAddress) ext;
            endpoint = addr.getLocationURI();
        }
    }
    return endpoint;
}
 
Example #14
Source File: ComponentBuilder.java    From tesb-studio-se with Apache License 2.0 4 votes vote down vote up
private static ServiceInfo populateComponent(Service service) {
    ServiceInfo serviceInfo = new ServiceInfo();
    serviceInfo.setServiceName(service.getQName());
    Collection<Port> ports = service.getPorts().values();
    for (Port port : ports) {
        String soapLocation = null;
        SOAPAddress soapAddress = findExtensibilityElement(port.getExtensibilityElements(), SOAPAddress.class);
        if (null != soapAddress) {
            soapLocation = soapAddress.getLocationURI();
        } else {
            SOAP12Address soap12Address = findExtensibilityElement(port.getExtensibilityElements(), SOAP12Address.class);
            if (null != soap12Address) {
                soapLocation = soap12Address.getLocationURI();
            }
        }
        Binding binding = port.getBinding();
        for (BindingOperation operation : (Collection<BindingOperation>) binding.getBindingOperations()) {
            SOAPOperation soapOperation = findExtensibilityElement(operation.getExtensibilityElements(), SOAPOperation.class);

            if (null != soapOperation && OPERATION_TYPE_RPC.equalsIgnoreCase(soapOperation.getStyle())) {
                // TESB-6151 disable display of unsupported RPC type.
                serviceInfo.setHasRpcOperation(true);
                continue;
            }
            OperationInfo operationInfo = new OperationInfo(operation.getOperation());
            operationInfo.setPortName(port.getName());
            operationInfo.setNamespaceURI(binding.getPortType().getQName().getNamespaceURI());
            if (soapOperation != null) {
                operationInfo.setSoapActionURI(soapOperation.getSoapActionURI());
            } else {
                SOAP12Operation soap12Operation = findExtensibilityElement(operation.getExtensibilityElements(),
                        SOAP12Operation.class);
                if (soap12Operation != null) {
                    operationInfo.setSoapActionURI(soap12Operation.getSoapActionURI());
                }
            }

            operationInfo.setTargetURL(soapLocation);
            serviceInfo.addOperation(operationInfo);
        }
    }
    return serviceInfo;
}
 
Example #15
Source File: PublishedEndpointUrlTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testPublishedEndpointUrl() throws Exception {

    Greeter implementor = new org.apache.hello_world_soap_http.GreeterImpl();
    String publishedEndpointUrl = "http://cxf.apache.org/publishedEndpointUrl";
    Bus bus = BusFactory.getDefaultBus();
    JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
    svrFactory.setBus(bus);
    svrFactory.setServiceClass(Greeter.class);
    svrFactory.setAddress("http://localhost:" + PORT + "/publishedEndpointUrl");
    svrFactory.setPublishedEndpointUrl(publishedEndpointUrl);
    svrFactory.setServiceBean(implementor);

    Server server = svrFactory.create();

    WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader();
    wsdlReader.setFeature("javax.wsdl.verbose", false);

    URL url = new URL(svrFactory.getAddress() + "?wsdl=1");
    HttpURLConnection connect = (HttpURLConnection)url.openConnection();
    assertEquals(500, connect.getResponseCode());

    Definition wsdl = wsdlReader.readWSDL(svrFactory.getAddress() + "?wsdl");
    assertNotNull(wsdl);

    Collection<Service> services = CastUtils.cast(wsdl.getAllServices().values());
    final String failMesg = "WSDL provided incorrect soap:address location";

    for (Service service : services) {
        Collection<Port> ports = CastUtils.cast(service.getPorts().values());
        for (Port port : ports) {
            List<?> extensions = port.getExtensibilityElements();
            for (Object extension : extensions) {
                String actualUrl = null;
                if (extension instanceof SOAP12Address) {
                    actualUrl = ((SOAP12Address)extension).getLocationURI();
                } else if (extension instanceof SOAPAddress) {
                    actualUrl = ((SOAPAddress)extension).getLocationURI();
                }

                //System.out.println("Checking url: " + actualUrl + " against " + publishedEndpointUrl);
                assertEquals(failMesg, publishedEndpointUrl, actualUrl);
            }
        }
    }
    server.stop();
    server.destroy();
    bus.shutdown(true);
}
 
Example #16
Source File: WSDLToServiceProcessorTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testNewService() throws Exception {
    String[] args = new String[] {"-transport", "soap", "-e", "serviceins", "-p", "portins", "-n",
                                  "Greeter_SOAPBinding", "-a",
                                  "http://localhost:9000/newservice/newport", "-d",
                                  output.getCanonicalPath(),
                                  getLocation("/misctools_wsdl/hello_world.wsdl")};
    WSDLToService.main(args);

    File outputFile = new File(output, "hello_world-service.wsdl");
    assertTrue("New wsdl file is not generated", outputFile.exists());
    WSDLToServiceProcessor processor = new WSDLToServiceProcessor();
    processor.setEnvironment(env);
    try {
        processor.parseWSDL(outputFile.getAbsolutePath());
        Service service = processor.getWSDLDefinition().getService(
                                                                   new QName(processor
                                                                       .getWSDLDefinition()
                                                                       .getTargetNamespace(),
                                                                             "serviceins"));
        if (service == null) {
            fail("Element wsdl:service serviceins Missed!");
        }
        Iterator<?> it = service.getPort("portins").getExtensibilityElements().iterator();
        if (it == null || !it.hasNext()) {
            fail("Element wsdl:port portins Missed!");
        }
        boolean found = false;
        while (it.hasNext()) {
            Object obj = it.next();
            if (obj instanceof SOAPAddress) {
                SOAPAddress soapAddress = (SOAPAddress)obj;
                if (soapAddress.getLocationURI() != null
                    && "http://localhost:9000/newservice/newport".equals(soapAddress.getLocationURI())) {
                    found = true;
                    break;
                }
            }
        }
        if (!found) {
            fail("Element soap:address of service port Missed!");
        }
    } catch (ToolException e) {
        fail("Exception Encountered when parsing wsdl, error: " + e.getMessage());
    }
}
 
Example #17
Source File: WSDLToServiceProcessorTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testDefaultLocation() throws Exception {

    String[] args = new String[] {"-transport", "soap", "-e", "serviceins", "-p", "portins", "-n",
                                  "Greeter_SOAPBinding", "-d", output.getCanonicalPath(),
                                  getLocation("/misctools_wsdl/hello_world.wsdl")};
    WSDLToService.main(args);

    File outputFile = new File(output, "hello_world-service.wsdl");
    assertTrue("New wsdl file is not generated", outputFile.exists());
    WSDLToServiceProcessor processor = new WSDLToServiceProcessor();
    processor.setEnvironment(env);
    try {
        processor.parseWSDL(outputFile.getAbsolutePath());
        Service service = processor.getWSDLDefinition().getService(
                                                                   new QName(processor
                                                                       .getWSDLDefinition()
                                                                       .getTargetNamespace(),
                                                                             "serviceins"));
        if (service == null) {
            fail("Element wsdl:service serviceins Missed!");
        }
        Iterator<?> it = service.getPort("portins").getExtensibilityElements().iterator();
        if (it == null || !it.hasNext()) {
            fail("Element wsdl:port portins Missed!");
        }
        boolean found = false;
        while (it.hasNext()) {
            Object obj = it.next();
            if (obj instanceof SOAPAddress) {
                SOAPAddress soapAddress = (SOAPAddress)obj;
                if (soapAddress.getLocationURI() != null
                    && "http://localhost:9000/serviceins/portins".equals(soapAddress.getLocationURI())) {
                    found = true;
                    break;
                }
            }
        }
        if (!found) {
            fail("Element soap:address of service port Missed!");
        }
    } catch (ToolException e) {
        fail("Exception Encountered when parsing wsdl, error: " + e.getMessage());
    }
}
 
Example #18
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 #19
Source File: SOAPBindingUtil.java    From cxf with Apache License 2.0 4 votes vote down vote up
public static boolean isSOAPAddress(Object obj) {
    return obj instanceof SOAPAddress || obj instanceof SOAP12Address;
}
 
Example #20
Source File: SOAPBindingUtil.java    From cxf with Apache License 2.0 4 votes vote down vote up
public static SOAPAddress getSoapAddress(Object obj) {
    if (isSOAPAddress(obj)) {
        return getProxy(SOAPAddress.class, obj);
    }
    return null;
}
 
Example #21
Source File: SOAPBindingUtil.java    From cxf with Apache License 2.0 4 votes vote down vote up
public static boolean isSOAPAddress(Object obj) {
    return obj instanceof SOAPAddress || obj instanceof SOAP12Address;
}
 
Example #22
Source File: PartialWSDLProcessor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public static SOAPAddress setAddrElement(Definition wsdlDefinition, Port port,
                                         ExtensionRegistry extReg) throws Exception {
    SOAPAddress address = SOAPBindingUtil.createSoapAddress(extReg, false);
    address.setLocationURI("dummy");
    return address;
}
 
Example #23
Source File: JaxRpcServiceInfoBuilder.java    From tomee with Apache License 2.0 4 votes vote down vote up
private String getAddressLocation(List extensibilityElements) throws OpenEJBException {
    SOAPAddress soapAddress = getExtensibilityElement(SOAPAddress.class, extensibilityElements);
    String locationURIString = soapAddress.getLocationURI();
    return locationURIString;
}