Author: keith
Date: Tue Apr 29 06:45:11 2008
New Revision: 16341

Log:

Avoid using MessageContext in HostObjects. We will be using AxisService instead


Modified:
   
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/system/FunctionSchedulingJob.java
   
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/system/SystemHostObject.java
   
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/wsrequest/WSRequestHostImpl.java

Modified: 
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/system/FunctionSchedulingJob.java
==============================================================================
--- 
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/system/FunctionSchedulingJob.java
     (original)
+++ 
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/system/FunctionSchedulingJob.java
     Tue Apr 29 06:45:11 2008
@@ -15,8 +15,9 @@
  */
 package org.wso2.mashup.hostobjects.system;
 
-import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.AxisFault;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.description.AxisService;
 import org.apache.axis2.description.Parameter;
 import org.mozilla.javascript.Context;
@@ -25,51 +26,51 @@
 import org.quartz.JobExecutionContext;
 import org.quartz.JobExecutionException;
 import org.wso2.javascript.rhino.JavaScriptEngine;
-import org.wso2.javascript.rhino.JavaScriptEngineUtils;
 import org.wso2.javascript.rhino.JavaScriptEngineConstants;
+import org.wso2.javascript.rhino.JavaScriptEngineUtils;
+import org.wso2.wsas.ServerManager;
 
