Search in sources :

Example 41 with WSEndpointReference

use of com.sun.xml.ws.api.addressing.WSEndpointReference in project metro-jax-ws by eclipse-ee4j.

the class EPRWriteNReadTest method verifyEPR.

private static void verifyEPR(WSEndpointReference wsepr) throws Exception {
    ByteArrayBuffer bytebuffer = new ByteArrayBuffer();
    XMLStreamWriter w = XMLOutputFactory.newInstance().createXMLStreamWriter(bytebuffer);
    System.out.println("----------------------------------------------------------------------");
    w.writeStartDocument();
    wsepr.writeTo("EndpointReference", w);
    w.writeEndDocument();
    System.out.println(bytebuffer.toString());
    // verify the validity of infoset by reading it as EPR back again
    EndpointReference epr = W3CEndpointReference.readFrom(new StreamSource(bytebuffer.newInputStream()));
    // Verify it good old way
    XMLStreamReader xsr = XMLInputFactory.newInstance().createXMLStreamReader(new StreamSource(bytebuffer.newInputStream()));
    QName q = new QName("http://schemas.xmlsoap.org/ws/2006/02/addressingidentity", "Identity");
    while (xsr.hasNext()) {
        xsr.next();
        if (xsr.getEventType() == XMLStreamConstants.START_ELEMENT && xsr.getLocalName().equals("Identity")) {
            assertEquals(q.getNamespaceURI(), xsr.getNamespaceURI());
        }
    }
}
Also used : QName(javax.xml.namespace.QName) StreamSource(javax.xml.transform.stream.StreamSource) ByteArrayBuffer(com.sun.xml.ws.util.ByteArrayBuffer) W3CEndpointReference(jakarta.xml.ws.wsaddressing.W3CEndpointReference) WSEndpointReference(com.sun.xml.ws.api.addressing.WSEndpointReference) EndpointReference(jakarta.xml.ws.EndpointReference)

Example 42 with WSEndpointReference

use of com.sun.xml.ws.api.addressing.WSEndpointReference in project metro-jax-ws by eclipse-ee4j.

the class EPRWriteNReadTest method test3.

public void test3() throws Exception {
    URL fileurl = getResource("hello_literal_identity3.wsdl");
    WSDLModel doc = RuntimeWSDLParser.parse(fileurl, new StreamSource(fileurl.toExternalForm()), getResolver(), true, null);
    WSDLService service = doc.getService(new QName("urn:test", "Hello2"));
    WSDLPort port = service.getFirstPort();
    WSEndpointReference wsepr = port.getExtension(WSEndpointReference.class);
    verifyEPR(wsepr);
}
Also used : QName(javax.xml.namespace.QName) StreamSource(javax.xml.transform.stream.StreamSource) WSEndpointReference(com.sun.xml.ws.api.addressing.WSEndpointReference) URL(java.net.URL)

Example 43 with WSEndpointReference

use of com.sun.xml.ws.api.addressing.WSEndpointReference in project metro-jax-ws by eclipse-ee4j.

the class EPRinWsdlPortTest method test1.

public void test1() throws Exception {
    URL fileurl = getResource("hello_literal_identity.wsdl");
    WSDLModel doc = RuntimeWSDLParser.parse(fileurl, new StreamSource(fileurl.toExternalForm()), getResolver(), true, null);
    WSDLService service = doc.getService(new QName("urn:test", "Hello"));
    WSDLPort port = service.getFirstPort();
    WSEndpointReference wsepr = port.getExtension(WSEndpointReference.class);
    QName q = new QName("http://schemas.xmlsoap.org/ws/2006/02/addressingidentity", "Identity");
    WSEndpointReference.EPRExtension eprExtn = wsepr.getEPRExtension(q);
    XMLStreamReader xsr = eprExtn.readAsXMLStreamReader();
    if (xsr.getEventType() == XMLStreamConstants.START_DOCUMENT)
        xsr.next();
    assertEquals(q.getNamespaceURI(), xsr.getNamespaceURI());
    assertEquals(q.getLocalPart(), xsr.getLocalName());
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) QName(javax.xml.namespace.QName) StreamSource(javax.xml.transform.stream.StreamSource) WSEndpointReference(com.sun.xml.ws.api.addressing.WSEndpointReference) URL(java.net.URL)

Example 44 with WSEndpointReference

use of com.sun.xml.ws.api.addressing.WSEndpointReference in project metro-jax-ws by eclipse-ee4j.

the class ProviderImpl method createW3CEndpointReference.

