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());
}
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);
}
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);
}
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));
}
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);
}
}
Aggregations