Metro is the Web services stack in GlassFish. It is your one-stop shop from a simple Hello World to Secure, Reliable, Transactional and .NET 3.0 interoperable endpoint. Metro Tooling is provided by NetBeans and other options are explained here. Screencast #ws7 describes how a Metro endpoint can be easily created and deployed on GlassFish and invoked from a Web client using NetBeans IDE. This TOTD (as requested here and here) describes how a Secure and Reliable Metro endpoint can be invoked using a Java SE client. Here is my environment: Windows Vista NetBeans 6 GlassFish v2 (downloaded from glassfish.java.net and configured in NetBeans). Java SE 1.6.0 U4 Let’s get started. Following screencast #ws7 create a plain (without Reliability and Security enabled) Metro endpoint. Create the Java SE client project In NetBeans IDE, create a new project of the type Java/Java Application. Name the project as “SEClient” and take all other defaults. Right-click on the newly created project, select “New“, “Web Service Client...“. Click on the “Browse...” button next to “Project” radio button and select the deployed Web service endpoint. Enter the package name as “client” and click on “Finish“. Invoke the plain Metro endpoint Right-click on the project, select “Properties“, “Libraries“, “Add JAR/Folder” and add “webservices-rt.jar” from the “lib” directory of GlassFish installation. Click on “OK“. Expand the “Web Service References” node in the project and drag the leaf node in the “main” method of “Main.java” of the client project. Change the value of parameter “name” to “Duke“. Right-click the project and select “Run“. This will build the project, invoke the endpoint and show the results in Output window as “Hello Duke“. If your GlassFish instance is configured to show SOAP messages then the following SOAP messages will be shown in the output window:====[com.sun.xml.ws.assembler.server:request]====<br> <?xml version="1.0" ?><br> <S:Envelope xmlns:S="<a href="https://schemas.xmlsoap.org/soap/envelope/">https://schemas.xmlsoap.org/soap/envelope/</a>"><br> <S:Body><br> <ns2:sayHello xmlns:ns2="<a href="https://server/">https://server/</a>"><br> <name>Duke</name><br> </ns2:sayHello><br> </S:Body><br> </S:Envelope><br> ============<br> ====[com.sun.xml.ws.assembler.server:response]====<br> <?xml version="1.0" ?><br> <S:Envelope xmlns:S="<a href="https://schemas.xmlsoap.org/soap/envelope/">https://schemas.xmlsoap.org/soap/envelope/</a>"><br> <S:Body><br> <ns2:sayHelloResponse xmlns:ns2="<a href="https://server/">https://server/</a>"><br> <return>Hello Duke</return><br> </ns2:sayHelloResponse><br> </S:Body><br> </S:Envelope><br> ============ Invoke the Reliable Metro endpoint Following the instructions in screencast #ws7, enable Reliability on Metro endpoint and re-deploy. In the client project, select the first child node of “Web Service References“, right-click and select “Refresh Client“. In the “Confirm Client Refresh” window, select “Also replace local wsdl file with original WSDLs located at:” checkbox and click on “Yes“. Right-click the client project and select “Run“. This will build the project, invoke the endpoint and show the results in Output window as “Hello Duke“. The SOAP messages during this run will now contain Reliable Messaging protocol messages and resemble as shown below:====[com.sun.xml.ws.assembler.server:request]====<br> <?xml version="1.0" ?><br> <S:Envelope xmlns:S="<a href="https://schemas.xmlsoap.org/soap/envelope/">https://schemas.xmlsoap.org/soap/envelope/</a>"><br> <S:Header><br> <To xmlns="<a href="https://www.w3.org/2005/08/addressing">https://www.w3.org/2005/08/addressing</a>"><a href="https://localhost:8080/SEEndpoint/HelloServiceService">https://localhost:8080/SEEndpoint/HelloServiceService</a></To><br> <Action xmlns="<a href="https://www.w3.org/2005/08/addressing">https://www.w3.org/2005/08/addressing</a>"><a href="https://schemas.xmlsoap.org/ws/2005/02/rm/CreateSequence">https://schemas.xmlsoap.org/ws/2005/02/rm/CreateSequence</a></Action><br> <ReplyTo xmlns="<a href="https://www.w3.org/2005/08/addressing">https://www.w3.org/2005/08/addressing</a>"><br> <Address><a href="https://www.w3.org/2005/08/addressing/anonymous">https://www.w3.org/2005/08/addressing/anonymous</a></Address><br> </ReplyTo><br> ... Invoke the Secure Metro endpoint Following the instructions in screencast #ws7, disable Reliability and enable Security on Metro endpoint and re-deploy. In the client project, select the first child node of “Web Service References“, right-click and select “Refresh Client“. In the “Confirm Client Refresh” window, select “Also replace local wsdl file with original WSDLs located at:” checkbox and click on “Yes“. Right-click on the first child of “Web Service References” node, select “Edit Web Service Attributes” and select “Use development defaults“. This will ensure that client and endpoint security credentials match. Expand “Source Packages“, “META-INF” and open “HelloServiceService.xml“. The name of this file is derived from the service name at the endpoint and may be different. Specify the location of trust store by adding the following attributes to “sc:KeyStore” element:location="C:testbedglassfishfinalglassfishdomainsdomain1configcacerts.jks" type="JKS" storepass="changeit" The updated element looks like:<sc:TrustStore wspp:visibility="private" peeralias="xws-security-server" location="C:testbedglassfishfinalglassfishdomainsdomain1configcacerts.jks" type="JKS" storepass="changeit"/> Make sure to match the value of location and password of the trust store in your environment. Right-click the client project and select “Run“. This will build the project, invoke the endpoint and show the results in Output window as “Hello Duke“. The SOAP messages during this run are now secured using the default security profile in NetBeans. The SOAP messages resemble as shown below:====[com.sun.xml.ws.assembler.server:request]====<br> <?xml version="1.0" ?><br> <S:Envelope<br> xmlns:S="<a href="https://schemas.xmlsoap.org/soap/envelope/">https://schemas.xmlsoap.org/soap/envelope/</a>"<br> xmlns:wsse="<a href="https://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secex...</a>"<br> xmlns:wsu="<a href="https://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utili...</a>"<br> xmlns:ds="<a href="https://www.w3.org/2000/09/xmldsig#">https://www.w3.org/2000/09/xmldsig#</a>" xmlns:xenc="<a href="https://www.w3.org/2001/04/xmlenc#">https://www.w3.org/2001/04/xmlenc#</a>"<br> xmlns:exc14n="<a href="https://www.w3.org/2001/10/xml-exc-c14n#">https://www.w3.org/2001/10/xml-exc-c14n#</a>"><br> <S:Header><br> <To xmlns="<a href="https://www.w3.org/2005/08/addressing">https://www.w3.org/2005/08/addressing</a>" wsu:Id="5006"><a href="https://localhost:8080/SEEndpoint/HelloServiceService">https://localhost:8080/SEEndpoint/HelloServiceService</a></To><br> <Action xmlns="<a href="https://www.w3.org/2005/08/addressing">https://www.w3.org/2005/08/addressing</a>" wsu:Id="5005"><a href="https://server/HelloService/sayHelloRequest">https://server/HelloService/sayHelloRequest</a></Action><br> <ReplyTo xmlns="<a href="https://www.w3.org/2005/08/addressing">https://www.w3.org/2005/08/addressing</a>" wsu:Id="5004"><br> <Address><a href="https://www.w3.org/2005/08/addressing/anonymous">https://www.w3.org/2005/08/addressing/anonymous</a></Address><br> </ReplyTo><br> <MessageID xmlns="<a href="https://www.w3.org/2005/08/addressing">https://www.w3.org/2005/08/addressing</a>" wsu:Id="5003">uuid:bb0e9571-a773-49bb-bad0-20a01d3af9f1</MessageID><br> <wsse:Security S:mustUnderstand="1"><br> <wsu:Timestamp xmlns:ns10="<a href="https://www.w3.org/2003/05/soap-envelope">https://www.w3.org/2003/05/soap-envelope</a>" wsu:Id="3"><br> <wsu:Created>2008-01-23T20:13:28Z</wsu:Created><br> ... If you are using JDK version prior to Java SE 6 U4, then need to override the JAX-WS and JAXB API as described here. Java SE 6 U4 already includes JAX-WS and JAXB 2.1 APIs which are required for the Metro client to work.Please leave suggestions on other TOTD that you’d like to see. A complete archive is available here. Technorati: totd webservices metro glassfish netbeans javase Web Development