mx4j/src/tools/mx4j/tools/remote/caucho/hessian HessianCauchoInput.java,NONE,1.1 HessianCauchoOutput.java,NONE,1.1 HessianClientInvoker.java,NONE,1.1 HessianConnector.java,NONE,1.1 HessianConnectorServer.java,NONE,1.1 HessianServlet.java,NONE,1.1

Simone Bordet <[email protected]>
Newsgroups gmane.comp.java.mx4j.cvs
Message-ID <[email protected]>
Update of /cvsroot/mx4j/mx4j/src/tools/mx4j/tools/remote/caucho/hessian
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24799/src/tools/mx4j/tools/remote/caucho/hessian

Added Files:
	HessianCauchoInput.java HessianCauchoOutput.java 
	HessianClientInvoker.java HessianConnector.java 
	HessianConnectorServer.java HessianServlet.java 
Log Message:
Implementation of the JSR 160 JMXConnector and JMXConnectorServer over Caucho's Hessian and Burlap protocols

--- NEW FILE: HessianClientInvoker.java ---
/*
 * Copyright (C) MX4J.
 * All rights reserved.
 *
 * This software is distributed under the terms of the MX4J License version 1.0.
 * See the terms of the MX4J License in the documentation provided with this software.
 */

package mx4j.tools.remote.caucho.hessian;

import java.io.InputStream;
import java.io.OutputStream;

import mx4j.tools.remote.caucho.CauchoClientInvoker;
import mx4j.tools.remote.caucho.CauchoInput;
import mx4j.tools.remote.caucho.CauchoOutput;

/**
 * @author <a href="mailto:[email protected]">Simone Bordet</a>
 * @version $
 */
public class HessianClientInvoker extends CauchoClientInvoker
{
   public HessianClientInvoker(String endpoint)
   {
      super(endpoint);
   }

   protected CauchoInput createCauchoInput(InputStream stream)
   {
      return new HessianCauchoInput(stream);
   }

   protected CauchoOutput createCauchoOutput(OutputStream stream)
   {
      return new HessianCauchoOutput(stream);
   }
}

--- NEW FILE: HessianConnectorServer.java ---
/*
 * Copyright (C) MX4J.
 * All rights reserved.
 *
 * This software is distributed under the terms of the MX4J License version 1.0.
 * See the terms of the MX4J License in the documentation provided with this software.
 */

package mx4j.tools.remote.caucho.hessian;

import java.util.Map;
import javax.management.MBeanServer;
import javax.management.remote.JMXServiceURL;

import mx4j.tools.remote.AbstractJMXConnectorServer;
import mx4j.tools.remote.ConnectionManager;
import mx4j.tools.remote.http.HTTPConnectionManager;
import mx4j.tools.remote.http.HTTPConnectorServer;

/**
 * @author <a href="mailto:[email protected]">Simone Bordet</a>
 * @version $Revision: 1.1 $
 */
public class HessianConnectorServer extends HTTPConnectorServer
{
   public HessianConnectorServer(JMXServiceURL url, Map environment, MBeanServer server)
   {
      super(url, environment, server);
   }

   protected ConnectionManager createConnectionManager(AbstractJMXConnectorServer server, Map environment)
   {
      return new HTTPConnectionManager(server, "hessian", environment);
   }
}

--- NEW FILE: HessianCauchoOutput.java ---
/*
 * Copyright (C) MX4J.
 * All rights reserved.
 *
 * This software is distributed under the terms of the MX4J License version 1.0.
 * See the terms of the MX4J License in the documentation provided with this software.
 */

package mx4j.tools.remote.caucho.hessian;

import java.io.IOException;
import java.io.OutputStream;

import com.caucho.hessian.io.HessianOutput;
import mx4j.tools.remote.caucho.CauchoOutput;
import mx4j.tools.remote.caucho.serialization.JMXSerializerFactory;

/**
 * @author <a href="mailto:[email protected]">Simone Bordet</a>
 * @version $Revision: 1.1 $
 */
class HessianCauchoOutput implements CauchoOutput
{
   private final OutputStream stream;
   private final HessianOutput output;

   HessianCauchoOutput(OutputStream stream)
   {
      this.stream = stream;
      this.output = new HessianOutput();
      output.setSerializerFactory(new JMXSerializerFactory());
      output.init(stream);
   }

   public void startReply() throws IOException
   {
      output.startReply();
   }

   public void completeReply() throws IOException
   {
      output.completeReply();
   }

   /**
    * A bug in the Hessian protocol requires this hack: headers cannot be written using
    * HessianOutput, since the HessianOutput.startCall() already writes the method name,
    * while HessianInput expects the headers before the method name
    *
    * @see #writeMethod
    */
   public void startCall() throws IOException
   {
      stream.write(99);
      stream.write(0);
      stream.write(1);
   }

