Search in sources :

Example 1 with W3CEndpointReference

use of jakarta.xml.ws.wsaddressing.W3CEndpointReference in project metro-jax-ws by eclipse-ee4j.

the class Main method main.

public static void main(String[] args) {
    BookStore bookstore = new BookStoreService().getBookStorePort();
    BookService service = new BookService();
    // obtain two book references
    Book book1 = service.getPort(bookstore.getProduct("abc001"), Book.class);
    Book book2 = service.getPort(bookstore.getProduct("def999"), Book.class);
    // you'll see that two proxies do represent two different server objects
    System.out.println("--- testing ID ---");
    System.out.println(book1.getId());
    System.out.println(book2.getId());
    // and as you see the server can maintain state on each book.
    // also notice that when you run the application repeatedly, the reviews accumulate.
    book1.postReview("This book is great!");
    book2.postReview("Recommend only for people with too much time");
    System.out.println("--- testing review ---");
    System.out.println(book1.getReviews());
    System.out.println(book2.getReviews());
    // if you obtain the 2nd reference to the same book, it still points to the same book
    Book book3 = service.getPort(bookstore.getProduct("abc001"), Book.class);
    System.out.println(book3.getReviews());
    // ... now we are done with basics, and moving on to a little more advanced topic.
    // on the wire, a reference to a remote object is captured
    // in an XML fragment called 'EndpointReference'.
    W3CEndpointReference bookEpr = bookstore.getProduct("def999");
    // since this is just an XML, you can save it to anywhere.
    // the following shows how to "save" it to System.out (so that you can see what's in it,
    // even though you don't really need to know what's in there)
    System.out.println("--- testing EPR ---");
    bookEpr.writeTo(new StreamResult(System.out));
    System.out.println();
    // let's save it to byte array
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bookEpr.writeTo(new StreamResult(baos));
    // it can be then read back to EPR later, maybe even from another JVM
    bookEpr = new W3CEndpointReference(new StreamSource(new ByteArrayInputStream(baos.toByteArray())));
    // ... and then to Book proxy
    Book book4 = service.getPort(bookEpr, Book.class);
    // ... to talk to this book
    System.out.println(book4.getReviews());
}
Also used : StreamResult(javax.xml.transform.stream.StreamResult) ByteArrayInputStream(java.io.ByteArrayInputStream) W3CEndpointReference(jakarta.xml.ws.wsaddressing.W3CEndpointReference) StreamSource(javax.xml.transform.stream.StreamSource) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 2 with W3CEndpointReference

use of jakarta.xml.ws.wsaddressing.W3CEndpointReference in project metro-jax-ws by eclipse-ee4j.

the class EndpointEPRTest method testProviderEndpointW3CEPR.

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

Example 3 with W3CEndpointReference

use of jakarta.xml.ws.wsaddressing.W3CEndpointReference in project metro-jax-ws by eclipse-ee4j.

the class EndpointEPRTest method testProviderEndpointW3CEPR_WSDL.