-import java.net.URL;
-import java.io.Reader;
-import java.io.InputStream;
+import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
-import java.io.BufferedReader;
+import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.io.Reader;
+import java.net.URL;
 
 public class FunctionSchedulingJob implements Job {
 
     public static String JAVASCRIPT_FUNCTION = "jsfunction";
     public static String FUNCTION_PARAMETERS = "jsfunctionarguments";
-    public static String PARENT_MESSAGE_CONTEXT = "parentMessageContext";
+    public static String AXIS_SERVICE = "axisService";
 
     public void execute(JobExecutionContext jobExecutionContext) throws 
JobExecutionException {
 
         try {
-            MessageContext currentMessageContext =
-                    (MessageContext) 
jobExecutionContext.getJobDetail().getJobDataMap()
-                            .get(FunctionSchedulingJob.PARENT_MESSAGE_CONTEXT);
+            ServerManager serverManager = ServerManager.getInstance();
+            AxisService axisServce =
+                    (AxisService) 
jobExecutionContext.getJobDetail().getJobDataMap()
+                            .get(FunctionSchedulingJob.AXIS_SERVICE);
 
             Object jsFunction = 
jobExecutionContext.getJobDetail().getJobDataMap()
                     .get(FunctionSchedulingJob.JAVASCRIPT_FUNCTION);
 
             JavaScriptEngine jsEngine =
-                    new 
JavaScriptEngine(currentMessageContext.getAxisService().getName());
+                    new JavaScriptEngine(axisServce.getName());
 
             // Rhino E4X XMLLibImpl object can be instantiated only from 
within a script
             // So we instantiate it in here, so that we can use it outside of 
the script later
             jsEngine.getCx().evaluateString(jsEngine, "new XML();", 
"Instantiate E4X", 0, null);
 
+            ConfigurationContext configurationContext = 
serverManager.configContext;
             JavaScriptEngineUtils
-                    .loadHostObjects(jsEngine, 
currentMessageContext.getConfigurationContext()
-                            .getAxisConfiguration());
+                    .loadHostObjects(jsEngine, 
configurationContext.getAxisConfiguration());
 
             // Inject the incoming MessageContext to the Rhino Context. Some
             // host objects need access to the MessageContext. Eg: FileSystem,
             // WSRequest
             Context context = jsEngine.getCx();
-            
context.putThreadLocal(JavaScriptEngineConstants.AXIS2_MESSAGECONTEXT,
-                                   currentMessageContext);
 
             /*
              * Some host objects depend on the data we obtain from the
@@ -80,26 +81,25 @@
              * available at that time. For the consistency we inject them in
              * here too..
              */
-            context.putThreadLocal(JavaScriptEngineConstants.AXIS2_SERVICE,
-                                   currentMessageContext.getAxisService());
+            context.putThreadLocal(JavaScriptEngineConstants.AXIS2_SERVICE, 
axisServce);
             
context.putThreadLocal(JavaScriptEngineConstants.AXIS2_CONFIGURATION_CONTEXT,
-                                   
currentMessageContext.getConfigurationContext());
+                                   configurationContext);
 
-            JavaScriptEngineUtils.loadGlobalPropertyObjects(jsEngine, 
currentMessageContext
-                    .getConfigurationContext().getAxisConfiguration());
+            AxisConfiguration axisConfig = configurationContext.
+                    getAxisConfiguration();
+            JavaScriptEngineUtils.loadGlobalPropertyObjects(jsEngine, 
axisConfig);
 
-            URL repoURL = 
currentMessageContext.getConfigurationContext().getAxisConfiguration()
-                    .getRepository();
+            URL repoURL = axisConfig.getRepository();
             if (repoURL != null) {
                 JavaScriptEngine.axis2RepositoryLocation = repoURL.getPath();
             }
 
-            Reader reader = readJS(currentMessageContext);
+            Reader reader = readJS(axisServce);
 
             Object[] args;
 
             //support for importing javaScript files using services.xml or the 
axis2.xml
-            String scripts = getImportScriptsList(currentMessageContext);
+            String scripts = getImportScriptsList(axisServce);
 
             //Loading imported JavaScript files if there are any
             if (scripts != null) {
@@ -139,15 +139,15 @@
      * Locates the service Javascript file associated with ServiceJS parameter 
and returns
      * a Reader for it.
      *
-     * @param inMessage MessageContext object with information about the 
incoming message
+     * @param axisService The relavant AxisService
      * @return an input stream to the javascript source file
      * @throws org.apache.axis2.AxisFault if the parameter ServiceJS is not 
specified or if the service
      *                                    implementation is not available
      */
-    private Reader readJS(MessageContext inMessage) throws AxisFault {
+    private Reader readJS(AxisService axisService) throws AxisFault {
         InputStream jsFileStream;
-        AxisService service = inMessage.getServiceContext().getAxisService();
-        Parameter implInfoParam = 
service.getParameter(JavaScriptEngineConstants.SERVICE_JS);
+
+        Parameter implInfoParam = 
axisService.getParameter(JavaScriptEngineConstants.SERVICE_JS);
         if (implInfoParam == null) {
             throw new AxisFault("Parameter 'ServiceJS' not specified");
         }
@@ -158,7 +158,7 @@
                 throw new AxisFault("Unable to load the javaScript, File not 
Found", e);
             }
         } else {
-            jsFileStream = service.getClassLoader().getResourceAsStream(
+            jsFileStream = axisService.getClassLoader().getResourceAsStream(
                     implInfoParam.getValue().toString());
         }
         if (jsFileStream == null) {
@@ -171,21 +171,21 @@
      * Provides support for importing JavaScript files specified in the
      * Services.xml or the Axis2.xml using the "loadJSScripts" parameter.
      *
-     * @param inMessage - The incoming message Context
+     * @param axisService - The irelavant AxisService
      * @return String
      */
-    private String getImportScriptsList(MessageContext inMessage) {
+    private String getImportScriptsList(AxisService axisService) {
         String scripts = null;
 
         // Get necessary JavaScripts to be loaded from services.xml
-        Parameter param = 
inMessage.getOperationContext().getAxisOperation().getParameter(
+        Parameter param = axisService.getParameter(
                 JavaScriptEngineConstants.LOAD_JSSCRIPTS);
         if (param != null) {
             scripts = (String) param.getValue();
         }
 
         // Get necessary JavaScripts to be loaded from axis2.xml
-        param = 
inMessage.getConfigurationContext().getAxisConfiguration().getParameter(
+        param = axisService.getAxisConfiguration().getParameter(
                 JavaScriptEngineConstants.LOAD_JSSCRIPTS);
         if (param != null) {
             if (scripts == null) {

Modified: 
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/system/SystemHostObject.java
==============================================================================
--- 
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/system/SystemHostObject.java
  (original)
+++ 
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/system/SystemHostObject.java
  Tue Apr 29 06:45:11 2008
@@ -337,8 +337,6 @@
         SystemHostObject systemHostObject = checkInstance(thisObj);
 
         Object object = 
cx.getThreadLocal(JavaScriptEngineConstants.AXIS2_SERVICE);
-        Object currentMessageContext =
-                
cx.getThreadLocal(JavaScriptEngineConstants.AXIS2_MESSAGECONTEXT);
 
         AxisService axisService;
         if (object instanceof AxisService) {
@@ -398,7 +396,7 @@
                 jobDetail.getJobDataMap()
                         .put(FunctionSchedulingJob.FUNCTION_PARAMETERS, 
functionParams);
                 jobDetail.getJobDataMap()
-                        .put(FunctionSchedulingJob.PARENT_MESSAGE_CONTEXT, 
currentMessageContext);
+                        .put(FunctionSchedulingJob.AXIS_SERVICE, axisService);
 
                 //Creating the trigger. There will be a one-to-one mapping 
between jobs and triggers in this implementation
                 trigger = new SimpleTrigger(jobId + "-trigger", null, new 
Date(), null,
@@ -464,7 +462,7 @@
                 jobDetail.getJobDataMap()
                         .put(FunctionSchedulingJob.FUNCTION_PARAMETERS, 
functionParams);
                 jobDetail.getJobDataMap()
-                        .put(FunctionSchedulingJob.PARENT_MESSAGE_CONTEXT, 
currentMessageContext);
+                        .put(FunctionSchedulingJob.AXIS_SERVICE, axisService);
 
                 //Creating the trigger. There will be a one-to-one mapping 
between jobs and triggers in this implementation
                 trigger = new SimpleTrigger(jobId + "-trigger", null, new 
Date(), null,
@@ -538,7 +536,7 @@
                 jobDetail.getJobDataMap()
                         .put(FunctionSchedulingJob.FUNCTION_PARAMETERS, 
functionParams);
                 jobDetail.getJobDataMap()
-                        .put(FunctionSchedulingJob.PARENT_MESSAGE_CONTEXT, 
currentMessageContext);
+                        .put(FunctionSchedulingJob.AXIS_SERVICE, axisService);
 
                 //Creating the trigger. There will be a one-to-one mapping 
between jobs and triggers in this implementation
                 trigger = new SimpleTrigger(jobId + "-trigger", null, 
startTime, null,
@@ -620,7 +618,7 @@
                 jobDetail.getJobDataMap()
                         .put(FunctionSchedulingJob.FUNCTION_PARAMETERS, 
functionParams);
                 jobDetail.getJobDataMap()
-                        .put(FunctionSchedulingJob.PARENT_MESSAGE_CONTEXT, 
currentMessageContext);
+                        .put(FunctionSchedulingJob.AXIS_SERVICE, axisService);
 
                 //Creating the trigger. There will be a one-to-one mapping 
between jobs and triggers in this implementation
                 trigger = new SimpleTrigger(jobId + "-trigger", null, 
startTime, endTime,
@@ -779,8 +777,6 @@
         SystemHostObject systemHostObject = checkInstance(thisObj);
 
         Object object = 
cx.getThreadLocal(JavaScriptEngineConstants.AXIS2_SERVICE);
-        Object currentMessageContext =
-                
cx.getThreadLocal(JavaScriptEngineConstants.AXIS2_MESSAGECONTEXT);
 
         AxisService axisService;
         if (object instanceof AxisService) {
@@ -830,7 +826,7 @@
         jobDetail.getJobDataMap()
                 .put(FunctionSchedulingJob.JAVASCRIPT_FUNCTION, jsFunction);
         jobDetail.getJobDataMap()
-                .put(FunctionSchedulingJob.PARENT_MESSAGE_CONTEXT, 
currentMessageContext);
+                .put(FunctionSchedulingJob.AXIS_SERVICE, axisService);
 
         //Creating the trigger. There will be a one-to-one mapping between 
jobs and triggers in this implementation
         trigger = new SimpleTrigger(jobId + "-trigger", null,

Modified: 
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/wsrequest/WSRequestHostImpl.java
==============================================================================
--- 
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/wsrequest/WSRequestHostImpl.java
      (original)
+++ 
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/wsrequest/WSRequestHostImpl.java
      Tue Apr 29 06:45:11 2008
@@ -29,8 +29,8 @@
 import org.apache.axis2.client.async.AxisCallback;
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.context.ConfigurationContextFactory;
-import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.description.AxisOperation;
+import org.apache.axis2.description.AxisService;
 import org.apache.axis2.description.WSDL2Constants;
 import org.apache.axis2.transport.http.HTTPConstants;
 import org.apache.axis2.transport.http.HttpTransportProperties;
@@ -57,11 +57,10 @@
 import org.mozilla.javascript.Undefined;
 import org.mozilla.javascript.UniqueTag;
 import org.w3c.dom.Document;
-import org.wso2.javascript.rhino.JavaScriptEngineConstants;
 import org.wso2.javascript.xmlimpl.XML;
-import org.wso2.mashup.MashupFault;
 import org.wso2.mashup.MashupConstants;
-import org.wso2.mashup.utils.MashupUtils;
+import org.wso2.mashup.MashupFault;
+import org.wso2.wsas.ServerManager;
 
 import javax.wsdl.Definition;
 import javax.wsdl.Port;
@@ -82,10 +81,10 @@
 import java.io.StringReader;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.ArrayList;
 
 /**
  * <p/>
@@ -334,14 +333,9 @@
             } else {
                 throw Context.reportRuntimeError("INVALID_SYNTAX_EXCEPTION");
             }
-            Object object = 
cx.getThreadLocal(JavaScriptEngineConstants.AXIS2_MESSAGECONTEXT);
-            if (!(object instanceof MessageContext)) {
-                MessageContext messageContext = (MessageContext) object;
-                wsRequest.sender =
-                        new 
ServiceClient(messageContext.getConfigurationContext(), null);
-            } else {
-                wsRequest.sender = new ServiceClient();
-            }
+            ServerManager serverManager = ServerManager.getInstance();
+            wsRequest.sender =
+                    new ServiceClient(serverManager.configContext, null);
 
             Options options = getOptionsObject(httpMethod, httpLocation, 
httpLocationIgnoreUncited,
                                                httpQueryParameterSeparator, 
httpInputSerialization,

_______________________________________________
Mashup-dev mailing list
[email protected]
http://www.wso2.org/cgi-bin/mailman/listinfo/mashup-dev

Reply via email to