[jbpm-commits] JBoss JBPM SVN: r2631 - in projects/gwt-console/trunk/war/src: main/java/org/jboss/bpm/console/client and 7 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Oct 27 13:25:05 EDT 2008


Author: heiko.braun at jboss.com
Date: 2008-10-27 13:25:05 -0400 (Mon, 27 Oct 2008)
New Revision: 2631

Added:
   projects/gwt-console/trunk/war/src/test/resources/org/
   projects/gwt-console/trunk/war/src/test/resources/org/jboss/
   projects/gwt-console/trunk/war/src/test/resources/org/jboss/bpm/
   projects/gwt-console/trunk/war/src/test/resources/org/jboss/bpm/console/
   projects/gwt-console/trunk/war/src/test/resources/org/jboss/bpm/console/client/
   projects/gwt-console/trunk/war/src/test/resources/org/jboss/bpm/console/client/SampleProcess.par
Modified:
   projects/gwt-console/trunk/war/src/main/java/jmaki/xhp/HttpClient.java
   projects/gwt-console/trunk/war/src/main/java/jmaki/xhp/XmlHttpProxyServlet.java
   projects/gwt-console/trunk/war/src/main/java/org/jboss/bpm/console/client/ConsoleView.java
   projects/gwt-console/trunk/war/src/test/java/org/jboss/bpm/console/client/GwtTestApplication.java
Log:
Improve logging XmlHttpProxy. Fix stderr redirect which causes GwtTest to interpret log output as failure

