Search in sources :

Example 16 with SOAPAddress

use of javax.wsdl.extensions.soap.SOAPAddress in project cxf by apache.

the class PublishedEndpointUrlTest method testPublishedEndpointUrl.

@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);
}
Also used : Bus(org.apache.cxf.Bus) Server(org.apache.cxf.endpoint.Server) Port(javax.wsdl.Port) Definition(javax.wsdl.Definition) Service(javax.wsdl.Service) URL(java.net.URL) HttpURLConnection(java.net.HttpURLConnection) Greeter(org.apache.hello_world_soap_http.Greeter) SOAPAddress(javax.wsdl.extensions.soap.SOAPAddress) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean) WSDLReader(javax.wsdl.xml.WSDLReader) SOAP12Address(javax.wsdl.extensions.soap12.SOAP12Address) Test(org.junit.Test)

Example 17 with SOAPAddress

use of javax.wsdl.extensions.soap.SOAPAddress in project tomcat70 by apache.

the class ServiceRefFactory method getSOAPLocation.

/**
 * @param port analyzed port
 * @return Returns the endpoint URL of the given Port
 */
private String getSOAPLocation(Port port) {
    String endpoint = null;
    // Can't change the API
    @SuppressWarnings("unchecked") 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;
}
Also used : SOAPAddress(javax.wsdl.extensions.soap.SOAPAddress) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement)

Example 18 with SOAPAddress

use of javax.wsdl.extensions.soap.SOAPAddress in project ofbiz-framework by apache.

the class ModelService method getWSDL.

