Author: saminda
Date: Mon Jun  9 04:26:27 2008
New Revision: 18216
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=18216

Log:


Modified:
   
branches/wsas/java/2.3/wsas/modules/samples/CommodityQuote/src/org/wso2/wsas/sample/commodityquote/client/Client.java

Modified: 
branches/wsas/java/2.3/wsas/modules/samples/CommodityQuote/src/org/wso2/wsas/sample/commodityquote/client/Client.java
URL: 
http://wso2.org/svn/browse/wso2/branches/wsas/java/2.3/wsas/modules/samples/CommodityQuote/src/org/wso2/wsas/sample/commodityquote/client/Client.java?rev=18216&r1=18215&r2=18216&view=diff
==============================================================================
--- 
branches/wsas/java/2.3/wsas/modules/samples/CommodityQuote/src/org/wso2/wsas/sample/commodityquote/client/Client.java
       (original)
+++ 
branches/wsas/java/2.3/wsas/modules/samples/CommodityQuote/src/org/wso2/wsas/sample/commodityquote/client/Client.java
       Mon Jun  9 04:26:27 2008
@@ -41,6 +41,10 @@
 import org.wso2.wsas.security.WSS4JUtil;
 import org.apache.ws.security.handler.WSHandlerConstants;
 import org.wso2.www.types.client.*;
+import org.wso2.mercury.util.MercuryClientConstants;
+import org.wso2.mercury.client.MercuryClient;
+import org.wso2.mercury.callback.MercuryErrorCallback;
+import org.wso2.mercury.exception.RMException;
 
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
@@ -61,7 +65,7 @@
     private static final String INVOCATION_TYPE_ASYNC = "async";
     private static final String INVOCATION_TYPE_SYNC = "sync";
     private static final String MODULE_SECURITY = "rampart";
-    private static final String MODULE_RM = "sandesha2";
+    private static final String MODULE_RM = "Mercury";
     private static String invocationType = null;
     private static String qosValue = null;
 
