Search in sources :

Example 16 with MemberSubmissionEndpointReference

use of com.sun.xml.ws.developer.MemberSubmissionEndpointReference in project metro-jax-ws by eclipse-ee4j.

the class AddNumbersClient method testCreateDispatchSMWsdlMSEPRNoPortQName.

public void testCreateDispatchSMWsdlMSEPRNoPortQName() throws Exception {
    if (ClientServerTestUtil.useLocal()) {
        System.out.println("HTTP Transport Only Exiting");
        return;
    }
    RespectBindingFeature rbf = new RespectBindingFeature(false);
    WebServiceFeature[] wse = new WebServiceFeature[] { rbf };
    Service service = createServiceWithWSDL();
    MemberSubmissionEndpointReference msEPR = createMSEPRStubServiceWithWSDL(service);
    msEPR.portTypeName.name = null;
    MSEPRString = msEPR.toString();
    Dispatch<SOAPMessage> dispatch = service.createDispatch(EndpointReference.readFrom(makeStreamSource(MSEPRString)), SOAPMessage.class, Service.Mode.MESSAGE, wse);
    SOAPMessage sm = dispatch.invoke(getSOAPMessage(makeStreamSource(SMMsg)));
    sm.writeTo(System.out);
// System.out.println("Adding numbers 2 and 4");
// int result = dispatch.invoke(getSOAPMessage())
// assert(result == 6);
// System.out.println("Addinion of 2 and 4 successful");
}
Also used : MemberSubmissionEndpointReference(com.sun.xml.ws.developer.MemberSubmissionEndpointReference) SOAPMessage(jakarta.xml.soap.SOAPMessage)

Example 17 with MemberSubmissionEndpointReference

use of com.sun.xml.ws.developer.MemberSubmissionEndpointReference in project metro-jax-ws by eclipse-ee4j.

the class EndpointReferenceUtil method toMSEpr.