public void getWSDL(Definition def, String locationURI) throws WSDLException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = null;
    Document document = null;
    try {
        builder = factory.newDocumentBuilder();
        document = builder.newDocument();
    } catch (Exception e) {
        throw new WSDLException("can not create WSDL", module);
    }
    def.setTypes(this.getTypes(document, def));
    // set the IN parameters
    Input input = def.createInput();
    Set<String> inParam = this.getInParamNames();
    Message inMessage = def.createMessage();
    inMessage.setQName(new QName(TNS, this.name + "Request"));
    inMessage.setUndefined(false);
    Part parametersPart = def.createPart();
    parametersPart.setName("map-Map");
    parametersPart.setTypeName(new QName(TNS, "map-Map"));
    inMessage.addPart(parametersPart);
    Element documentation = document.createElement("wsdl:documentation");
    for (String paramName : inParam) {
        ModelParam param = this.getParam(paramName);
        if (!param.internal) {
            Part part = param.getWSDLPart(def);
            Element attribute = document.createElement("attribute");
            attribute.setAttribute("name", paramName);
            attribute.setAttribute("type", part.getTypeName().getLocalPart());
            attribute.setAttribute("namespace", part.getTypeName().getNamespaceURI());
            attribute.setAttribute("java-class", param.type);
            attribute.setAttribute("optional", Boolean.toString(param.optional));
            documentation.appendChild(attribute);
        }
    }
    Element usernameAttr = document.createElement("attribute");
    usernameAttr.setAttribute("name", "login.username");
    usernameAttr.setAttribute("type", "std-String");
    usernameAttr.setAttribute("namespace", TNS);
    usernameAttr.setAttribute("java-class", String.class.getName());
    usernameAttr.setAttribute("optional", Boolean.toString(!this.auth));
    documentation.appendChild(usernameAttr);
    Element passwordAttr = document.createElement("attribute");
    passwordAttr.setAttribute("name", "login.password");
    passwordAttr.setAttribute("type", "std-String");
    passwordAttr.setAttribute("namespace", TNS);
    passwordAttr.setAttribute("java-class", String.class.getName());
    passwordAttr.setAttribute("optional", Boolean.toString(!this.auth));
    documentation.appendChild(passwordAttr);
    parametersPart.setDocumentationElement(documentation);
    def.addMessage(inMessage);
    input.setMessage(inMessage);
    // set the OUT parameters
    Output output = def.createOutput();
    Set<String> outParam = this.getOutParamNames();
    Message outMessage = def.createMessage();
    outMessage.setQName(new QName(TNS, this.name + "Response"));
    outMessage.setUndefined(false);
    Part resultsPart = def.createPart();
    resultsPart.setName("map-Map");
    resultsPart.setTypeName(new QName(TNS, "map-Map"));
    outMessage.addPart(resultsPart);
    documentation = document.createElement("wsdl:documentation");
    for (String paramName : outParam) {
        ModelParam param = this.getParam(paramName);
        if (!param.internal) {
            Part part = param.getWSDLPart(def);
            Element attribute = document.createElement("attribute");
            attribute.setAttribute("name", paramName);
            attribute.setAttribute("type", part.getTypeName().getLocalPart());
            attribute.setAttribute("namespace", part.getTypeName().getNamespaceURI());
            attribute.setAttribute("java-class", param.type);
            attribute.setAttribute("optional", Boolean.toString(param.optional));
            documentation.appendChild(attribute);
        }
    }
    resultsPart.setDocumentationElement(documentation);
    def.addMessage(outMessage);
    output.setMessage(outMessage);
    // set port type
    Operation operation = def.createOperation();
    operation.setName(this.name);
    operation.setUndefined(false);
    operation.setOutput(output);
    operation.setInput(input);
    PortType portType = def.createPortType();
    portType.setQName(new QName(TNS, this.name + "PortType"));
    portType.addOperation(operation);
    portType.setUndefined(false);
    def.addPortType(portType);
    // SOAP binding
    SOAPBinding soapBinding = new SOAPBindingImpl();
    soapBinding.setStyle("rpc");
    soapBinding.setTransportURI("http://schemas.xmlsoap.org/soap/http");
    Binding binding = def.createBinding();
    binding.setQName(new QName(TNS, this.name + "SoapBinding"));
    binding.setPortType(portType);
    binding.setUndefined(false);
    binding.addExtensibilityElement(soapBinding);
    BindingOperation bindingOperation = def.createBindingOperation();
    bindingOperation.setName(operation.getName());
    bindingOperation.setOperation(operation);
    SOAPBody soapBody = new SOAPBodyImpl();
    soapBody.setUse("literal");
    soapBody.setNamespaceURI(TNS);
    soapBody.setEncodingStyles(UtilMisc.toList("http://schemas.xmlsoap.org/soap/encoding/"));
    BindingOutput bindingOutput = def.createBindingOutput();
    bindingOutput.addExtensibilityElement(soapBody);
    bindingOperation.setBindingOutput(bindingOutput);
    BindingInput bindingInput = def.createBindingInput();
    bindingInput.addExtensibilityElement(soapBody);
    bindingOperation.setBindingInput(bindingInput);
    SOAPOperation soapOperation = new SOAPOperationImpl();
    // soapAction should be set to the location of the SOAP URI, or Visual Studio won't construct the correct SOAP message
    soapOperation.setSoapActionURI(locationURI);
    // this is the RPC/literal style.  See http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/
    // this parameter is necessary or Apache Synapse won't recognize the WSDL
    soapOperation.setStyle("rpc");
    bindingOperation.addExtensibilityElement(soapOperation);
    binding.addBindingOperation(bindingOperation);
    def.addBinding(binding);
    // Service port
    Port port = def.createPort();
    port.setBinding(binding);
    port.setName(this.name + "Port");
    if (locationURI != null) {
        SOAPAddress soapAddress = new SOAPAddressImpl();
        soapAddress.setLocationURI(locationURI);
        port.addExtensibilityElement(soapAddress);
    }
    Service service = def.createService();
    service.setQName(new QName(TNS, this.name));
    service.addPort(port);
    def.addService(service);
}
Also used : SOAPAddressImpl(com.ibm.wsdl.extensions.soap.SOAPAddressImpl) BindingOutput(javax.wsdl.BindingOutput) SOAPOperation(javax.wsdl.extensions.soap.SOAPOperation) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Message(javax.wsdl.Message) Element(org.w3c.dom.Element) Port(javax.wsdl.Port) Operation(javax.wsdl.Operation) BindingOperation(javax.wsdl.BindingOperation) SOAPOperation(javax.wsdl.extensions.soap.SOAPOperation) SOAPBodyImpl(com.ibm.wsdl.extensions.soap.SOAPBodyImpl) Document(org.w3c.dom.Document) BindingInput(javax.wsdl.BindingInput) Input(javax.wsdl.Input) BindingInput(javax.wsdl.BindingInput) BindingOperation(javax.wsdl.BindingOperation) BindingOutput(javax.wsdl.BindingOutput) Output(javax.wsdl.Output) SOAPBinding(javax.wsdl.extensions.soap.SOAPBinding) Binding(javax.wsdl.Binding) WSDLException(javax.wsdl.WSDLException) QName(javax.xml.namespace.QName) SOAPBinding(javax.wsdl.extensions.soap.SOAPBinding) Service(javax.wsdl.Service) SOAPOperationImpl(com.ibm.wsdl.extensions.soap.SOAPOperationImpl) GeneralException(org.apache.ofbiz.base.util.GeneralException) NoSuchElementException(java.util.NoSuchElementException) WSDLException(javax.wsdl.WSDLException) SOAPBody(javax.wsdl.extensions.soap.SOAPBody) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Part(javax.wsdl.Part) SOAPAddress(javax.wsdl.extensions.soap.SOAPAddress) SOAPBindingImpl(com.ibm.wsdl.extensions.soap.SOAPBindingImpl) PortType(javax.wsdl.PortType)

