Search in sources :

Example 6 with JaxWSHeaderContextProcessor

use of com.arjuna.mw.wst11.client.JaxWSHeaderContextProcessor in project quickstart by wildfly.

the class WSATSimpleServletClient method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    /*
         * Add client handler chain
         */
    BindingProvider bindingProvider = (BindingProvider) client;
    @SuppressWarnings("rawtypes") List<Handler> handlers = new ArrayList<>(1);
    handlers.add(new JaxWSHeaderContextProcessor());
    bindingProvider.getBinding().setHandlerChain(handlers);
    /*
         * Lookup the DNS name of the server from the environment and set the endpoint address on the client.
         */
    String openshift = System.getenv("OPENSHIFT_APP_DNS");
    if (openshift != null) {
        bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://" + openshift + "/RestaurantServiceAT");
    }
    resp.setContentType("text/html");
    PrintWriter out = resp.getWriter();
    out.write("<h1>Quickstart: This example demonstrates the deployment of a WS-AT (WS-AtomicTransaction) enabled JAX-WS Web service bundled in a war archive for deployment to *Red Hat JBoss Enterprise Application Platform*.</h1>");
    System.out.println("[CLIENT] Creating a new WS-AT User Transaction");
    UserTransaction ut = UserTransactionFactory.userTransaction();
    try {
        System.out.println("[CLIENT] Beginning Atomic Transaction (All calls to Web services that support WS-AT wil be included in this transaction)");
        ut.begin();
        System.out.println("[CLIENT] invoking makeBooking() on WS");
        client.makeBooking();
        System.out.println("[CLIENT] committing Atomic Transaction (This will cause the AT to complete successfully)");
        ut.commit();
        out.write("<p><b>Transaction succeeded!</b></p>");
    } catch (Exception e) {
        e.printStackTrace();
        out.write("<p><b>Transaction failed with the following error:</b></p>");
        out.write("<p><blockquote>");
        out.write(e.toString());
        out.write("</blockquote></p>");
    } finally {
        rollbackIfActive(ut);
        client.reset();
        out.write("<p><i>Go to your JBoss EAP Server console or log to see the detailed result of the transaction.</i></p>");
    }
}
Also used : UserTransaction(com.arjuna.mw.wst11.UserTransaction) JaxWSHeaderContextProcessor(com.arjuna.mw.wst11.client.JaxWSHeaderContextProcessor) ArrayList(java.util.ArrayList) Handler(javax.xml.ws.handler.Handler) BindingProvider(javax.xml.ws.BindingProvider) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Aggregations

JaxWSHeaderContextProcessor (com.arjuna.mw.wst11.client.JaxWSHeaderContextProcessor)6 ArrayList (java.util.ArrayList)6 BindingProvider (javax.xml.ws.BindingProvider)6 Handler (javax.xml.ws.handler.Handler)6 Service (javax.xml.ws.Service)5 URL (java.net.URL)4 IOException (java.io.IOException)3 ServletException (javax.servlet.ServletException)3 UnknownHostException (java.net.UnknownHostException)2 QName (javax.xml.namespace.QName)2 JaxWSTxOutboundBridgeHandler (org.jboss.jbossts.txbridge.outbound.JaxWSTxOutboundBridgeHandler)2 RollbackException (com.arjuna.ats.jta.exceptions.RollbackException)1 UserTransaction (com.arjuna.mw.wst11.UserTransaction)1 TransactionRolledBackException (com.arjuna.wst.TransactionRolledBackException)1 PrintWriter (java.io.PrintWriter)1 Context (javax.naming.Context)1 InitialContext (javax.naming.InitialContext)1 ServletContext (javax.servlet.ServletContext)1