Author: keith
Date: Sun Jul 13 07:21:12 2008
New Revision: 19194
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=19194

Log:
More clen up of errors thrown


Modified:
   
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/file/JavaScriptFileObject.java
   
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/im/IM.java
   
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/scraper/ScraperHostObject.java
   
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/session/SessionHostObject.java
   
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/system/FunctionSchedulingJob.java
   
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/wsrequest/WSRequestHostImpl.java
   
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/wsrequest/WebServiceErrorHostObject.java

Modified: 
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/file/JavaScriptFileObject.java
URL: 
http://wso2.org/svn/browse/wso2/trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/file/JavaScriptFileObject.java?rev=19194&r1=19193&r2=19194&view=diff
==============================================================================
--- 
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/file/JavaScriptFileObject.java
        (original)
+++ 
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/file/JavaScriptFileObject.java
        Sun Jul 13 07:21:12 2008
@@ -34,6 +34,7 @@
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.Writer;
+import java.io.FileNotFoundException;
 import java.util.Date;
 
 /**
@@ -58,7 +59,7 @@
     private BufferedReader reader;
 
     public static Scriptable jsConstructor(Context cx, Object[] args, Function 
ctorObj,
-                                           boolean inNewExpr) throws 
IOException {
+                                           boolean inNewExpr) throws 
MashupFault {
         JavaScriptFileObject result = new JavaScriptFileObject();
 
         // Falling back to use AxisService as MessageContext is not available 
in deployment time.
@@ -122,12 +123,16 @@
      *
      * @throws IOException if the file is already open for either appending or 
reading, if the file does not exist, if the file cannot be opened for any other 
file system specific reason.
      */