Modified: projects/gwt-console/trunk/war/src/main/java/jmaki/xhp/HttpClient.java
===================================================================
--- projects/gwt-console/trunk/war/src/main/java/jmaki/xhp/HttpClient.java	2008-10-27 16:18:55 UTC (rev 2630)
+++ projects/gwt-console/trunk/war/src/main/java/jmaki/xhp/HttpClient.java	2008-10-27 17:25:05 UTC (rev 2631)
@@ -19,238 +19,246 @@
  */
 public class HttpClient {
 
-    private static Logger logger;
-    private String proxyHost = null;
-    private int proxyPort = -1;
-    private boolean isHttps = false;
-    private boolean isProxy = false;
-    private HttpURLConnection urlConnection = null;
-    private Map headers;
+   private static Logger logger;
+   private String proxyHost = null;
+   private int proxyPort = -1;
+   private boolean isHttps = false;
+   private boolean isProxy = false;
+   private HttpURLConnection urlConnection = null;
+   private Map headers;
 
-    /**
-     * @param phost PROXY host name
-     * @param pport PROXY port string
-     * @param url URL string
-     * @param headers Map
-     */
-    public HttpClient(
-            String phost,
-            int pport,
-            String url,
-            Map headers,
-            String method)
-            throws MalformedURLException
-    {
-        if (phost != null && pport != -1)
-        {
+   /**
+    * @param phost PROXY host name
+    * @param pport PROXY port string
+    * @param url URL string
+    * @param headers Map
+    */
+   public HttpClient(
+         String phost,
+         int pport,
+         String url,
+         Map headers,
+         String method)
+         throws MalformedURLException
+   {
+      if (phost != null && pport != -1)
+      {
+         this.isProxy = true;
+      }
+
+      this.proxyHost = phost;
+      this.proxyPort = pport;
+
+      if (url.trim().startsWith("https:")) {
+         isHttps = true;
+      }
+
+      this.urlConnection = getURLConnection(url);
+      try {
+         this.urlConnection.setRequestMethod(method);
+      } catch (java.net.ProtocolException pe) {
+         HttpClient.getLogger().severe("Unable protocol method to " + method + " : " + pe);
+      }
+      this.headers = headers;
+      // seat headers
+      if (headers != null) {
+         Iterator it = headers.keySet().iterator();
+         if (it != null) {
+            while (it.hasNext()) {
+               String key = (String)it.next();
+               String value = (String)headers.get(key);
+               this.urlConnection.setRequestProperty (key, value);
+            }
+         }
+      }
+   }
+
+   /**
+    * @param phost PROXY host name
+    * @param pport PROXY port string
+    * @param url URL string
+    * @param headers Map
+    * @param userName string
+    * @param password string
+    */
+   public HttpClient(String phost,
+                     int pport,
+                     String url,
+                     Map headers,
+                     String method,
+                     String userName,
+                     String password)
+         throws MalformedURLException {
+      try
+      {
+         if (phost != null && pport != -1) {
             this.isProxy = true;
-        }
+         }
 
-        this.proxyHost = phost;
-        this.proxyPort = pport;
-
-        if (url.trim().startsWith("https:")) {
+         this.proxyHost = phost;
+         this.proxyPort = pport;
+         if (url.trim().startsWith("https:")) {
             isHttps = true;
-        }
-
-        this.urlConnection = getURLConnection(url);
-        try {
+         }
+         this.urlConnection = getURLConnection(url);
+         try {
             this.urlConnection.setRequestMethod(method);
-        } catch (java.net.ProtocolException pe) {
+         } catch (java.net.ProtocolException pe) {
             HttpClient.getLogger().severe("Unable protocol method to " + method + " : " + pe);
-        }
-        this.headers = headers;
-        // seat headers
-        if (headers != null) {
-            Iterator it = headers.keySet().iterator();
+         }
+         // set basic authentication information
+         String auth = userName + ":" +  password;
+         String encoded = new sun.misc.BASE64Encoder().encode (auth.getBytes());
+         // set basic authorization
+         this.urlConnection.setRequestProperty ("Authorization", "Basic " + encoded);
+         this.headers = headers;
+         // seat headers
+         if (headers != null) {
+            Iterator it = headers.entrySet().iterator();
             if (it != null) {
-                while (it.hasNext()) {
-                    String key = (String)it.next();
-                    String value = (String)headers.get(key);
-                    this.urlConnection.setRequestProperty (key, value);
-                }
+               while (it.hasNext()) {
+                  String key = (String)it.next();
+                  String value = (String)headers.get(key);
+                  this.urlConnection.setRequestProperty (key, value);
+               }
             }
-        }
-    }
+         }
+      } catch (Exception ex) {
+         HttpClient.getLogger().severe("Unable to set basic authorization for " + userName  + " : " +ex);
+      }
+   }
 
-    /**
-     * @param phost PROXY host name
-     * @param pport PROXY port string
-     * @param url URL string
-     * @param headers Map
-     * @param userName string
-     * @param password string
-     */
-    public HttpClient(String phost,
-                      int pport,
-                      String url,
-                      Map headers,
-                      String method,
-                      String userName,
-                      String password)
-            throws MalformedURLException {
-        try
-        {
-            if (phost != null && pport != -1) {
-                this.isProxy = true;
-            }
+   /**
+    * private method to get the URLConnection
+    * @param str URL string
+    */
+   private HttpURLConnection getURLConnection(String str)
+         throws MalformedURLException {
+      try {
 
-            this.proxyHost = phost;
-            this.proxyPort = pport;
-            if (url.trim().startsWith("https:")) {
-                isHttps = true;
+         if (isHttps) {
+            /* when communicating with the server which has unsigned or invalid
+            * certificate (https), SSLException or IOException is thrown.
+            * the following line is a hack to avoid that
+            */
+            Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
+            System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
+            if (isProxy) {
+               System.setProperty("https.proxyHost", proxyHost);
+               System.setProperty("https.proxyPort", proxyPort + "");
             }
-            this.urlConnection = getURLConnection(url);
-            try {
-                this.urlConnection.setRequestMethod(method);
-            } catch (java.net.ProtocolException pe) {
-                HttpClient.getLogger().severe("Unable protocol method to " + method + " : " + pe);
-            }
-            // set basic authentication information
-            String auth = userName + ":" +  password;
-            String encoded = new sun.misc.BASE64Encoder().encode (auth.getBytes());
-            // set basic authorization
-            this.urlConnection.setRequestProperty ("Authorization", "Basic " + encoded);
-            this.headers = headers;
-            // seat headers
-            if (headers != null) {
-                Iterator it = headers.entrySet().iterator();
-                if (it != null) {
-                    while (it.hasNext()) {
-                        String key = (String)it.next();
-                        String value = (String)headers.get(key);
-                        this.urlConnection.setRequestProperty (key, value);
-                    }
-                }
-            }
-        } catch (Exception ex) {
-            HttpClient.getLogger().severe("Unable to set basic authorization for " + userName  + " : " +ex);
-        }
-    }
-
-    /**
-     * private method to get the URLConnection
-     * @param str URL string
-     */
-    private HttpURLConnection getURLConnection(String str)
-            throws MalformedURLException {
-        try {
-
-            if (isHttps) {
-                /* when communicating with the server which has unsigned or invalid
-                * certificate (https), SSLException or IOException is thrown.
-                * the following line is a hack to avoid that
-                */
-                Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
-                System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
-                if (isProxy) {
-                    System.setProperty("https.proxyHost", proxyHost);
-                    System.setProperty("https.proxyPort", proxyPort + "");
-                }
-            }
-            else
+         }
+         else
+         {
+            if (isProxy)
             {
-                if (isProxy)
-                {
-                    System.setProperty("http.proxyHost", proxyHost);
-                    System.setProperty("http.proxyPort", proxyPort  + "");
-                }
+               System.setProperty("http.proxyHost", proxyHost);
+               System.setProperty("http.proxyPort", proxyPort  + "");
             }
+         }
 
-            URL url = new URL(str);
-            HttpURLConnection uc = (HttpURLConnection)url.openConnection();
-            // if this header has not been set by a request set the user agent.
-            if (headers == null ||
-                    (headers != null &&  headers.get("user-agent") == null)) {
-                // set user agent to mimic a common browser
-                String ua="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)";
-                uc.setRequestProperty("user-agent", ua);
-            }
-            return uc;
-        }
-        catch (MalformedURLException me)
-        {
-            throw new MalformedURLException(str + " is not a valid URL");
-        }
-        catch (Exception e)
-        {
-            throw new RuntimeException("Unknown error creating UrlConnection: " + e);            
-        }
-    }
+         URL url = new URL(str);
+         HttpURLConnection uc = (HttpURLConnection)url.openConnection();
+         // if this header has not been set by a request set the user agent.
+         if (headers == null ||
+               (headers != null &&  headers.get("user-agent") == null)) {
+            // set user agent to mimic a common browser
+            String ua="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)";
+            uc.setRequestProperty("user-agent", ua);
+         }
+         return uc;
+      }
+      catch (MalformedURLException me)
+      {
+         throw new MalformedURLException(str + " is not a valid URL");
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException("Unknown error creating UrlConnection: " + e);
+      }
+   }
 
-    /**
-     * returns the inputstream from URLConnection
-     * @return InputStream
-     */
-    public InputStream getInputStream() {
-        try {
-            return (this.urlConnection.getInputStream());
-        } catch (Exception e) {
-            e.printStackTrace();
-            return null;
-        }
-    }
+   /**
+    * returns the inputstream from URLConnection
+    * @return InputStream
+    */
+   public InputStream getInputStream() {
+      try
+      {
+         // logger doesnt work, because it writes to stderr,
+         // which causes GwtTest to interpret it as failure
+         System.out.println(
+               this.urlConnection.getRequestMethod()+ " " +
+                     this.urlConnection.getURL() +": "+
+                     this.urlConnection.getResponseCode()
+         );
+         return (this.urlConnection.getInputStream());
+      } catch (Exception e) {
+         e.printStackTrace();
+         return null;
+      }
+   }
 
-    /**
-     * return the OutputStream from URLConnection
-     * @return OutputStream
-     */
-    public OutputStream getOutputStream() {
+   /**
+    * return the OutputStream from URLConnection
+    * @return OutputStream
+    */
+   public OutputStream getOutputStream() {
 
-        try {
-            return (this.urlConnection.getOutputStream());
-        } catch (Exception e) {
-            e.printStackTrace();
-            return null;
-        }
-    }
+      try {
+         return (this.urlConnection.getOutputStream());
+      } catch (Exception e) {
+         e.printStackTrace();
+         return null;
+      }
+   }
 
-    /**
-     * posts data to the inputstream and returns the InputStream.
-     * @param postData data to be posted. must be url-encoded already.
-     * @param contentType allows you to set the contentType of the request.
-     * @return InputStream input stream from URLConnection
-     */
-    public InputStream doPost(String postData, String contentType) {
-        this.urlConnection.setDoOutput(true);
-        if (contentType != null) this.urlConnection.setRequestProperty( "Content-type", contentType );
+   /**
+    * posts data to the inputstream and returns the InputStream.
+    * @param postData data to be posted. must be url-encoded already.
+    * @param contentType allows you to set the contentType of the request.
+    * @return InputStream input stream from URLConnection
+    */
+   public InputStream doPost(String postData, String contentType) {
+      this.urlConnection.setDoOutput(true);
+      if (contentType != null) this.urlConnection.setRequestProperty( "Content-type", contentType );
 
-        OutputStream os = this.getOutputStream();
-        PrintStream ps = new PrintStream(os);
-        ps.print(postData);
-        ps.close();
-        return (this.getInputStream());
-    }
+      OutputStream os = this.getOutputStream();
+      PrintStream ps = new PrintStream(os);
+      ps.print(postData);
+      ps.close();
+      return (this.getInputStream());
+   }
 
-    public String getContentEncoding() {
-        if (this.urlConnection == null) return null;
-        return (this.urlConnection.getContentEncoding());
-    }
-    public int getContentLength() {
-        if (this.urlConnection == null) return -1;
-        return (this.urlConnection.getContentLength());
-    }
-    public String getContentType() {
-        if (this.urlConnection == null) return null;
-        return (this.urlConnection.getContentType());
-    }
-    public long getDate() {
-        if (this.urlConnection == null) return -1;
-        return (this.urlConnection.getDate());
-    }
-    public String getHeader(String name) {
-        if (this.urlConnection == null) return null;
-        return (this.urlConnection.getHeaderField(name));
-    }
-    public long getIfModifiedSince() {
-        if (this.urlConnection == null) return -1;
-        return (this.urlConnection.getIfModifiedSince());
-    }
+   public String getContentEncoding() {
+      if (this.urlConnection == null) return null;
+      return (this.urlConnection.getContentEncoding());
+   }
+   public int getContentLength() {
+      if (this.urlConnection == null) return -1;
+      return (this.urlConnection.getContentLength());
+   }
+   public String getContentType() {
+      if (this.urlConnection == null) return null;
+      return (this.urlConnection.getContentType());
+   }
+   public long getDate() {
+      if (this.urlConnection == null) return -1;
+      return (this.urlConnection.getDate());
+   }
+   public String getHeader(String name) {
+      if (this.urlConnection == null) return null;
+      return (this.urlConnection.getHeaderField(name));
+   }
+   public long getIfModifiedSince() {
+      if (this.urlConnection == null) return -1;
+      return (this.urlConnection.getIfModifiedSince());
+   }
 
-    public static Logger getLogger() {
-        if (logger == null) {
-            logger = Logger.getLogger("jmaki.xhp.Log");
-        }
-        return logger;
-    }
+   public static Logger getLogger() {
+      if (logger == null) {
+         logger = Logger.getLogger("jmaki.xhp.Log");
+      }
+      return logger;
+   }
 }
\ No newline at end of file

Modified: projects/gwt-console/trunk/war/src/main/java/jmaki/xhp/XmlHttpProxyServlet.java
===================================================================
--- projects/gwt-console/trunk/war/src/main/java/jmaki/xhp/XmlHttpProxyServlet.java	2008-10-27 16:18:55 UTC (rev 2630)
+++ projects/gwt-console/trunk/war/src/main/java/jmaki/xhp/XmlHttpProxyServlet.java	2008-10-27 17:25:05 UTC (rev 2631)
@@ -161,7 +161,7 @@
       OutputStream out = null;
       PrintWriter writer = null;
       String serviceKey = null;
-      /*try {
+      try {
         BufferedReader in = req.getReader();
         String line = null;
         while ((line = in.readLine()) != null) {
@@ -169,7 +169,7 @@
            bodyContent.append(line);
         }
      } catch (Exception e) {
-     } */
+     } 
 
       try
       {
@@ -340,8 +340,6 @@
             }
          }
 