// private static void writeW3CMetadata(StreamWriterBufferCreator writer) throws XMLStreamException {
// if (!w3cMetadataWritten) {
// writer.writeStartElement(AddressingVersion.W3C.getPrefix(), AddressingVersion.W3C.eprType.wsdlMetadata.getLocalPart(), AddressingVersion.W3C.nsUri);
// w3cMetadataWritten = true;
// }
// }
// 
private static MemberSubmissionEndpointReference toMSEpr(W3CEndpointReference w3cEpr) {
    DOMResult result = new DOMResult();
    w3cEpr.writeTo(result);
    Node eprNode = result.getNode();
    Element e = DOMUtil.getFirstElementChild(eprNode);
    if (e == null) {
        return null;
    }
    MemberSubmissionEndpointReference msEpr = new MemberSubmissionEndpointReference();
    NodeList nodes = e.getChildNodes();
    for (int i = 0; i < nodes.getLength(); i++) {
        if (nodes.item(i).getNodeType() == Node.ELEMENT_NODE) {
            Element child = (Element) nodes.item(i);
            if (child.getNamespaceURI().equals(AddressingVersion.W3C.nsUri) && child.getLocalName().equals(AddressingVersion.W3C.eprType.address)) {
                if (msEpr.addr == null) {
                    msEpr.addr = new MemberSubmissionEndpointReference.Address();
                }
                msEpr.addr.uri = XmlUtil.getTextForNode(child);
            } else if (child.getNamespaceURI().equals(AddressingVersion.W3C.nsUri) && child.getLocalName().equals("ReferenceParameters")) {
                NodeList refParams = child.getChildNodes();
                for (int j = 0; j < refParams.getLength(); j++) {
                    if (refParams.item(j).getNodeType() == Node.ELEMENT_NODE) {
                        if (msEpr.referenceParameters == null) {
                            msEpr.referenceParameters = new MemberSubmissionEndpointReference.Elements();
                            msEpr.referenceParameters.elements = new ArrayList<>();
                        }
                        msEpr.referenceParameters.elements.add((Element) refParams.item(j));
                    }
                }
            } else if (child.getNamespaceURI().equals(AddressingVersion.W3C.nsUri) && child.getLocalName().equals(AddressingVersion.W3C.eprType.wsdlMetadata.getLocalPart())) {
                NodeList metadata = child.getChildNodes();
                String wsdlLocation = child.getAttributeNS(W3CAddressingMetadataConstants.WSAM_WSDLI_ATTRIBUTE_NAMESPACE, W3CAddressingMetadataConstants.WSAM_WSDLI_ATTRIBUTE_LOCALNAME);
                Element wsdlDefinitions = null;
                for (int j = 0; j < metadata.getLength(); j++) {
                    Node node = metadata.item(j);
                    if (node.getNodeType() != Node.ELEMENT_NODE) {
                        continue;
                    }
                    Element elm = (Element) node;
                    if ((elm.getNamespaceURI().equals(AddressingVersion.W3C.wsdlNsUri) || elm.getNamespaceURI().equals(W3CAddressingMetadataConstants.WSAM_NAMESPACE_NAME)) && elm.getLocalName().equals(AddressingVersion.W3C.eprType.serviceName)) {
                        msEpr.serviceName = new MemberSubmissionEndpointReference.ServiceNameType();
                        msEpr.serviceName.portName = elm.getAttribute(AddressingVersion.W3C.eprType.portName);
                        String service = elm.getTextContent();
                        String prefix = XmlUtil.getPrefix(service);
                        String name = XmlUtil.getLocalPart(service);
                        // if there is no service name then its not a valid EPR but lets continue as its optional anyway
                        if (name == null) {
                            continue;
                        }
                        if (prefix != null) {
                            String ns = elm.lookupNamespaceURI(prefix);
                            if (ns != null) {
                                msEpr.serviceName.name = new QName(ns, name, prefix);
                            }
                        } else {
                            msEpr.serviceName.name = new QName(null, name);
                        }
                        msEpr.serviceName.attributes = getAttributes(elm);
                    } else if ((elm.getNamespaceURI().equals(AddressingVersion.W3C.wsdlNsUri) || elm.getNamespaceURI().equals(W3CAddressingMetadataConstants.WSAM_NAMESPACE_NAME)) && elm.getLocalName().equals(AddressingVersion.W3C.eprType.portTypeName)) {
                        msEpr.portTypeName = new MemberSubmissionEndpointReference.AttributedQName();
                        String portType = elm.getTextContent();
                        String prefix = XmlUtil.getPrefix(portType);
                        String name = XmlUtil.getLocalPart(portType);
                        // if there is no portType name then its not a valid EPR but lets continue as its optional anyway
                        if (name == null) {
                            continue;
                        }
                        if (prefix != null) {
                            String ns = elm.lookupNamespaceURI(prefix);
                            if (ns != null) {
                                msEpr.portTypeName.name = new QName(ns, name, prefix);
                            }
                        } else {
                            msEpr.portTypeName.name = new QName(null, name);
                        }
                        msEpr.portTypeName.attributes = getAttributes(elm);
                    } else if (elm.getNamespaceURI().equals(WSDLConstants.NS_WSDL) && elm.getLocalName().equals(WSDLConstants.QNAME_DEFINITIONS.getLocalPart())) {
                        wsdlDefinitions = elm;
                    } else {
                        // its extensions in META-DATA and should be copied to extensions in MS EPR
                        if (msEpr.elements == null) {
                            msEpr.elements = new ArrayList<>();
                        }
                        msEpr.elements.add(elm);
                    }
                }
                Document doc = DOMUtil.createDom();
                Element mexEl = doc.createElementNS(MemberSubmissionAddressingConstants.MEX_METADATA.getNamespaceURI(), MemberSubmissionAddressingConstants.MEX_METADATA.getPrefix() + ":" + MemberSubmissionAddressingConstants.MEX_METADATA.getLocalPart());
                Element metadataEl = doc.createElementNS(MemberSubmissionAddressingConstants.MEX_METADATA_SECTION.getNamespaceURI(), MemberSubmissionAddressingConstants.MEX_METADATA_SECTION.getPrefix() + ":" + MemberSubmissionAddressingConstants.MEX_METADATA_SECTION.getLocalPart());
                metadataEl.setAttribute(MemberSubmissionAddressingConstants.MEX_METADATA_DIALECT_ATTRIBUTE, MemberSubmissionAddressingConstants.MEX_METADATA_DIALECT_VALUE);
                if (wsdlDefinitions == null && wsdlLocation != null && !wsdlLocation.equals("")) {
                    wsdlLocation = wsdlLocation.trim();
                    String wsdlTns = wsdlLocation.substring(0, wsdlLocation.indexOf(' '));
                    wsdlLocation = wsdlLocation.substring(wsdlLocation.indexOf(' ') + 1);
                    Element wsdlEl = doc.createElementNS(WSDLConstants.NS_WSDL, WSDLConstants.PREFIX_NS_WSDL + ":" + WSDLConstants.QNAME_DEFINITIONS.getLocalPart());
                    Element wsdlImportEl = doc.createElementNS(WSDLConstants.NS_WSDL, WSDLConstants.PREFIX_NS_WSDL + ":" + WSDLConstants.QNAME_IMPORT.getLocalPart());
                    wsdlImportEl.setAttribute("namespace", wsdlTns);
                    wsdlImportEl.setAttribute("location", wsdlLocation);
                    wsdlEl.appendChild(wsdlImportEl);
                    metadataEl.appendChild(wsdlEl);
                } else if (wsdlDefinitions != null) {
                    metadataEl.appendChild(wsdlDefinitions);
                }
                mexEl.appendChild(metadataEl);
                if (msEpr.elements == null) {
                    msEpr.elements = new ArrayList<>();
                }
                msEpr.elements.add(mexEl);
            } else {
                // its extensions
                if (msEpr.elements == null) {
                    msEpr.elements = new ArrayList<>();
                }
                msEpr.elements.add(child);
            }
        } else if (nodes.item(i).getNodeType() == Node.ATTRIBUTE_NODE) {
            Node n = nodes.item(i);
            if (msEpr.attributes == null) {
                msEpr.attributes = new HashMap<>();
                String prefix = fixNull(n.getPrefix());
                String ns = fixNull(n.getNamespaceURI());
                String localName = n.getLocalName();
                msEpr.attributes.put(new QName(ns, localName, prefix), n.getNodeValue());
            }
        }
    }
    return msEpr;
}
Also used : DOMResult(javax.xml.transform.dom.DOMResult) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) MemberSubmissionEndpointReference(com.sun.xml.ws.developer.MemberSubmissionEndpointReference)