public W3CEndpointReference createW3CEndpointReference(String address, QName interfaceName, QName serviceName, QName portName, List<Element> metadata, String wsdlDocumentLocation, List<Element> referenceParameters, List<Element> elements, Map<QName, String> attributes) {
    Container container = ContainerResolver.getInstance().getContainer();
    if (address == null) {
        if (serviceName == null || portName == null) {
            throw new IllegalStateException(ProviderApiMessages.NULL_ADDRESS_SERVICE_ENDPOINT());
        } else {
            // check if it is run in a Java EE Container and if so, get address using serviceName and portName
            Module module = container.getSPI(Module.class);
            if (module != null) {
                List<BoundEndpoint> beList = module.getBoundEndpoints();
                for (BoundEndpoint be : beList) {
                    WSEndpoint wse = be.getEndpoint();
                    if (wse.getServiceName().equals(serviceName) && wse.getPortName().equals(portName)) {
                        try {
                            address = be.getAddress().toString();
                        } catch (WebServiceException e) {
                        // May be the container does n't support this
                        // just ignore the exception
                        }
                        break;
                    }
                }
            }
            // address is still null? may be its not run in a JavaEE Container
            if (address == null)
                throw new IllegalStateException(ProviderApiMessages.NULL_ADDRESS());
        }
    }
    if ((serviceName == null) && (portName != null)) {
        throw new IllegalStateException(ProviderApiMessages.NULL_SERVICE());
    }
    // Validate Service and Port in WSDL
    String wsdlTargetNamespace = null;
    if (wsdlDocumentLocation != null) {
        try {
            EntityResolver er = XmlUtil.createDefaultCatalogResolver();
            URL wsdlLoc = new URL(wsdlDocumentLocation);
            WSDLModel wsdlDoc = RuntimeWSDLParser.parse(wsdlLoc, new StreamSource(wsdlLoc.toExternalForm()), er, true, container, ServiceFinder.find(WSDLParserExtension.class).toArray());
            if (serviceName != null) {
                WSDLService wsdlService = wsdlDoc.getService(serviceName);
                if (wsdlService == null)
                    throw new IllegalStateException(ProviderApiMessages.NOTFOUND_SERVICE_IN_WSDL(serviceName, wsdlDocumentLocation));
                if (portName != null) {
                    WSDLPort wsdlPort = wsdlService.get(portName);
                    if (wsdlPort == null)
                        throw new IllegalStateException(ProviderApiMessages.NOTFOUND_PORT_IN_WSDL(portName, serviceName, wsdlDocumentLocation));
                }
                wsdlTargetNamespace = serviceName.getNamespaceURI();
            } else {
                QName firstService = wsdlDoc.getFirstServiceName();
                wsdlTargetNamespace = firstService.getNamespaceURI();
            }
        } catch (Exception e) {
            throw new IllegalStateException(ProviderApiMessages.ERROR_WSDL(wsdlDocumentLocation), e);
        }
    }
    // wcf3.0/3.5 rejected empty metadata element.
    if (metadata != null && metadata.size() == 0) {
        metadata = null;
    }
    return new WSEndpointReference(AddressingVersion.fromSpecClass(W3CEndpointReference.class), address, serviceName, portName, interfaceName, metadata, wsdlDocumentLocation, wsdlTargetNamespace, referenceParameters, elements, attributes).toSpec(W3CEndpointReference.class);
}
Also used : WebServiceException(jakarta.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) StreamSource(javax.xml.transform.stream.StreamSource) WSDLModel(com.sun.xml.ws.api.model.wsdl.WSDLModel) EntityResolver(org.xml.sax.EntityResolver) BoundEndpoint(com.sun.xml.ws.api.server.BoundEndpoint) URL(java.net.URL) WebServiceException(jakarta.xml.ws.WebServiceException) JAXBException(jakarta.xml.bind.JAXBException) WSDLPort(com.sun.xml.ws.api.model.wsdl.WSDLPort) Container(com.sun.xml.ws.api.server.Container) WSEndpoint(com.sun.xml.ws.api.server.WSEndpoint) WSEndpointReference(com.sun.xml.ws.api.addressing.WSEndpointReference) WSDLService(com.sun.xml.ws.api.model.wsdl.WSDLService) Module(com.sun.xml.ws.api.server.Module)

Example 45 with WSEndpointReference

use of com.sun.xml.ws.api.addressing.WSEndpointReference in project metro-jax-ws by eclipse-ee4j.

the class WSEndpointImpl method getEndpointReference.

@Override
public <T extends EndpointReference> T getEndpointReference(Class<T> clazz, String address, String wsdlAddress, List<Element> metadata, List<Element> referenceParameters) {
    QName portType = null;
    if (port != null) {
        portType = port.getBinding().getPortTypeName();
    }
    AddressingVersion av = AddressingVersion.fromSpecClass(clazz);
    return new WSEndpointReference(av, address, serviceName, portName, portType, metadata, wsdlAddress, referenceParameters, endpointReferenceExtensions.values(), null).toSpec(clazz);
}
Also used : AddressingVersion(com.sun.xml.ws.api.addressing.AddressingVersion) QName(javax.xml.namespace.QName) WSEndpointReference(com.sun.xml.ws.api.addressing.WSEndpointReference)

Aggregations

WSEndpointReference (com.sun.xml.ws.api.addressing.WSEndpointReference)80 QName (javax.xml.namespace.QName)32 Element (org.w3c.dom.Element)17 URL (java.net.URL)16 StreamSource (javax.xml.transform.stream.StreamSource)16 EndpointReference (jakarta.xml.ws.EndpointReference)13 WSBindingProvider (com.sun.xml.ws.developer.WSBindingProvider)11 SAAJMessage (com.sun.xml.ws.message.saaj.SAAJMessage)11 SOAPMessage (jakarta.xml.soap.SOAPMessage)11 Packet (com.sun.xml.ws.api.message.Packet)10 XMLStreamReader (javax.xml.stream.XMLStreamReader)10 Message (com.sun.xml.ws.api.message.Message)9 WebServiceException (jakarta.xml.ws.WebServiceException)9 MemberSubmissionEndpointReference (com.sun.xml.ws.developer.MemberSubmissionEndpointReference)8 ByteArrayInputStream (java.io.ByteArrayInputStream)8 WSDLPort (com.sun.xml.ws.api.model.wsdl.WSDLPort)6 MessageFactory (jakarta.xml.soap.MessageFactory)6 MimeHeaders (jakarta.xml.soap.MimeHeaders)6 Service (jakarta.xml.ws.Service)6 W3CEndpointReference (jakarta.xml.ws.wsaddressing.W3CEndpointReference)6