summaryrefslogtreecommitdiffstats
path: root/java/sca/modules
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2008-08-07 01:57:35 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2008-08-07 01:57:35 +0000
commit3762920a8fd57276b62d6d3306c7f8a339398506 (patch)
treeb10da5a2944385ae0525929af36d66acd3f9febf /java/sca/modules
parent3bd7a3525abf9d1b4567cd33acb6a455df25275f (diff)
Convert localhost to the actual local host name when configuring Widget proxies otherwise you get security exceptions in the browser, even though localhost and your local host name point to the same address.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@683471 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules')
-rw-r--r--java/sca/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationInvoker.java34
1 files changed, 20 insertions, 14 deletions
diff --git a/java/sca/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationInvoker.java b/java/sca/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationInvoker.java
index 18bf692401..7a8d780366 100644
--- a/java/sca/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationInvoker.java
+++ b/java/sca/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationInvoker.java
@@ -24,16 +24,18 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
+import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
+import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;
import org.apache.tuscany.sca.assembly.Binding;
import org.apache.tuscany.sca.assembly.ComponentProperty;
import org.apache.tuscany.sca.assembly.ComponentReference;
-import org.apache.tuscany.sca.assembly.OptimizableBinding;
import org.apache.tuscany.sca.invocation.Invoker;
import org.apache.tuscany.sca.invocation.Message;
import org.apache.tuscany.sca.runtime.RuntimeComponent;
@@ -90,6 +92,12 @@ class WidgetImplementationInvoker implements Invoker {
// Report exception as a fault
msg.setFaultBody(e);
+
+ } catch (URISyntaxException e) {
+
+ // Report exception as a fault
+ msg.setFaultBody(e);
+
} catch (IOException e) {
// Report exception as a fault
@@ -102,7 +110,7 @@ class WidgetImplementationInvoker implements Invoker {
* This helper class concatenates the necessary JavaScript client code into a
* single JavaScript per component
*/
- private InputStream generateWidgetCode() throws IOException {
+ private InputStream generateWidgetCode() throws IOException, URISyntaxException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
PrintWriter pw = new PrintWriter(bos);
@@ -204,7 +212,7 @@ class WidgetImplementationInvoker implements Invoker {
* @param pw
* @throws IOException
*/
- private void generateJavaScriptReferenceFunction (PrintWriter pw) throws IOException {
+ private void generateJavaScriptReferenceFunction (PrintWriter pw) throws IOException, URISyntaxException {
pw.println("var referenceMap = new Object();");
for(ComponentReference reference : component.getReferences()) {
@@ -215,19 +223,17 @@ class WidgetImplementationInvoker implements Invoker {
String proxyClient = WidgetProxyHelper.getJavaScriptProxyClient(binding.getClass().getName());
if(proxyClient != null) {
- //FIXME Eventually the binding URI should be initialized from the SCA domain
- // for now point to the target binding model directly, assuming that it's available
- // in the same node
- String targetURI = null;
- if (binding instanceof OptimizableBinding) {
- Binding targetBinding = ((OptimizableBinding)binding).getTargetBinding();
- if (targetBinding != null) {
- targetURI = targetBinding.getURI();
+ // Convert the local host to the acutal name of local host
+ URI targetURI = URI.create(binding.getURI());
+ if ("localhost".equals(targetURI.getHost())) {
+ try {
+ String host = InetAddress.getLocalHost().getHostName();
+ targetURI = new URI(targetURI.getScheme(), targetURI.getUserInfo(),
+ host, targetURI.getPort(),
+ targetURI.getPath(), targetURI.getQuery(), targetURI.getFragment());
+ } catch (UnknownHostException e) {
}
}
- if (targetURI == null) {
- targetURI = binding.getURI();
- }
if(proxyClient.equals("JSONRpcClient")) {
pw.println("referenceMap." + referenceName + " = new " + proxyClient + "(\"" + targetURI + "\").Service;");