@@ -169,13 +173,13 @@
         }
 
         if (QOS_VALUE_RM.equals(qosValue)) {
-           try {
-                 configureRM();
-           }catch (AxisFault e) {
-              e.printStackTrace();
-           } catch (IOException e) {
-              e.printStackTrace();
-           }
+            try {
+                configureRM();
+            } catch (AxisFault e) {
+                e.printStackTrace();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
         }
 
         try {
@@ -270,8 +274,9 @@
             -1) {
             System.err.println(SECURITY_TOKEN_ERROR_STR);
         } else {
-            System.err.println("Security failure. Please refer to the 
CommodityQuote documentation " +
-                               "and configure the CommodityQuote service 
properly");
+            System.err
+                    .println("Security failure. Please refer to the 
CommodityQuote documentation " +
+                             "and configure the CommodityQuote service 
properly");
             e.printStackTrace();
         }
     }
@@ -301,26 +306,23 @@
     }
 
     private void configureRM() throws AxisFault, IOException {
-        stub._getServiceClient().engageModule(new QName(MODULE_RM));
-        stub._getServiceClient().engageModule(new QName(
-                org.apache.axis2.Constants.MODULE_ADDRESSING));
+        stub._getServiceClient().engageModule(MODULE_RM);
+        
stub._getServiceClient().engageModule(org.apache.axis2.Constants.MODULE_ADDRESSING);
 
         Options clientOptions = stub._getServiceClient().getOptions();
+        clientOptions.setUseSeparateListener(true);
 
+        clientOptions.setProperty(MercuryClientConstants.ERROR_CALLBACK,
+                                  new MercuryErrorCallbackImpl());
+        MercuryClient mercuryClient = new 
MercuryClient(stub._getServiceClient());
+        mercuryClient.setRMSSequenceRetransmitTime(5000);
+    }
 
-        String sequenceKey = UUIDGenerator.getUUID();  //sequence key for thie 
sequence.
-        clientOptions.setProperty(SandeshaClientConstants.SEQUENCE_KEY, 
sequenceKey);
-
-        clientOptions.setProperty(SandeshaClientConstants.SANDESHA_LISTENER,
-                                  new SandeshaListenerImpl());
-
-        clientOptions.setTransportInProtocol(Constants.TRANSPORT_HTTP);
-        clientOptions.setUseSeparateListener(true);
-        clientOptions.setProperty(SandeshaClientConstants.SANDESHA_LISTENER,
-                                  new SandeshaListenerImpl());
+    private static class MercuryErrorCallbackImpl implements 
MercuryErrorCallback {
 
-        String offeredSequenceId = UUIDGenerator.getUUID();
-        clientOptions.setProperty(SandeshaClientConstants.OFFERED_SEQUENCE_ID, 
offeredSequenceId);
+        public void onError(RMException rmException) {
+            System.out.println("ERROR: " + rmException.getMessage());
+        }
     }
 
     private void configureMail() throws AxisFault {
@@ -406,7 +408,8 @@
             epr.setAddress(serviceEPR);
             stub._getServiceClient().getOptions().setTo(epr);
             configureUtSec(stub, scenarioNumber);
-        } else if (scenarioNumber == 7 || scenarioNumber == 8 || 
scenarioNumber == 14 ||scenarioNumber == 15){
+        } else if (scenarioNumber == 7 || scenarioNumber == 8 || 
scenarioNumber == 14 ||
+                   scenarioNumber == 15) {
             // Use HTTP EPR WITH USER
             configureUtKeystoreSec(stub, scenarioNumber);
         } else {
@@ -442,7 +445,8 @@
         if (QOS_VALUE_SECURE_RM.equals(qosValue)) {
             //TODO added per testing securerm scenario
             
stub._getServiceClient().getServiceContext().getConfigurationContext()
-                    
.getAxisConfiguration().getPolicyInclude().addPolicyElement(PolicyInclude.AXIS_POLICY,
 policy);
+                    .getAxisConfiguration().getPolicyInclude()
+                    .addPolicyElement(PolicyInclude.AXIS_POLICY, policy);
 
         }
 
@@ -500,15 +504,18 @@
 
         if (QOS_VALUE_SECURE_RM.equals(qosValue)) {
             
stub._getServiceClient().getServiceContext().getConfigurationContext()
-                    
.getAxisConfiguration().getPolicyInclude().addPolicyElement(PolicyInclude.AXIS_POLICY,
 policy);
+                    .getAxisConfiguration().getPolicyInclude()
+                    .addPolicyElement(PolicyInclude.AXIS_POLICY, policy);
         }
 
     }
 
-    private void configureUtKeystoreSec(Stub stub, int scenario) throws 
AxisFault, FileNotFoundException,
-                                                                               
              XMLStreamException {
-        System.out.println("In this demonstration, client will use client.jks 
and server should use\n" +
-                                                                               
                      "service.jks.");
+    private void configureUtKeystoreSec(Stub stub, int scenario)
+            throws AxisFault, FileNotFoundException,
+                   XMLStreamException {
+        System.out.println(
+                "In this demonstration, client will use client.jks and server 
should use\n" +
+                "service.jks.");
         RampartConfig rc = new RampartConfig();
         Policy policy = loadPolicy(scenario);
 
@@ -528,13 +535,13 @@
 
         stub._getServiceClient().getAxisService().addParameter(param);
 
-       CryptoConfig sigCryptoConfig = new CryptoConfig();
+        CryptoConfig sigCryptoConfig = new CryptoConfig();
 
         
sigCryptoConfig.setProvider("org.apache.ws.security.components.crypto.Merlin");
 
         String keystore = wso2wsasHome + File.separator + "samples" +
-        File.separator + "CommodityQuote" + File.separator +
-        "keys" + File.separator + "client.jks";
+                          File.separator + "CommodityQuote" + File.separator +
+                          "keys" + File.separator + "client.jks";
 
         Properties prop1 = new Properties();
         prop1.put("org.apache.ws.security.crypto.merlin.keystore.type", "JKS");
@@ -560,14 +567,15 @@
         policy.addAssertion(rc);
 
         stub._getServiceClient().getServiceContext()
-        .setProperty(RampartMessageData.KEY_RAMPART_POLICY, policy);
+                .setProperty(RampartMessageData.KEY_RAMPART_POLICY, policy);
 
         if (QOS_VALUE_SECURE_RM.equals(qosValue)) {
-        stub._getServiceClient().getServiceContext().getConfigurationContext()
-        
.getAxisConfiguration().getPolicyInclude().addPolicyElement(PolicyInclude.AXIS_POLICY,
 policy);
+            
stub._getServiceClient().getServiceContext().getConfigurationContext()
+                    .getAxisConfiguration().getPolicyInclude()
+                    .addPolicyElement(PolicyInclude.AXIS_POLICY, policy);
         }
 
-}
+    }
 
     private static Policy loadPolicy(int scenario) throws 
FileNotFoundException,
                                                           XMLStreamException {
@@ -582,8 +590,9 @@
                                    EndpointReference epr) throws IOException, 
XMLStreamException {
         int secScenarioNumber = this.configureSecurity(args, epr);
         if (secScenarioNumber == 1 || secScenarioNumber == 9) {
-            System.err.println("Secure-RM not supported for scenarios 1 & 9 
since HTTPS is required " +
-                               "on the client side receiver. This is a 
limitation of the client.");
+            System.err.println(
+                    "Secure-RM not supported for scenarios 1 & 9 since HTTPS 
is required " +
+                    "on the client side receiver. This is a limitation of the 
client.");
             System.exit(1);
         }
         this.configureRM();

_______________________________________________
Wsas-java-dev mailing list
Wsas-java-dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/wsas-java-dev

Reply via email to