Author: azeez Date: Sun Jun 7 02:18:17 2009 New Revision: 38006 URL: http://wso2.org/svn/browse/wso2?view=rev&revision=38006
Log: improvements Modified: trunk/wsas/java/modules/samples/CommodityQuote/src/org/wso2/wsas/sample/commodityquote/client/Client.java Modified: trunk/wsas/java/modules/samples/CommodityQuote/src/org/wso2/wsas/sample/commodityquote/client/Client.java URL: http://wso2.org/svn/browse/wso2/trunk/wsas/java/modules/samples/CommodityQuote/src/org/wso2/wsas/sample/commodityquote/client/Client.java?rev=38006&r1=38005&r2=38006&view=diff ============================================================================== --- trunk/wsas/java/modules/samples/CommodityQuote/src/org/wso2/wsas/sample/commodityquote/client/Client.java (original) +++ trunk/wsas/java/modules/samples/CommodityQuote/src/org/wso2/wsas/sample/commodityquote/client/Client.java Sun Jun 7 02:18:17 2009 @@ -41,7 +41,6 @@ import org.wso2.carbon.security.util.WSS4JUtil; import org.wso2.www.types.client.*; -import javax.xml.namespace.QName; import javax.xml.stream.XMLStreamException; import java.io.*; import java.rmi.RemoteException; @@ -109,7 +108,9 @@ System.out.println("...Getting Quote..."); if (stub == null) { - System.out.println("Trade stub is not available"); + String msg = "CommodityQuote stub is not available"; + System.out.println(msg); + throw new RuntimeException(msg); } System.out.print("Please enter the symbol:"); @@ -118,7 +119,6 @@ if (symbol == null) { System.out.println("ERROR:Invalid symbol"); - return; } @@ -164,17 +164,19 @@ System.out.println("...Getting symbols..."); if (stub == null) { - System.out.println("Stub is not available"); + String msg = "CommodityQuote stub is not available"; + System.out.println(msg); + throw new RuntimeException(msg); } if (QOS_VALUE_RM.equals(qosValue)) { - try { - configureRM(); - }catch (AxisFault e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } + try { + configureRM(); + } catch (Exception e) { + e.printStackTrace(); + String msg = "Error occurred while configuring RM"; + throw new RuntimeException(msg, e); + } } try { @@ -265,8 +267,8 @@ return; } - if (e.getMessage().indexOf("The security token could not be authenticated or authorized") != - -1) { + if (e.getMessage(). + indexOf("The security token could not be authenticated or authorized") != -1) { System.err.println(SECURITY_TOKEN_ERROR_STR); } else { System.err.println("Security failure. Please refer to the CommodityQuote documentation " + @@ -299,10 +301,9 @@ } } - private void configureRM() throws AxisFault, IOException { - stub._getServiceClient().engageModule(new QName(MODULE_RM)); - stub._getServiceClient().engageModule(new QName( - org.apache.axis2.Constants.MODULE_ADDRESSING)); + private void configureRM() throws IOException { + stub._getServiceClient().engageModule(MODULE_RM); + stub._getServiceClient().engageModule(org.apache.axis2.Constants.MODULE_ADDRESSING); Options clientOptions = stub._getServiceClient().getOptions(); @@ -351,19 +352,11 @@ // } - /** - * Configuring for security authentication. - * All will be configured via https - * - * @return the selected security scenario number - * @throws AxisFault - * @throws IOException - */ private int configureSecurity(String[] args, EndpointReference epr) - throws AxisFault, IOException, XMLStreamException { - stub._getServiceClient().engageModule(new QName(MODULE_SECURITY)); + throws IOException, XMLStreamException { + stub._getServiceClient().engageModule(MODULE_SECURITY); stub._getServiceClient() - .engageModule(new QName(org.apache.axis2.Constants.MODULE_ADDRESSING)); + .engageModule(org.apache.axis2.Constants.MODULE_ADDRESSING); String clientSSLStore = wso2wsasHome + File.separator + "resources" + File.separator + "security" + File.separator + "wso2carbon.jks"; @@ -420,10 +413,11 @@ epr.setAddress(serviceEPR); stub._getServiceClient().getOptions().setTo(epr); configureUtSec(stub, scenarioNumber); - } else if (scenarioNumber == 6 || scenarioNumber == 7 || scenarioNumber == 9 ||scenarioNumber == 13){ + } else if (scenarioNumber == 7 || scenarioNumber == 8 || + scenarioNumber == 14 || scenarioNumber == 15) { // All UT scenarios which involve keys // Use HTTP EPR WITH USER + Keystore config configureUtKeystoreSec(stub, scenarioNumber); - } else { + } else { // Scenarios only involving keys // Use HTTP EPR with Keystore config configureKeystoreSec(stub, scenarioNumber); } @@ -518,14 +512,15 @@ } } - - private void configureUtKeystoreSec(Stub stub, int scenario) throws AxisFault, FileNotFoundException, - XMLStreamException { + + 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."); + "service.jks."); RampartConfig rc = new RampartConfig(); Policy policy = loadPolicy(scenario); - + System.out.println("Please enter your username :"); String username = readOption(); @@ -534,51 +529,51 @@ String password = readOption(); Parameter param = WSS4JUtil.getClientUsernameTokenHandler(password); stub._getServiceClient().getAxisService().addParameter(param); - + rc.setUserCertAlias("client"); rc.setEncryptionUser("service"); rc.setPwCbClass(PWCallback.class.getName()); - + 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"); prop1.put("org.apache.ws.security.crypto.merlin.file", keystore); prop1.put("org.apache.ws.security.crypto.merlin.keystore.password", "testing"); sigCryptoConfig.setProp(prop1); - + CryptoConfig encrCryptoConfig = new CryptoConfig(); encrCryptoConfig.setProvider("org.apache.ws.security.components.crypto.Merlin"); - + Properties prop2 = new Properties(); - + prop2.put("org.apache.ws.security.crypto.merlin.keystore.type", "JKS"); - - + + prop2.put("org.apache.ws.security.crypto.merlin.file", keystore); prop2.put("org.apache.ws.security.crypto.merlin.keystore.password", "testing"); encrCryptoConfig.setProp(prop2); - + rc.setSigCryptoConfig(sigCryptoConfig); rc.setEncrCryptoConfig(encrCryptoConfig); - + 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 { _______________________________________________ Wsas-java-dev mailing list [email protected] https://wso2.org/cgi-bin/mailman/listinfo/wsas-java-dev