Example 18 with MemberSubmissionEndpointReference

use of com.sun.xml.ws.developer.MemberSubmissionEndpointReference in project metro-jax-ws by eclipse-ee4j.

the class EndpointEPRTester method testProviderEndpointMSCEPR_WSDL.

public void testProviderEndpointMSCEPR_WSDL() throws Exception {
    int port = Util.getFreePort();
    String address = "http://127.0.0.1:" + port + "/";
    Endpoint e = Endpoint.create(HTTPBinding.HTTP_BINDING, new MyProvider());
    List<Source> metadata = new ArrayList<Source>();
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    String[] docs = { "WEB-INF/wsdl/RpcLitEndpoint.wsdl", "WEB-INF/wsdl/RpcLitAbstract.wsdl", "WEB-INF/wsdl/RpcLitEndpoint.xsd" };
    for (String doc : docs) {
        URL url = cl.getResource(doc);
        metadata.add(new StreamSource(url.openStream(), url.toExternalForm()));
    }
    e.setMetadata(metadata);
    Map<String, Object> endpointProps = new HashMap<String, Object>();
    endpointProps.put(Endpoint.WSDL_SERVICE, new QName("http://echo.org/", "RpcLitEndpoint"));
    endpointProps.put(Endpoint.WSDL_PORT, new QName("http://echo.org/", "RpcLitPort"));
    e.setProperties(endpointProps);
    e.publish(address);
    MemberSubmissionEndpointReference epr = e.getEndpointReference(MemberSubmissionEndpointReference.class);
    e.stop();
    EprUtil.validateEPR(epr, address, serviceName, portName, portTypeName, Boolean.TRUE);
    printEPR(epr);
}
Also used : HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) StreamSource(javax.xml.transform.stream.StreamSource) ArrayList(java.util.ArrayList) Endpoint(jakarta.xml.ws.Endpoint) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) URL(java.net.URL) Endpoint(jakarta.xml.ws.Endpoint) MemberSubmissionEndpointReference(com.sun.xml.ws.developer.MemberSubmissionEndpointReference)