-         getLogger().info("XmlHttpProxy target url: " + urlString);
-
          if (!isPost)
          {
             xhp.processRequest(urlString, out, xslInputStream, paramsMap, headers, method, userName, password);

Modified: projects/gwt-console/trunk/war/src/main/java/org/jboss/bpm/console/client/ConsoleView.java
===================================================================
--- projects/gwt-console/trunk/war/src/main/java/org/jboss/bpm/console/client/ConsoleView.java	2008-10-27 16:18:55 UTC (rev 2630)
+++ projects/gwt-console/trunk/war/src/main/java/org/jboss/bpm/console/client/ConsoleView.java	2008-10-27 17:25:05 UTC (rev 2631)
@@ -237,4 +237,5 @@
    {
       return rolesAssigned;
    }
+
 }

Modified: projects/gwt-console/trunk/war/src/test/java/org/jboss/bpm/console/client/GwtTestApplication.java
===================================================================
--- projects/gwt-console/trunk/war/src/test/java/org/jboss/bpm/console/client/GwtTestApplication.java	2008-10-27 16:18:55 UTC (rev 2630)
+++ projects/gwt-console/trunk/war/src/test/java/org/jboss/bpm/console/client/GwtTestApplication.java	2008-10-27 17:25:05 UTC (rev 2631)
@@ -21,10 +21,13 @@
  */
 package org.jboss.bpm.console.client;
 
