Save This Page
Home » jboss-5.0.0.CR1-src » org.jboss.console » remote » [javadoc | source]
    1   /*
    2     * JBoss, Home of Professional Open Source
    3     * Copyright 2005, JBoss Inc., and individual contributors as indicated
    4     * by the @authors tag. See the copyright.txt in the distribution for a
    5     * full listing of individual contributors.
    6     *
    7     * This is free software; you can redistribute it and/or modify it
    8     * under the terms of the GNU Lesser General Public License as
    9     * published by the Free Software Foundation; either version 2.1 of
   10     * the License, or (at your option) any later version.
   11     *
   12     * This software is distributed in the hope that it will be useful,
   13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
   14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   15     * Lesser General Public License for more details.
   16     *
   17     * You should have received a copy of the GNU Lesser General Public
   18     * License along with this software; if not, write to the Free
   19     * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
   20     * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
   21     */
   22   package org.jboss.console.remote;
   23   /** Common client utility methods
   24    *
   25    * @author Scott.Stark@jboss.org
   26    * @version $Revision: 37459 $
   27   */
   28   public class Util
   29   {
   30      /** A serialized RemoteMBeanInvocation */
   31      private static String REQUEST_CONTENT_TYPE =
   32         "application/x-java-serialized-object; class=org.jboss.console.remote.RemoteMBeanInvocation";
   33      private static org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(Util.class);
   34   
   35      static
   36      {
   37         /** TODO solve authentication issues!!
   38         // Install the java.net.Authenticator to use
   39         try
   40         {
   41            java.net.Authenticator.setDefault(new org.jboss.security.SecurityAssociationAuthenticator());
   42         }
   43         catch(Exception e)
   44         {
   45            log.warn("Failed to install SecurityAssociationAuthenticator", e);
   46         }
   47          */
   48      }
   49   
   50      /** Post the Invocation as a serialized MarshalledInvocation object. This is
   51       using the URL class for now but this should be improved to a cluster aware
   52       layer with full usage of HTTP 1.1 features, pooling, etc.
   53      */
   54      public static Object invoke (java.net.URL externalURL, RemoteMBeanInvocation mi) throws Exception
   55      {
   56         if( log.isTraceEnabled() )
   57            log.trace("invoke, externalURL="+externalURL);
   58         /* Post the MarshalledInvocation data. This is using the URL class
   59          for now but this should be improved to a cluster aware layer with
   60          full usage of HTTP 1.1 features, pooling, etc.
   61          */
   62         java.net.HttpURLConnection conn = (java.net.HttpURLConnection) externalURL.openConnection();
   63         //if( conn instanceof com.sun.net.ssl.HttpsURLConnection )
   64         //{
   65            // See if the org.jboss.security.ignoreHttpsHost property is set
   66            /*
   67            if( Boolean.getBoolean("org.jboss.security.ignoreHttpsHost") == true )
   68            {
   69               com.sun.net.ssl.HttpsURLConnection sconn = (com.sun.net.ssl.HttpsURLConnection) conn;
   70               AnyhostVerifier verifier = new AnyhostVerifier();
   71               sconn.setHostnameVerifier(verifier);
   72            }
   73             **/
   74         //}
   75         conn.setDoInput(true);
   76         conn.setDoOutput(true);
   77         conn.setRequestProperty("ContentType", REQUEST_CONTENT_TYPE);
   78         conn.setRequestMethod("POST");
   79         java.io.OutputStream os = conn.getOutputStream();
   80         java.io.ObjectOutputStream oos = new java.io.ObjectOutputStream(os);
   81         oos.writeObject(mi);
   82         oos.flush();
   83   
   84         // Get the response MarshalledValue object
   85         java.io.InputStream is = conn.getInputStream();
   86         java.io.ObjectInputStream ois = new java.io.ObjectInputStream(is);
   87         org.jboss.invocation.MarshalledValue mv = (org.jboss.invocation.MarshalledValue) ois.readObject();
   88         ois.close();
   89         oos.close();
   90   
   91         // If the encoded value is an exception throw it
   92         Object value = mv.get();
   93         
   94         if( value instanceof org.jboss.invocation.InvocationException )
   95            throw (Exception) (((org.jboss.invocation.InvocationException)value).getTargetException ());
   96   
   97         if( value instanceof Exception )
   98            throw (Exception) value;
   99   
  100         return value;
  101      }
  102   
  103      public static Object getAttribute (java.net.URL externalURL, RemoteMBeanAttributeInvocation mi) throws Exception
  104      {
  105         if( log.isTraceEnabled() )
  106            log.trace("invoke, externalURL="+externalURL);
  107         /* Post the MarshalledInvocation data. This is using the URL class
  108          for now but this should be improved to a cluster aware layer with
  109          full usage of HTTP 1.1 features, pooling, etc.
  110          */
  111         java.net.HttpURLConnection conn = (java.net.HttpURLConnection) externalURL.openConnection();
  112         //if( conn instanceof com.sun.net.ssl.HttpsURLConnection )
  113         //{
  114            // See if the org.jboss.security.ignoreHttpsHost property is set
  115            /*
  116            if( Boolean.getBoolean("org.jboss.security.ignoreHttpsHost") == true )
  117            {
  118               com.sun.net.ssl.HttpsURLConnection sconn = (com.sun.net.ssl.HttpsURLConnection) conn;
  119               AnyhostVerifier verifier = new AnyhostVerifier();
  120               sconn.setHostnameVerifier(verifier);
  121            }
  122             **/
  123         //}
  124         conn.setDoInput(true);
  125         conn.setDoOutput(true);
  126         conn.setRequestProperty("ContentType", REQUEST_CONTENT_TYPE);
  127         conn.setRequestMethod("POST");
  128         java.io.OutputStream os = conn.getOutputStream();
  129         java.io.ObjectOutputStream oos = new java.io.ObjectOutputStream(os);
  130         oos.writeObject(mi);
  131         oos.flush();
  132   
  133         // Get the response MarshalledValue object
  134         java.io.InputStream is = conn.getInputStream();
  135         java.io.ObjectInputStream ois = new java.io.ObjectInputStream(is);
  136         org.jboss.invocation.MarshalledValue mv = (org.jboss.invocation.MarshalledValue) ois.readObject();
  137         ois.close();
  138         oos.close();
  139   
  140         // If the encoded value is an exception throw it
  141         Object value = mv.get();
  142   
  143         if( value instanceof org.jboss.invocation.InvocationException )
  144            throw (Exception) (((org.jboss.invocation.InvocationException)value).getTargetException ());
  145   
  146         if( value instanceof Exception )
  147            throw (Exception) value;
  148   
  149         return value;
  150      }
  151   }

Save This Page
Home » jboss-5.0.0.CR1-src » org.jboss.console » remote » [javadoc | source]