[wsas-java-dev] svn commit r96 - in wsas/java/trunk: .
modules/samples/CommodityQuote/conf
modules/samples/CommodityQuote/src/org/wso2/wsas/sample/commodityquote/client
modules/samples/JavascriptService/conf
modules/samples/JavascriptService/src/org/wso2/wsas/sample/javascript
modules/samples/Trader/conf
modules/samples/Trader/src/org/wso2/wsas/sample/trader
modules/wsf-common-core/src/org/wso2/wsf/common/util
svn at wso2.com
svn at wso2.com
Fri Dec 1 14:10:33 PST 2006
Author: azeez
Date: Fri Dec 1 14:10:32 2006
New Revision: 96
Modified:
wsas/java/trunk/maven.xml
wsas/java/trunk/modules/samples/CommodityQuote/conf/default_epr.properties
wsas/java/trunk/modules/samples/CommodityQuote/conf/default_epr_web.properties
wsas/java/trunk/modules/samples/CommodityQuote/src/org/wso2/wsas/sample/commodityquote/client/Client.java
wsas/java/trunk/modules/samples/JavascriptService/conf/default_epr.properties
wsas/java/trunk/modules/samples/JavascriptService/conf/default_epr_web.properties
wsas/java/trunk/modules/samples/JavascriptService/src/org/wso2/wsas/sample/javascript/Client.java
wsas/java/trunk/modules/samples/Trader/conf/default_epr.properties
wsas/java/trunk/modules/samples/Trader/conf/default_epr_web.properties
wsas/java/trunk/modules/samples/Trader/src/org/wso2/wsas/sample/trader/Client.java
wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/util/NetworkUtils.java
Log:
Handling EPRs
Modified: wsas/java/trunk/maven.xml
==============================================================================
--- wsas/java/trunk/maven.xml (original)
+++ wsas/java/trunk/maven.xml Fri Dec 1 14:10:32 2006
@@ -827,7 +827,7 @@
<exclude name="**/*.iml"/>
<exclude name="**/.project"/>
<exclude name="**/.classpath"/>
- <exclude name="**/default_epr*.properties"/>
+ <exclude name="**/default_epr_web.properties"/>
<exclude name="**/**.jks"/>
</ant:fileset>
</ant:copy>
Modified: wsas/java/trunk/modules/samples/CommodityQuote/conf/default_epr.properties
==============================================================================
--- wsas/java/trunk/modules/samples/CommodityQuote/conf/default_epr.properties (original)
+++ wsas/java/trunk/modules/samples/CommodityQuote/conf/default_epr.properties Fri Dec 1 14:10:32 2006
@@ -14,8 +14,5 @@
# limitations under the License.
#
-http.port=9762
-https.port=9443
-
-contextRoot=/
-servicePath=soap/CommodityQuote
\ No newline at end of file
+http.epr=http://@hostname@:9762/soap/CommodityQuote
+https.epr=https://@hostname@:9443/soap/CommodityQuote
\ No newline at end of file
Modified: wsas/java/trunk/modules/samples/CommodityQuote/conf/default_epr_web.properties
==============================================================================
--- wsas/java/trunk/modules/samples/CommodityQuote/conf/default_epr_web.properties (original)
+++ wsas/java/trunk/modules/samples/CommodityQuote/conf/default_epr_web.properties Fri Dec 1 14:10:32 2006
@@ -14,8 +14,5 @@
# limitations under the License.
#
-http.port=9762
-https.port=9443
-
-contextRoot=/wso2wsas
-servicePath=/soap/CommodityQuote
\ No newline at end of file
+http.epr=http://@hostname@:9762/wso2wsas/soap/CommodityQuote
+https.epr=https://@hostname@:9443/wso2wsas/soap/CommodityQuote
\ No newline at end of file
Modified: wsas/java/trunk/modules/samples/CommodityQuote/src/org/wso2/wsas/sample/commodityquote/client/Client.java
==============================================================================
--- wsas/java/trunk/modules/samples/CommodityQuote/src/org/wso2/wsas/sample/commodityquote/client/Client.java (original)
+++ wsas/java/trunk/modules/samples/CommodityQuote/src/org/wso2/wsas/sample/commodityquote/client/Client.java Fri Dec 1 14:10:32 2006
@@ -8,7 +8,6 @@
import org.apache.axis2.client.Stub;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
-import org.apache.axis2.context.MessageContextConstants;
import org.apache.axis2.description.AxisModule;
import org.apache.axis2.description.Parameter;
import org.apache.axis2.description.PolicyInclude;
@@ -32,6 +31,7 @@
import java.math.BigInteger;
import java.rmi.RemoteException;
import java.util.Properties;
+import java.net.SocketException;
public class Client {
@@ -50,8 +50,8 @@
private static final String MODULE_RM = "sandesha2";
private static String invocationType = null;
private static String qosValue = null;
-
-
+
+
static final String SECURITY_TOKEN_ERROR_STR =
"The security token could not be authenticated or authorized. " +
"\nPlease make sure this user is authorized to access the CommodityQuote service, or " +
@@ -63,8 +63,6 @@
private static final String wso2wsasHome = System.getProperty("wso2wsas.home");
- private static String serviceEPR;
-
// ===========================================================
private static boolean isMailEPR = false;
@@ -162,7 +160,7 @@
System.out.println("...Getting symbols...");
if (stub == null) {
- System.out.println("Trade stub is not available");
+ System.out.println("Stub is not available");
}
GetSymbolsRequest request = new GetSymbolsRequest();
@@ -223,11 +221,8 @@
private String readOption() {
try {
String str;
-
while ((str = console.readLine()).equals("")) {
- ;
}
-
return str;
} catch (Exception e) {
return null;
@@ -235,7 +230,7 @@
}
private int readIntOption() {
- int option = -1;
+ int option;
while (true) {
String s = readOption();
@@ -250,38 +245,6 @@
}
}
- private float readFloatOption() {
- float option = -1;
-
- while (true) {
- String s = readOption();
-
- try {
- option = Float.parseFloat(s);
-
- return option;
- } catch (NumberFormatException e) {
- System.out.println("Please enter an float value.");
- }
- }
- }
-
- private BigInteger readBigIntegerOption() {
- BigInteger option = null;
-
- while (true) {
- String s = readOption();
-
- try {
- BigInteger number = new BigInteger(s);
-
- return number;
- } catch (NumberFormatException e) {
- System.out.println("Please enter an valid number (BigInteger)");
- }
- }
- }
-
private void handleException(Exception e) {
if ((e == null) || (e.getMessage() == null)) {
System.out.println(
@@ -292,21 +255,15 @@
if (e.getMessage().indexOf("The security token could not be authenticated or authorized") !=
-1) {
System.err.println(SECURITY_TOKEN_ERROR_STR);
- } else
- if (e.getMessage().indexOf("Request does not contain required Security header") != -1) {
- System.err.println(
- "Required security header not found in request.\n" +
- " Username Token Authentication has been enabled, " +
- "\nand security module has been engaged with the CommodityQuote service. " +
- "\nPlease use the 'security QoS parameter, and run the client again.'");
} else {
- System.err.println(e.getMessage());
+ System.err.println("Security failure. Please refer to the CommodityQuote documentation " +
+ "and configure the CommodityQuote service properly");
+ e.printStackTrace();
}
}
public void start() throws IOException {
while (true) {
- int i;
showOperations();
System.out.print(":");
@@ -370,7 +327,7 @@
* @throws AxisFault
* @throws IOException
*/
- private void configureSecurity(Properties props, String[] args, EndpointReference epr)
+ private void configureSecurity(String[] args, EndpointReference epr)
throws AxisFault, IOException, XMLStreamException {
stub._getServiceClient().engageModule(new QName(MODULE_SECURITY));
stub._getServiceClient()
@@ -388,17 +345,7 @@
String serviceEPR = getParam(PARAM_ENDPOINT, args);
if (serviceEPR == null) {
-
- StringBuffer httpStringBuffer = new StringBuffer();
-
- httpStringBuffer.append("https://");
- httpStringBuffer.append(NetworkUtils.getLocalHostname());
- httpStringBuffer.append(":");
- httpStringBuffer.append(props.getProperty("http.port"));
- httpStringBuffer.append(props.getProperty("contextRoot"));
- httpStringBuffer.append(props.getProperty("servicePath"));
-
- serviceEPR = httpStringBuffer.toString();
+ serviceEPR = computeDefaultHttpsEPR();
}
int scenario;
@@ -463,12 +410,12 @@
policy.addAssertion(rc);
if (QOS_VALUE_SECURE_RM.equals(qosValue)) {
- //TODO added per testing securerm scenario
- stub._getServiceClient().getServiceContext().getConfigurationContext()
- .getAxisConfiguration().getPolicyInclude().addPolicyElement(PolicyInclude.AXIS_POLICY ,policy);
-
+ //TODO added per testing securerm scenario
+ stub._getServiceClient().getServiceContext().getConfigurationContext()
+ .getAxisConfiguration().getPolicyInclude().addPolicyElement(PolicyInclude.AXIS_POLICY, policy);
+
}
-
+
stub._getServiceClient().getOptions()
.setProperty(RampartMessageData.KEY_RAMPART_POLICY,
policy);
@@ -519,11 +466,11 @@
stub._getServiceClient().getOptions()
.setProperty(RampartMessageData.KEY_RAMPART_POLICY,
policy);
-
+
if (QOS_VALUE_SECURE_RM.equals(qosValue)) {
- //TODO added per testing securerm scenario
- stub._getServiceClient().getServiceContext().getConfigurationContext()
- .getAxisConfiguration().getPolicyInclude().addPolicyElement(PolicyInclude.AXIS_POLICY ,policy);
+ //TODO added per testing securerm scenario
+ stub._getServiceClient().getServiceContext().getConfigurationContext()
+ .getAxisConfiguration().getPolicyInclude().addPolicyElement(PolicyInclude.AXIS_POLICY, policy);
}
}
@@ -537,9 +484,9 @@
return PolicyEngine.getPolicy(builder.getDocumentElement());
}
- private void configureSecureRM(Properties props, String[] args, EndpointReference epr)
- throws IOException, XMLStreamException, WSSPolicyException {
- this.configureSecurity(props, args, epr);
+ private void configureSecureRM(String[] args,
+ EndpointReference epr) throws IOException, XMLStreamException {
+ this.configureSecurity(args, epr);
this.configureRM();
}
@@ -554,31 +501,9 @@
}
}
- serviceEPR = getParam(PARAM_ENDPOINT, args);
- Properties props = new Properties();
-
- StringBuffer httpStringBuffer = new StringBuffer();
-
- try {
- String defEPRProperties = wso2wsasHome + File.separator + "samples" +
- File.separator + "CommodityQuote" + File.separator +
- "conf" + File.separator + "default_epr.properties";
- props.load(new FileInputStream(defEPRProperties));
- if (serviceEPR == null) {
- httpStringBuffer.append("http://");
- httpStringBuffer.append(NetworkUtils.getLocalHostname());
- httpStringBuffer.append(":");
- httpStringBuffer.append(props.getProperty("http.port"));
- httpStringBuffer.append(props.getProperty("contextRoot"));
- httpStringBuffer.append(props.getProperty("servicePath"));
- serviceEPR = httpStringBuffer.toString();
-
- System.out.println("servie epr : " + serviceEPR);
-
- }
- } catch (IOException e) {
- System.err.println(
- "[WARN] default_epr.properties not found in conf directory");
+ String serviceEPR = getParam(PARAM_ENDPOINT, args);
+ if (serviceEPR == null) {
+ serviceEPR = computeDefaultHttpEPR();
}
if (serviceEPR != null) {
@@ -589,7 +514,7 @@
String qos = getParam(PARAM_QOS, args);
qosValue = qos;
-
+
try {
if ((qos != null) && !qos.equalsIgnoreCase(QOS_VALUE_RM) &&
!qos.equalsIgnoreCase(QOS_VALUE_SECURE) &&
@@ -621,9 +546,9 @@
if (QOS_VALUE_RM.equalsIgnoreCase(qos)) {
client.configureRM();
} else if (QOS_VALUE_SECURE.equalsIgnoreCase(qos)) {
- client.configureSecurity(props, args, epr);
+ client.configureSecurity(args, epr);
} else if (QOS_VALUE_SECURE_RM.equalsIgnoreCase(qos)) {
- client.configureSecureRM(props, args, epr);
+ client.configureSecureRM(args, epr);
}
if (isMailEPR) {
@@ -703,4 +628,40 @@
System.out.println("ERROR: RM Sequence timed out");
}
}
+
+ private static String computeDefaultHttpEPR() {
+ try {
+ Properties props = new Properties();
+ String defEPRProperties = wso2wsasHome + File.separator + "samples" +
+ File.separator + "CommodityQuote" + File.separator +
+ "conf" + File.separator + "default_epr.properties";
+ props.load(new FileInputStream(defEPRProperties));
+ return props.getProperty("http.epr").
+ replaceAll("@hostname@", NetworkUtils.getLocalHostname());
+ } catch (IOException e) {
+ System.err.println(
+ "[ERROR] default_epr.properties not found in conf directory & " +
+ "the HTTP service EPR has not been specified.");
+ System.exit(1);
+ }
+ return null;
+ }
+
+ private String computeDefaultHttpsEPR() {
+ try {
+ Properties props = new Properties();
+ String defEPRProperties = wso2wsasHome + File.separator + "samples" +
+ File.separator + "CommodityQuote" + File.separator +
+ "conf" + File.separator + "default_epr.properties";
+ props.load(new FileInputStream(defEPRProperties));
+ return props.getProperty("https.epr").
+ replaceAll("@hostname@", NetworkUtils.getLocalHostname());
+ } catch (IOException e) {
+ System.err.println(
+ "[ERROR] default_epr.properties not found in conf directory & " +
+ "the HTTP service EPR has not been specified.");
+ System.exit(1);
+ }
+ return null;
+ }
}
Modified: wsas/java/trunk/modules/samples/JavascriptService/conf/default_epr.properties
==============================================================================
--- wsas/java/trunk/modules/samples/JavascriptService/conf/default_epr.properties (original)
+++ wsas/java/trunk/modules/samples/JavascriptService/conf/default_epr.properties Fri Dec 1 14:10:32 2006
@@ -14,4 +14,4 @@
# limitations under the License.
#
-js.epr=http://localhost:9762/soap/JavascriptService/echo
\ No newline at end of file
+js.epr=http://@hostname@:9762/soap/JavascriptService/echo
\ No newline at end of file
Modified: wsas/java/trunk/modules/samples/JavascriptService/conf/default_epr_web.properties
==============================================================================
--- wsas/java/trunk/modules/samples/JavascriptService/conf/default_epr_web.properties (original)
+++ wsas/java/trunk/modules/samples/JavascriptService/conf/default_epr_web.properties Fri Dec 1 14:10:32 2006
@@ -14,4 +14,4 @@
# limitations under the License.
#
-js.epr=http://localhost:9762/wso2wsas/soap/JavascriptService/echo
\ No newline at end of file
+js.epr=http://@hostname@:9762/wso2wsas/soap/JavascriptService/echo
\ No newline at end of file
Modified: wsas/java/trunk/modules/samples/JavascriptService/src/org/wso2/wsas/sample/javascript/Client.java
==============================================================================
--- wsas/java/trunk/modules/samples/JavascriptService/src/org/wso2/wsas/sample/javascript/Client.java (original)
+++ wsas/java/trunk/modules/samples/JavascriptService/src/org/wso2/wsas/sample/javascript/Client.java Fri Dec 1 14:10:32 2006
@@ -24,6 +24,7 @@
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
+import org.wso2.wsf.common.util.NetworkUtils;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory;
@@ -53,7 +54,8 @@
File.separator + "JavascriptService" + File.separator +
"conf" + File.separator + "default_epr.properties";
props.load(new FileInputStream(defEPRProperties));
- serviceEPR = props.getProperty("js.epr");
+ serviceEPR = props.getProperty("js.epr").replaceAll("@hostname@",
+ NetworkUtils.getLocalHostname());
} catch (IOException e) {
System.err.println("[WARN] default_epr.properties not found in conf directory");
}
Modified: wsas/java/trunk/modules/samples/Trader/conf/default_epr.properties
==============================================================================
--- wsas/java/trunk/modules/samples/Trader/conf/default_epr.properties (original)
+++ wsas/java/trunk/modules/samples/Trader/conf/default_epr.properties Fri Dec 1 14:10:32 2006
@@ -14,7 +14,7 @@
# limitations under the License.
#
-trader.http.epr=http://127.0.0.1:9762/soap/TraderClient
-trader.https.epr=https://127.0.0.1:9443/soap/TraderClient
-exchange.http.epr=http://127.0.0.1:9762/soap/ExchangeClient
-exchange.https.epr=https://127.0.0.1:9443/soap/ExchangeClient
\ No newline at end of file
+trader.http.epr=http://@hostname@:9762/soap/TraderClient
+trader.https.epr=https://@hostname@:9443/soap/TraderClient
+exchange.http.epr=http://@hostname@:9762/soap/ExchangeClient
+exchange.https.epr=https://@hostname@:9443/soap/ExchangeClient
\ No newline at end of file
Modified: wsas/java/trunk/modules/samples/Trader/conf/default_epr_web.properties
==============================================================================
--- wsas/java/trunk/modules/samples/Trader/conf/default_epr_web.properties (original)
+++ wsas/java/trunk/modules/samples/Trader/conf/default_epr_web.properties Fri Dec 1 14:10:32 2006
@@ -14,7 +14,7 @@
# limitations under the License.
#
-trader.http.epr=http://127.0.0.1:9762/wso2wsas/soap/TraderClient
-trader.https.epr=https://127.0.0.1:9443/wso2wsas/soap/TraderClient
-exchange.http.epr=http://127.0.0.1:9762/wso2wsas/soap/ExchangeClient
-exchange.https.epr=https://127.0.0.1:9443/wso2wsas/soap/ExchangeClient
\ No newline at end of file
+trader.http.epr=http://@hostname@:9762/wso2wsas/soap/TraderClient
+trader.https.epr=https://@hostname@:9443/wso2wsas/soap/TraderClient
+exchange.http.epr=http://@hostname@:9762/wso2wsas/soap/ExchangeClient
+exchange.https.epr=https://@hostname@:9443/wso2wsas/soap/ExchangeClient
\ No newline at end of file
Modified: wsas/java/trunk/modules/samples/Trader/src/org/wso2/wsas/sample/trader/Client.java
==============================================================================
--- wsas/java/trunk/modules/samples/Trader/src/org/wso2/wsas/sample/trader/Client.java (original)
+++ wsas/java/trunk/modules/samples/Trader/src/org/wso2/wsas/sample/trader/Client.java Fri Dec 1 14:10:32 2006
@@ -42,6 +42,7 @@
import org.wso2.www.types.exchange.client.GetInfoResponse;
import org.wso2.www.types.exchange.client.MarketInfo;
import org.wso2.www.types.trader.client.*;
+import org.wso2.wsf.common.util.NetworkUtils;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
@@ -876,10 +877,16 @@
"conf" + File.separator + "default_epr.properties";
props.load(new FileInputStream(defEPRProperties));
if (traderServiceEPR == null) {
- traderServiceEPR = props.getProperty("trader.http.epr");
+ traderServiceEPR =
+ props.getProperty("trader.http.epr").
+ replaceAll("@hostname@",
+ NetworkUtils.getLocalHostname());
}
if (exchangeServiceEPR == null) {
- exchangeServiceEPR = props.getProperty("exchange.http.epr");
+ exchangeServiceEPR =
+ props.getProperty("exchange.http.epr").
+ replaceAll("@hostname@",
+ NetworkUtils.getLocalHostname());
}
} catch (IOException e) {
System.err.println(
@@ -919,12 +926,17 @@
if (QOS_VALUE_SECURE.equals(qos) || QOS_VALUE_SECURE_RM.equals(qos)) {
tempValue = getParam(PARAM_TRADER_ENDPOINT, args);
if (tempValue == null) {
- traderServiceEPR = props.getProperty("trader.https.epr");
-
+ traderServiceEPR =
+ props.getProperty("trader.https.epr").
+ replaceAll("@hostname@",
+ NetworkUtils.getLocalHostname());
}
tempValue = getParam(PARAM_EXCHANGE_ENDPOINT, args);
if (tempValue == null) {
- exchangeServiceEPR = props.getProperty("exchange.https.epr");
+ exchangeServiceEPR =
+ props.getProperty("exchange.https.epr").
+ replaceAll("@hostname@",
+ NetworkUtils.getLocalHostname());
}
}
Modified: wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/util/NetworkUtils.java
==============================================================================
--- wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/util/NetworkUtils.java (original)
+++ wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/util/NetworkUtils.java Fri Dec 1 14:10:32 2006
@@ -16,8 +16,6 @@
package org.wso2.wsf.common.util;
import org.apache.axis2.transport.http.server.HttpUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import java.net.SocketException;
@@ -63,12 +61,9 @@
* @return a string name of the host.
*/
public static String getLocalHostname() throws SocketException {
- String ip;
if (hostName == null) {
- ip = HttpUtils.getIpAddress();
- } else {
- ip = hostName;
+ hostName = HttpUtils.getIpAddress();
}
- return ip;
+ return hostName;
}
}
More information about the Wsas-java-dev
mailing list