+import com.google.gwt.http.client.Request;
+import com.google.gwt.http.client.Response;
 import com.google.gwt.junit.client.GWTTestCase;
 import com.google.gwt.user.client.Timer;
-import com.google.gwt.http.client.Request;
-import com.google.gwt.http.client.Response;
+import com.gwtext.client.widgets.ComponentMgr;
+import org.jboss.bpm.console.client.process.ProcessDefinitionList;
+import org.jboss.bpm.console.client.process.ProcessDefinitionListEditor;
 
 /**
  * @author Heiko.Braun <heiko.braun at jboss.com>
@@ -32,68 +35,116 @@
 public class GwtTestApplication extends GWTTestCase
 {
 
-    private static Application application = null;
+   private static Application application = null;
 
-    public String getModuleName()
-    {
-        return "org.jboss.bpm.console.Application";
-    }
+   public String getModuleName()
+   {
+      return "org.jboss.bpm.console.Application";
+   }
 
 
-    protected void gwtSetUp() throws Exception
-    {
-        super.gwtSetUp();
-        if(null==application)
-        {
-            application = new Application();
-            application.onModuleLoad();
-        }
+   protected void gwtSetUp() throws Exception
+   {
+      super.gwtSetUp();
+      if(null==application)
+      {
+         application = new Application();
+         application.onModuleLoad();
+      }
 
-    }
+   }
 
-    public void testAuthentication()
-    {
-        final ConsoleView view = application.getConsoleView();
-        assertNotNull("View not initialized", view);
+   public void testAuthentication()
+   {
+      final ConsoleView view = application.getConsoleView();
+      assertNotNull("View not initialized", view);
 
-        DeferredExecution authTestPiece = new DeferredExecution()
-        {
-            public void execute() {
+      Timer timer = new Timer()
+      {
+         public void run()
+         {
 
-                String inRoleURL = view.getUrlBuilder().getUserInRoleURL(ConsoleView.KNOWN_ROLES);
-                final Authentication auth = new Authentication(inRoleURL);
-                auth.setCallback(
-                        new Authentication.AuthCallback() {
+            String inRoleURL = view.getUrlBuilder().getUserInRoleURL(ConsoleView.KNOWN_ROLES);
+            final Authentication auth = new Authentication(inRoleURL);
+            auth.setCallback(
+                  new Authentication.AuthCallback() {
 
-                            public void onLoginSuccess(Request request, Response response) {
-                                System.out.println("Assigned roles: " + auth.getRolesAssigned() );
-                            }
+                     public void onLoginSuccess(Request request, Response response) {
+                        System.out.println("Assigned roles: " + auth.getRolesAssigned() );
+                     }
 
-                            public void onLoginFailed(Request request, Throwable t) {
+                     public void onLoginFailed(Request request, Throwable t) {
 
-                                throw new RuntimeException("Login failed", t);
-                            }
-                        }
-                );
-                auth.doLogin();
-            }
-        };
+                        throw new RuntimeException("Login failed", t);
+                     }
+                  }
+            );
+            auth.doLogin();
+            finishTest();
+         }
 
-        deferredExec(authTestPiece);
-    }
 
-    private void deferredExec(final DeferredExecution testPiece) {
-        Timer timer = new Timer()
-        {
-            public void run()
-            {
+      };
 
-                testPiece.execute();
-                finishTest();
-            }
-        };
+      timer.schedule(300);
+      delayTestFinish(500);
+   }
 
-        timer.schedule(300);
-        delayTestFinish(500);
-    }
+   public void testProcessDefList()
+   {
+      final ConsoleView view = application.getConsoleView();
+      assertNotNull("View not initialized", view);
+
+
+
+      Timer pdlTimer = new Timer(){
+
+         public void run()
+         {
+            System.out.println("Verify process definition list");
+            ProcessDefinitionListEditor editor = (ProcessDefinitionListEditor)
+                  ComponentMgr.getComponent(ProcessDefinitionListEditor.ID);
+
+            ProcessDefinitionList list = editor.getProcessDefinitionList();
+
+            System.out.println("Got " + list.getAvailableProcessDefinitions().size() + " definitions");
+            assertFalse("No process definitions loaded",
+                  list.getAvailableProcessDefinitions().isEmpty()
+            );
+
+            finishTest();
+         }
+      };
+
+      Timer pdlLoadTimer = new Timer(){
+
+         public void run()
+         {
+            System.out.println("Fetch process definitions");
+            ProcessDefinitionListEditor editor = (ProcessDefinitionListEditor)
+                  ComponentMgr.getComponent(ProcessDefinitionListEditor.ID);
+
+            ProcessDefinitionList list = editor.getProcessDefinitionList();
+            list.reloadStore();
+         }
+      };
+
+      Timer authTimer = new Timer()
+      {
+         public void run()
+         {
+            System.out.println("Do authentication");
+            String inRoleURL = view.getUrlBuilder().getUserInRoleURL(ConsoleView.KNOWN_ROLES);
+            final Authentication auth = new Authentication(inRoleURL);
+            auth.doLogin();
+
+         }
+      };
+
+      authTimer.schedule(200);
+      pdlLoadTimer.schedule(400);
+      pdlTimer.schedule(600);
+
+      delayTestFinish(800);
+   }
 }

Added: projects/gwt-console/trunk/war/src/test/resources/org/jboss/bpm/console/client/SampleProcess.par
===================================================================
(Binary files differ)


Property changes on: projects/gwt-console/trunk/war/src/test/resources/org/jboss/bpm/console/client/SampleProcess.par
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream




More information about the jbpm-commits mailing list