-    public void jsFunction_openForReading() throws IOException {
+    public void jsFunction_openForReading() throws MashupFault {
         if (writer != null)
             throw new MashupFault(
                     "Cannot read from the already writing file. Please close 
the file beforehand by calling close().");
         if (reader == null) {
-            reader = new BufferedReader(new FileReader(file));
+            try {
+                reader = new BufferedReader(new FileReader(file));
+            } catch (FileNotFoundException e) {
+                throw new MashupFault(e);
+            }
         }
     }
 
@@ -138,7 +143,7 @@
      *
      * @throws IOException if the file is already open for either appending or 
reading, if the file cannot be opened for any other file system specific reason.
      */
-    public void jsFunction_openForWriting() throws IOException {
+    public void jsFunction_openForWriting() throws MashupFault {
         getWriter(false);
     }
 
@@ -149,7 +154,7 @@
      *
      * @throws IOException if the file is already open for either writing or 
reading, if the file cannot be opened for any other file system specific reason.
      */
-    public void jsFunction_openForAppending() throws IOException {
+    public void jsFunction_openForAppending() throws MashupFault {
         getWriter(true);
     }
 
@@ -169,13 +174,17 @@
      * @param object
      * @throws IOException
      */
-    public void jsFunction_write(Object object) throws IOException {
+    public void jsFunction_write(Object object) throws MashupFault {
         if (writer == null && reader == null) {
             getWriter(false);
         }
         if (writer != null) {
-            writer.write(Context.toString(object));
-            writer.flush();
+            try {
+                writer.write(Context.toString(object));
+                writer.flush();
+            } catch (IOException e) {
+                throw new MashupFault(e);
+            }
         } else {
             throw new MashupFault(
                     "File not open for writing. Please call 
openFileFor{Writing|Appending}() accordingly beforehand. ");
@@ -198,10 +207,14 @@
      * @param object
      * @throws IOException
      */
-    public void jsFunction_writeLine(Object object) throws IOException {
+    public void jsFunction_writeLine(Object object) throws MashupFault {
         jsFunction_write(object);
-        writer.newLine();
-        writer.flush();
+        try {
+            writer.newLine();
+            writer.flush();
+        } catch (IOException e) {
+            throw new MashupFault(e);
+        }
     }
 
     /**
@@ -220,7 +233,7 @@
      * @param noOfCharacters of characters to be read
      * @throws IOException
      */
-    public String jsFunction_read(int noOfCharacters) throws IOException {
+    public String jsFunction_read(int noOfCharacters) throws MashupFault {
         if (writer == null && reader == null) {
             jsFunction_openForReading();
         }
@@ -229,12 +242,16 @@
             int index = 0;
             StringBuffer buffer2 = new StringBuffer();
             int count;
-            while (((count = reader.read(buffer)) > 0) & index < 
noOfCharacters) {
-                buffer2.append(buffer);
-                index += count;
-                if (index < noOfCharacters) {
-                    buffer = new char[noOfCharacters - index];
+            try {
+                while (((count = reader.read(buffer)) > 0) & index < 
noOfCharacters) {
+                    buffer2.append(buffer);
+                    index += count;
+                    if (index < noOfCharacters) {
+                        buffer = new char[noOfCharacters - index];
+                    }
                 }
+            } catch (IOException e) {
+                throw new MashupFault(e);
             }
             return buffer2.toString();
         }
@@ -257,12 +274,16 @@
      *
      * @throws IOException
      */
-    public String jsFunction_readLine() throws IOException {
+    public String jsFunction_readLine() throws MashupFault {
         if (writer == null && reader == null) {
             jsFunction_openForReading();
         }
         if (reader != null) {
-            return reader.readLine();
+            try {
+                return reader.readLine();
+            } catch (IOException e) {
+                throw new MashupFault(e);
+            }
         }
         throw new MashupFault(
                 "File not open for reading. Please call openFileForReading() 
beforehand. ");
@@ -283,19 +304,23 @@
      *
      * @throws IOException
      */
-    public String jsFunction_readAll() throws IOException {
+    public String jsFunction_readAll() throws MashupFault {
         if (writer == null && reader == null) {
             jsFunction_openForReading();
         }
-        if (reader != null) {
-            StringBuffer stringBuffer = new StringBuffer();
-            BufferedReader reader = new BufferedReader(new FileReader(file));
-            String lineText;
-            while ((lineText = reader.readLine()) != null) {
-                stringBuffer.append(lineText);
+        try {
+            if (reader != null) {
+                StringBuffer stringBuffer = new StringBuffer();
+                BufferedReader reader = new BufferedReader(new 
FileReader(file));
+                String lineText;
+                while ((lineText = reader.readLine()) != null) {
+                    stringBuffer.append(lineText);
+                }
+                reader.close();
+                return stringBuffer.toString();
             }
-            reader.close();
-            return stringBuffer.toString();
+        } catch (IOException e) {
+            throw new MashupFault(e);
         }
         throw new MashupFault(
                 "File not open for reading. Please call openFileForReading() 
beforehand. ");
@@ -315,13 +340,17 @@
      *
      * @throws IOException
      */
-    public void jsFunction_close() throws IOException {
-        if (writer != null) {
-            writer.close();
-            writer = null;
-        } else if (reader != null) {
-            reader.close();
-            reader = null;
+    public void jsFunction_close() throws MashupFault {
+        try {
+            if (writer != null) {
+                writer.close();
+                writer = null;
+            } else if (reader != null) {
+                reader.close();
+                reader = null;
+            }
+        } catch (IOException e) {
+            throw new MashupFault(e);
         }
     }
 
@@ -334,13 +363,17 @@
      *
      * @throws IOException
      */
-    public boolean jsFunction_createFile() throws IOException {
+    public boolean jsFunction_createFile() throws MashupFault {
         if (!file.exists()) {
             File parentFile = file.getParentFile();
             if (parentFile != null) {
                 parentFile.mkdirs();
             }
-            return file.createNewFile();
+            try {
+                return file.createNewFile();
+            } catch (IOException e) {
+                throw new MashupFault(e);
+            }
         }
         return false;
     }
@@ -353,10 +386,10 @@
      * @throws IOException
      */
     public static boolean jsFunction_move(Context cx, Scriptable thisObj, 
Object[] arguments,
-                                          Function funObj) throws IOException {
-        boolean result = false;
+                                          Function funObj) throws MashupFault {
+        boolean result;
         JavaScriptFileObject fileObject = (JavaScriptFileObject) thisObj;
-        String fileName = null;
+        String fileName;
         try {
 
             if (arguments[0] instanceof String) {
@@ -402,7 +435,7 @@
 
             BufferedWriter destination = new BufferedWriter(new 
FileWriter(newFile));
 
-            String str = null;
+            String str;
 
             // Copying contents to new location
             while ((str = source.readLine()) != null) {
@@ -422,7 +455,7 @@
 
             result = true;
         } catch (IOException e) {
-            throw new MashupFault(e.getMessage());
+            throw new MashupFault(e);
         }
 
         return result;
@@ -440,7 +473,7 @@
         return false;
     }
 
-    public String jsFunction_toString() throws IOException {
+    public String jsFunction_toString() throws MashupFault {
         return jsFunction_readAll();
     }
 
@@ -482,14 +515,18 @@
         return file.exists();
     }
 
-    private Writer getWriter(boolean append) throws IOException {
+    private Writer getWriter(boolean append) throws MashupFault {
         jsFunction_createFile();
         if (reader != null) {
             throw new MashupFault(
                     "Cannot write to the already reading file. Please close 
the file beforehand by calling close().");
         }
         if (writer == null) {
-            writer = new BufferedWriter(new FileWriter(file, append));
+            try {
+                writer = new BufferedWriter(new FileWriter(file, append));
+            } catch (IOException e) {
+                throw new MashupFault(e);
+            }
         }
         return writer;
     }

Modified: 
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/im/IM.java
URL: 
http://wso2.org/svn/browse/wso2/trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/im/IM.java?rev=19194&r1=19193&r2=19194&view=diff
==============================================================================
--- 
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/im/IM.java
    (original)
+++ 
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/im/IM.java
    Sun Jul 13 07:21:12 2008
@@ -26,9 +26,6 @@
 import org.wso2.mashup.MashupFault;
 import org.wso2.utils.ServerConfiguration;
 
-import java.io.IOException;
-
-
 /**
  * <p/>
  * The IM host object is a generic host object designed to send Instant 
Messages (IM) using various
@@ -97,7 +94,7 @@
     private String protocol;
 
     public static Scriptable jsConstructor(Context cx, Object[] args, Function 
ctorObj,
-                                           boolean inNewExpr) throws 
IOException {
+                                           boolean inNewExpr) throws 
MashupFault {
         IM im = new IM();
 
         if (args.length == 1 & args[0] instanceof String) {
@@ -128,7 +125,7 @@
 
     public static void jsFunction_login(Context cx, Scriptable thisObj, 
Object[] args,
                                         Function funObj)
-            throws IMException, MashupFault {
+            throws MashupFault {
         IM im = (IM) thisObj;
         String username;
         String password;
@@ -159,14 +156,26 @@
                     "details specified in the server.xml call this method with 
0 parameters else " +
                     "pass in the username and password");
         }
-        im.imWrapper.login(username, password);
+        try {
+            im.imWrapper.login(username, password);
+        } catch (IMException e) {
+            throw new MashupFault(e);
+        }
     }
 
-    public void jsFunction_sendMessage(String to, String message) throws 
IMException {
-        imWrapper.sendMessage(to, message);
+    public void jsFunction_sendMessage(String to, String message) throws 
MashupFault {
+        try {
+            imWrapper.sendMessage(to, message);
+        } catch (IMException e) {
+            throw new MashupFault(e);
+        }
     }
 
-    public void jsFunction_disconnect() throws IMException {
-        imWrapper.disconnect();
+    public void jsFunction_disconnect() throws MashupFault {
+        try {
+            imWrapper.disconnect();
+        } catch (IMException e) {
+            throw new MashupFault(e);
+        }
     }
 }

Modified: 
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/scraper/ScraperHostObject.java
URL: 
http://wso2.org/svn/browse/wso2/trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/scraper/ScraperHostObject.java?rev=19194&r1=19193&r2=19194&view=diff
==============================================================================
--- 
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/scraper/ScraperHostObject.java
        (original)
+++ 
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/scraper/ScraperHostObject.java
        Sun Jul 13 07:21:12 2008
@@ -42,7 +42,7 @@
 import javax.xml.stream.XMLStreamException;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.IOException;
+import java.io.FileNotFoundException;
 
 public class ScraperHostObject extends ScriptableObject {
 
@@ -52,7 +52,7 @@
     private String resourcesFolderPath;
 
     public static Scriptable jsConstructor(Context cx, Object[] args, Function 
ctorObj,
-                                           boolean inNewExpr) throws 
IOException {
+                                           boolean inNewExpr) throws 
MashupFault {
         ScraperHostObject result = new ScraperHostObject();
 
         // Falling back to use AxisService as MessageContext is not available 
in deployment time.
@@ -83,7 +83,12 @@
                 configElement = (OMElement) xml.getAxiomFromXML();
             } else if (args[0] instanceof File) {
                 File configFile = (File) args[0];
-                FileInputStream fis = new FileInputStream(configFile);
+                FileInputStream fis;
+                try {
+                    fis = new FileInputStream(configFile);
+                } catch (FileNotFoundException e) {
+                    throw new MashupFault(e);
+                }
                 StAXOMBuilder staxOMBuilder;
                 try {
                     staxOMBuilder = new StAXOMBuilder(fis);

Modified: 
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/session/SessionHostObject.java
URL: 
http://wso2.org/svn/browse/wso2/trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/session/SessionHostObject.java?rev=19194&r1=19193&r2=19194&view=diff
==============================================================================
--- 
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/session/SessionHostObject.java
        (original)
+++ 
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/session/SessionHostObject.java
        Sun Jul 13 07:21:12 2008
@@ -23,6 +23,7 @@
 import org.mozilla.javascript.Scriptable;
 import org.mozilla.javascript.ScriptableObject;
 import org.wso2.javascript.rhino.JavaScriptEngineConstants;
+import org.wso2.mashup.MashupFault;
 
 import java.io.IOException;
 import java.util.Hashtable;
@@ -67,7 +68,7 @@
      * @throws IOException
      */
     public static Scriptable jsConstructor(Context cx, Object[] args, Function 
ctorObj,
-                                           boolean inNewExpr) throws 
IOException {
+                                           boolean inNewExpr) throws 
MashupFault {
         SessionHostObject sessionHostObject;
         Object object = 
cx.getThreadLocal(JavaScriptEngineConstants.AXIS2_MESSAGECONTEXT);
         if (object instanceof MessageContext) {

Modified: 
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/system/FunctionSchedulingJob.java
URL: 
http://wso2.org/svn/browse/wso2/trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/system/FunctionSchedulingJob.java?rev=19194&r1=19193&r2=19194&view=diff
==============================================================================
--- 
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
     Sun Jul 13 07:21:12 2008
@@ -26,7 +26,6 @@
 import org.wso2.javascript.rhino.JavaScriptEngine;
 import org.wso2.javascript.rhino.JavaScriptEngineConstants;
 import org.wso2.javascript.rhino.JavaScriptEngineUtils;
-import org.wso2.mashup.MashupConstants;
 import org.wso2.mashup.utils.MashupUtils;
 import org.wso2.wsas.ServerManager;
 

Modified: 
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/wsrequest/WSRequestHostImpl.java
URL: 
http://wso2.org/svn/browse/wso2/trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/wsrequest/WSRequestHostImpl.java?rev=19194&r1=19193&r2=19194&view=diff
==============================================================================
--- 
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
      Sun Jul 13 07:21:12 2008
@@ -179,7 +179,7 @@
      * specification</a> for more details.
      */
     public static void jsFunction_open(Context cx, Scriptable thisObj, 
Object[] arguments,
-                                       Function funObj) throws AxisFault {
+                                       Function funObj) throws MashupFault {
         // Defaults to post
         String httpMethod = "post";
         String url;
@@ -337,8 +337,12 @@
             }
         }
         ServerManager serverManager = ServerManager.getInstance();
-        wsRequest.sender =
-                new ServiceClient(serverManager.configContext, null);
+        try {
+            wsRequest.sender =
+                    new ServiceClient(serverManager.configContext, null);
+        } catch (AxisFault axisFault) {
+            throw new MashupFault(axisFault);
+        }
 
         Options options = getOptionsObject(httpMethod, httpLocation, 
httpLocationIgnoreUncited,
                                            httpQueryParameterSeparator, 
httpInputSerialization,
@@ -356,7 +360,7 @@
      * configure it your self using an options object.
      */
     public static void jsFunction_openWSDL(Context cx, Scriptable thisObj, 
Object[] arguments,
-                                       Function funObj) throws AxisFault {
+                                       Function funObj) throws MashupFault {
         WSRequestHostImpl wsRequest = checkInstance(thisObj);
         if (wsRequest.readyState > 0 && wsRequest.readyState < 4) {
             throw new Error("INVALID_STATE_EXCEPTION");
@@ -619,7 +623,7 @@
      * specification</a> for more details.
      */
     public static void jsFunction_send(Context cx, Scriptable thisObj, 
Object[] arguments,
-                                       Function funObj) throws AxisFault {
+                                       Function funObj) throws MashupFault {
         WSRequestHostImpl wsRequest = (WSRequestHostImpl) thisObj;
         Object payload = null;
         QName operationName = null;
@@ -757,11 +761,11 @@
             if (faultCode != null)
                 wsRequest.error.jsSet_code(faultCode.toString());
             wsRequest.error.jsSet_reason(e.getReason());
-            throw e;
+            throw new MashupFault(e);
         } catch (WSSPolicyException e) {
             wsRequest.error = new WebServiceErrorHostObject();
             wsRequest.error.jsSet_detail(e.getMessage());
-            throw AxisFault.makeFault(e);
+            throw new MashupFault(e);
         }
     }
 
@@ -881,7 +885,7 @@
                                             String username,
                                             String passwd, String useSOAP, 
String useWSA, String useWSS,
                                             String action, NativeArray 
optionsArray,
-                                            WSRequestHostImpl wsRequest) 
throws AxisFault {
+                                            WSRequestHostImpl wsRequest) 
throws MashupFault {
         Options options = new Options();
         options.setProperty(HTTPConstants.CHUNKED, Boolean.FALSE);
         EndpointReference targetEPR = new EndpointReference(url);
@@ -903,8 +907,12 @@
             }
             options.setUserName(username);
             options.setPassword(passwd);
-            wsRequest.sender.engageModule(MashupConstants.RAMPART);
-            wsRequest.sender.engageModule(MashupConstants.ADDRESSING);
+            try {
+                wsRequest.sender.engageModule(MashupConstants.RAMPART);
+                wsRequest.sender.engageModule(MashupConstants.ADDRESSING);
+            } catch (AxisFault axisFault) {
+                throw new MashupFault(axisFault);
+            }
         } else if (username != null) {
             // handle basic authentication
             // set username if not null
@@ -1008,7 +1016,11 @@
                                     AddressingConstants.Final.WSA_NAMESPACE);
             }
             if (action != null) {
-                wsRequest.sender.engageModule(Constants.MODULE_ADDRESSING);
+                try {
+                    wsRequest.sender.engageModule(Constants.MODULE_ADDRESSING);
+                } catch (AxisFault axisFault) {
+                    throw new MashupFault(axisFault);
+                }
                 options.setAction(action);
             } else {
                 throw Context
@@ -1059,14 +1071,14 @@
         return (WSRequestHostImpl) obj;
     }
 
-    private static void setSSLProperties(WSRequestHostImpl wsRequest) throws 
AxisFault {
+    private static void setSSLProperties(WSRequestHostImpl wsRequest) throws 
MashupFault {
         Options options = wsRequest.sender.getOptions();
         String toAddress = options.getTo().getAddress();
         URL url;
         try {
             url = new URL(toAddress);
         } catch (MalformedURLException e) {
-            throw AxisFault.makeFault(e);
+            throw new MashupFault(e);
         }
         if (ServerConstants.HTTPS_TRANSPORT.equals(url.getProtocol())) {
             ProtocolSocketFactory psf = 
MashupUtils.getCustomProtocolSocketFactory();

Modified: 
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/wsrequest/WebServiceErrorHostObject.java
URL: 
http://wso2.org/svn/browse/wso2/trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/wsrequest/WebServiceErrorHostObject.java?rev=19194&r1=19193&r2=19194&view=diff
==============================================================================
--- 
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/wsrequest/WebServiceErrorHostObject.java
      (original)
+++ 
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/wsrequest/WebServiceErrorHostObject.java
      Sun Jul 13 07:21:12 2008
@@ -19,8 +19,7 @@
 import org.mozilla.javascript.Function;
 import org.mozilla.javascript.Scriptable;
 import org.mozilla.javascript.ScriptableObject;
-
-import java.io.IOException;
+import org.wso2.mashup.MashupFault;
 
 public class WebServiceErrorHostObject extends ScriptableObject {
 
@@ -31,7 +30,7 @@
     String detail;
 
     public static Scriptable jsConstructor(Context cx, Object[] args, Function 
ctorObj,
-                                           boolean inNewExpr) throws 
IOException {
+                                           boolean inNewExpr) throws 
MashupFault {
         WebServiceErrorHostObject webServiceErrorHostObject = new 
WebServiceErrorHostObject();
         switch (args.length) {
             case 0:

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

Reply via email to