Example 19 with MemberSubmissionEndpointReference

use of com.sun.xml.ws.developer.MemberSubmissionEndpointReference in project metro-jax-ws by eclipse-ee4j.

the class EndpointEPRTester method testProviderEndpointMSCEPR.

public void testProviderEndpointMSCEPR() {
    int port = Util.getFreePort();
    String address = "http://127.0.0.1:" + port + "/";
    Endpoint e = Endpoint.create(HTTPBinding.HTTP_BINDING, new MyProvider());
    e.publish(address);
    MemberSubmissionEndpointReference epr = e.getEndpointReference(MemberSubmissionEndpointReference.class);
    e.stop();
    EprUtil.validateEPR(epr, address, null, null, null, Boolean.FALSE);
    printEPR(epr);
}
Also used : Endpoint(jakarta.xml.ws.Endpoint) MemberSubmissionEndpointReference(com.sun.xml.ws.developer.MemberSubmissionEndpointReference) Endpoint(jakarta.xml.ws.Endpoint)

Example 20 with MemberSubmissionEndpointReference

use of com.sun.xml.ws.developer.MemberSubmissionEndpointReference in project metro-jax-ws by eclipse-ee4j.

the class ClientEpr method msEprGettertest.

private void msEprGettertest(BindingProvider bp, boolean hasWSDL) throws Exception {
    Service service = Service.create(serviceName);
    service.addPort(portName, jakarta.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);
    Dispatch dispatch = service.createDispatch(portName, Source.class, Service.Mode.PAYLOAD);
    // validate ms epr
    MemberSubmissionEndpointReference msEpr = bp.getEndpointReference(MemberSubmissionEndpointReference.class);
    // printEPR(msEpr);
    assertTrue(EprUtil.validateEPR(msEpr, endpointAddress, serviceName, portName, portTypeName, hasWSDL));
    W3CEndpointReference w3cEpr = bp.getEndpointReference(W3CEndpointReference.class);
    // printEPR(w3cEpr);
    // assertTrue(EprUtil.validateEPR(w3cEpr,endpointAddress, serviceName, portName, portTypeName, hasWSDL));
    assertTrue(EprUtil.validateEPR(w3cEpr, endpointAddress, null, null, null, false));
}
Also used : W3CEndpointReference(jakarta.xml.ws.wsaddressing.W3CEndpointReference) Service(jakarta.xml.ws.Service) Dispatch(jakarta.xml.ws.Dispatch) MemberSubmissionEndpointReference(com.sun.xml.ws.developer.MemberSubmissionEndpointReference)

Aggregations

MemberSubmissionEndpointReference (com.sun.xml.ws.developer.MemberSubmissionEndpointReference)31 W3CEndpointReference (jakarta.xml.ws.wsaddressing.W3CEndpointReference)13 WSEndpointReference (com.sun.xml.ws.api.addressing.WSEndpointReference)8 Element (org.w3c.dom.Element)7 Endpoint (jakarta.xml.ws.Endpoint)6 EndpointReference (jakarta.xml.ws.EndpointReference)6 W3CEndpointReferenceBuilder (jakarta.xml.ws.wsaddressing.W3CEndpointReferenceBuilder)6 URL (java.net.URL)6 ArrayList (java.util.ArrayList)6 DocumentBuilder (javax.xml.parsers.DocumentBuilder)6 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)6 Source (javax.xml.transform.Source)6 Document (org.w3c.dom.Document)6 StreamSource (javax.xml.transform.stream.StreamSource)5 JAXBElement (jakarta.xml.bind.JAXBElement)4 HashMap (java.util.HashMap)3 QName (javax.xml.namespace.QName)3 DOMResult (javax.xml.transform.dom.DOMResult)3 MemberSubmissionAddressingFeature (com.sun.xml.ws.developer.MemberSubmissionAddressingFeature)2 JAXBContext (jakarta.xml.bind.JAXBContext)2