public void testProviderEndpointW3CEPR_WSDL() throws Exception {
    int port = PortAllocator.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 = { "RpcLitEndpoint.wsdl", "RpcLitAbstract.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);
    W3CEndpointReference epr = e.getEndpointReference(W3CEndpointReference.class);
    e.stop();
    // EprUtil.validateEPR(epr, address, serviceName, portName, portTypeName, Boolean.TRUE );
    EprUtil.validateEPR(epr, address, null, null, null, false);
    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) W3CEndpointReference(jakarta.xml.ws.wsaddressing.W3CEndpointReference)

Example 4 with W3CEndpointReference

use of jakarta.xml.ws.wsaddressing.W3CEndpointReference in project metro-jax-ws by eclipse-ee4j.

the class ClientEprTest method w3cEprGettertest.

private void w3cEprGettertest(BindingProvider bp, boolean hasWSDL) throws Exception {
    // validate w3c epr
    W3CEndpointReference w3cEpr = (W3CEndpointReference) bp.getEndpointReference();
    // printEPR(w3cEpr);
    // assertTrue(EprUtil.validateEPR(w3cEpr,endpointAddress, serviceName, portName, portTypeName, hasWSDL));
    assertTrue(EprUtil.validateEPR(w3cEpr, endpointAddress, null, null, null, false));
    // validate ms epr
    MemberSubmissionEndpointReference msEpr = bp.getEndpointReference(MemberSubmissionEndpointReference.class);
    // printEPR(msEpr);
    assertTrue(EprUtil.validateEPR(msEpr, endpointAddress, serviceName, portName, portTypeName, hasWSDL));
}
Also used : W3CEndpointReference(jakarta.xml.ws.wsaddressing.W3CEndpointReference) MemberSubmissionEndpointReference(com.sun.xml.ws.developer.MemberSubmissionEndpointReference)

Example 5 with W3CEndpointReference

use of jakarta.xml.ws.wsaddressing.W3CEndpointReference in project metro-jax-ws by eclipse-ee4j.

the class EprMarshalUnmarshalTest method testW3CEPRBuilder.

public void testW3CEPRBuilder() throws Exception {
    try {
        String xmlParam1 = "<myns:MyParam1 xmlns:myns=\"http://cptestservice.org/wsdl\">Hello</myns:MyParam1>";
        Node n1 = DOMUtil.createDOMNode(new ByteArrayInputStream(xmlParam1.getBytes()));
        String metadata = "<myMetadata>This is not useful metadata</myMetadata>";
        Node n2 = createDOMNodeNoNS(new ByteArrayInputStream(metadata.getBytes()));
        W3CEndpointReferenceBuilder eprBuilder = new W3CEndpointReferenceBuilder();
        eprBuilder.address(endpointAddress);
        eprBuilder.referenceParameter((Element) n1.getFirstChild());
        eprBuilder.metadata((Element) n2.getFirstChild());
        W3CEndpointReference epr = eprBuilder.build();
        epr.writeTo(new StreamResult(System.out));
    } catch (Exception e) {
        e.printStackTrace();
        assertTrue(false);
    }
}
Also used : W3CEndpointReferenceBuilder(jakarta.xml.ws.wsaddressing.W3CEndpointReferenceBuilder) StreamResult(javax.xml.transform.stream.StreamResult) ByteArrayInputStream(java.io.ByteArrayInputStream) W3CEndpointReference(jakarta.xml.ws.wsaddressing.W3CEndpointReference) Node(org.w3c.dom.Node) IOException(java.io.IOException) JAXBException(jakarta.xml.bind.JAXBException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Aggregations

W3CEndpointReference (jakarta.xml.ws.wsaddressing.W3CEndpointReference)44 MemberSubmissionEndpointReference (com.sun.xml.ws.developer.MemberSubmissionEndpointReference)19 W3CEndpointReferenceBuilder (jakarta.xml.ws.wsaddressing.W3CEndpointReferenceBuilder)10 StreamResult (javax.xml.transform.stream.StreamResult)9 StreamSource (javax.xml.transform.stream.StreamSource)9 Endpoint (jakarta.xml.ws.Endpoint)6 WSEndpointReference (com.sun.xml.ws.api.addressing.WSEndpointReference)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 QName (javax.xml.namespace.QName)5 Source (javax.xml.transform.Source)5 DOMResult (javax.xml.transform.dom.DOMResult)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 URL (java.net.URL)4 ArrayList (java.util.ArrayList)4 Node (org.w3c.dom.Node)3 JAXBContext (jakarta.xml.bind.JAXBContext)2 JAXBException (jakarta.xml.bind.JAXBException)2 Marshaller (jakarta.xml.bind.Marshaller)2 JAXBResult (jakarta.xml.bind.util.JAXBResult)2 BindingProvider (jakarta.xml.ws.BindingProvider)2