Example 19 with SOAPAddress

use of javax.wsdl.extensions.soap.SOAPAddress in project tesb-studio-se by Talend.

the class ComponentBuilder method populateComponent.

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);
            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;
}
Also used : ServiceInfo(org.talend.designer.esb.webservice.ws.wsdlinfo.ServiceInfo) Binding(javax.wsdl.Binding) OperationInfo(org.talend.designer.esb.webservice.ws.wsdlinfo.OperationInfo) BindingOperation(javax.wsdl.BindingOperation) SOAPOperation(javax.wsdl.extensions.soap.SOAPOperation) SOAP12Operation(javax.wsdl.extensions.soap12.SOAP12Operation) Port(javax.wsdl.Port) SOAPAddress(javax.wsdl.extensions.soap.SOAPAddress) Collection(java.util.Collection) SOAP12Address(javax.wsdl.extensions.soap12.SOAP12Address)

Example 20 with SOAPAddress

use of javax.wsdl.extensions.soap.SOAPAddress in project jbossws-cxf by jbossws.

the class JBossWebServicesEarTestCase method testEJB3Endpoint.

@Test
@RunAsClient
public void testEJB3Endpoint() throws Exception {
    String soapAddress = "http://" + baseURL.getHost() + ":" + baseURL.getPort() + "/earejb3/EndpointService/Endpoint";
    QName serviceName = new QName("http://eardeployment.jaxws/", "EndpointService");
    Service service = Service.create(new URL(soapAddress + "?wsdl"), serviceName);
    Endpoint port = service.getPort(Endpoint.class);
    // check soap address rewrite to verify jboss-webservices.xml override
    Definition wsdl = getWSDLDefinition(soapAddress + "?wsdl");
    SOAPAddress sa = (SOAPAddress) wsdl.getService(serviceName).getPort("EndpointPort").getExtensibilityElements().iterator().next();
    assertEquals("https://foo-jar:" + JBossWSTestHelper.getSecureServerPort(null, null) + "/earejb3/EndpointService/Endpoint", sa.getLocationURI());
    BindingProvider bp = (BindingProvider) port;
    bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, soapAddress);
    String helloWorld = "Hello world!";
    String retObj = port.echo(helloWorld);
    assertEquals(helloWorld, retObj);
}
Also used : QName(javax.xml.namespace.QName) SOAPAddress(javax.wsdl.extensions.soap.SOAPAddress) Definition(javax.wsdl.Definition) Service(javax.xml.ws.Service) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest)

Aggregations

SOAPAddress (javax.wsdl.extensions.soap.SOAPAddress)22 Port (javax.wsdl.Port)12 QName (javax.xml.namespace.QName)9 Service (javax.wsdl.Service)7 SOAP12Address (javax.wsdl.extensions.soap12.SOAP12Address)7 Definition (javax.wsdl.Definition)5 Test (org.junit.Test)5 List (java.util.List)4 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)4 HTTPAddress (javax.wsdl.extensions.http.HTTPAddress)4 URL (java.net.URL)3 Iterator (java.util.Iterator)3 Binding (javax.wsdl.Binding)3 File (java.io.File)2 Map (java.util.Map)2 BindingOperation (javax.wsdl.BindingOperation)2 UnknownExtensibilityElement (javax.wsdl.extensions.UnknownExtensibilityElement)2 SOAPBinding (javax.wsdl.extensions.soap.SOAPBinding)2 SOAPOperation (javax.wsdl.extensions.soap.SOAPOperation)2 ToolException (org.apache.cxf.tools.common.ToolException)2