   public void completeCall() throws IOException
   {
      output.completeCall();
   }

   public void writeHeader(String header) throws IOException
   {
      output.writeHeader(header);
   }

   /**
    * Same hack as {@link #startCall}: this method is missing from HessianOutput
    */
   public void writeMethod(String methodName) throws IOException
   {
      stream.write(109);
      int len = methodName.length();
      stream.write(len >> 8);
      stream.write(len);
      output.printString(methodName, 0, len);
   }

   public void writeObject(Object object) throws IOException
   {
      output.writeObject(object);
   }

   public void writeFault(Throwable fault) throws IOException
   {
      output.writeFault(fault.getClass().getName(), fault.getMessage(), fault);
   }
}

--- NEW FILE: HessianServlet.java ---
/*
 * Copyright (C) MX4J.
 * All rights reserved.
 *
 * This software is distributed under the terms of the MX4J License version 1.0.
 * See the terms of the MX4J License in the documentation provided with this software.
 */

package mx4j.tools.remote.caucho.hessian;

import java.io.InputStream;
import java.io.OutputStream;
import javax.servlet.ServletException;

import mx4j.tools.remote.caucho.CauchoInput;
import mx4j.tools.remote.caucho.CauchoOutput;
import mx4j.tools.remote.caucho.CauchoService;
import mx4j.tools.remote.caucho.CauchoServlet;

/**
 * @author <a href="mailto:[email protected]">Simone Bordet</a>
 * @version $Revision: 1.1 $
 */
public class HessianServlet extends CauchoServlet
{
   private CauchoService service;

   public void init() throws ServletException
   {
      super.init();
      service = new CauchoService("hessian");
   }

   public void destroy()
   {
      this.service = null;
   }

   protected Object getService()
   {
      return service;
   }

   protected CauchoInput createCauchoInput(InputStream stream)
   {
      return new HessianCauchoInput(stream);
   }

   protected CauchoOutput createCauchoOutput(OutputStream stream)
   {
      return new HessianCauchoOutput(stream);
   }
}

--- NEW FILE: HessianConnector.java ---
/*
 * Copyright (C) MX4J.
 * All rights reserved.
 *
 * This software is distributed under the terms of the MX4J License version 1.0.
 * See the terms of the MX4J License in the documentation provided with this software.
 */

package mx4j.tools.remote.caucho.hessian;

import java.io.IOException;
import java.util.Map;
import javax.management.MBeanServerConnection;
import javax.management.remote.JMXServiceURL;
import javax.security.auth.Subject;

import mx4j.tools.remote.http.HTTPConnectionMBeanServerConnection;
import mx4j.tools.remote.http.HTTPConnector;

/**
 * @author <a href="mailto:[email protected]">Simone Bordet</a>
 * @version $Revision: 1.1 $
 */
public class HessianConnector extends HTTPConnector
{
   public HessianConnector(JMXServiceURL address, Map environment) throws IOException
   {
      super(address);
   }

   protected MBeanServerConnection doGetMBeanServerConnection(Subject delegate) throws IOException
   {
      return new HTTPConnectionMBeanServerConnection(getHTTPConnection(), delegate, getRemoteNotificationClientHandler());
   }
}

--- NEW FILE: HessianCauchoInput.java ---
/*
 * Copyright (C) MX4J.
 * All rights reserved.
 *
 * This software is distributed under the terms of the MX4J License version 1.0.
 * See the terms of the MX4J License in the documentation provided with this software.
 */

package mx4j.tools.remote.caucho.hessian;

import java.io.IOException;
import java.io.InputStream;

import com.caucho.hessian.io.HessianInput;
import mx4j.tools.remote.caucho.CauchoInput;
import mx4j.tools.remote.caucho.serialization.JMXSerializerFactory;

/**
 * @author <a href="mailto:[email protected]">Simone Bordet</a>
 * @version $Revision: 1.1 $
 */
class HessianCauchoInput implements CauchoInput
{
   private final HessianInput input;

   HessianCauchoInput(InputStream stream)
   {
      this.input = new HessianInput();
      input.setSerializerFactory(new JMXSerializerFactory());
      input.init(stream);
   }

   public void startCall() throws IOException
   {
      input.readCall();
   }

   public void completeCall() throws IOException
   {
      input.completeCall();
   }

   public void startReply() throws Exception
   {
      try
      {
         input.startReply();
      }
      catch (Throwable x)
      {
         if (x instanceof Exception) throw (Exception)x;
         throw (Error)x;
      }
   }

   public void completeReply() throws IOException
   {
      input.completeReply();
   }

   public String readHeader() throws IOException
   {
      return input.readHeader();
   }

   public String readMethod() throws IOException
   {
      return input.readMethod();
   }

   public Object readObject(Class cls) throws IOException
   {
      return cls == null ? input.readObject() : input.readObject(cls);
   }
}



-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media
100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33
Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.