Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2005, JBoss Inc., and individual contributors as indicated
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as
  * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
 
 package org.jboss.remoting.transport.web;
 
 import java.util.Map;

Author(s):
Tom Elrod
 
 public abstract class WebServerInvoker extends ServerInvoker
 {
    // header constants
    public static String HEADER_SESSION_ID = "sessionId";
    public static String HEADER_SUBSYSTEM = "subsystem";
 
 
    public WebServerInvoker(InvokerLocator locator)
    {
       super(locator);
    }
 
    public WebServerInvoker(InvokerLocator locatorMap configuration)
    {
       super(locatorconfiguration);
    }

   
returns true if the transport is bi-directional in nature, for example, HTTP in unidirectional and SOCKETs are bi-directional (unless behind a firewall for example).

Returns:
false (HTTP is unidirrectional)
 
    public boolean isTransportBiDirectional()
    {
       return false;
    }
 
    protected String getDefaultDataType()
    {
       return .;
    }
 
    protected InvocationRequest getInvocationRequest(Map metadataObject obj)
    {
       InvocationRequest request = null;
 
       if(obj instanceof InvocationRequest)
       {
          request = (InvocationRequestobj;
          if(request.getRequestPayload() == null)
          {
             request.setRequestPayload(metadata);
          }
          else
          {
             request.getRequestPayload().putAll(metadata);
          }
       }
       else
       {
          request = createNewInvocationRequest(metadataobj);
       }
       return request;
    }
 
   {
      Map map =  ?  : null;
      UnMarshaller unmarshaller = MarshalFactory.getUnMarshaller(getLocator(), this.getClass().getClassLoader(), map);
      if(unmarshaller == null)
      {
         unmarshaller = MarshalFactory.getUnMarshaller(getDataType(), getSerializationType());
      }
      return unmarshaller;
   }
   public Marshaller getMarshaller()
   {
      Map map =  ?  : null;
      Marshaller marshaller = MarshalFactory.getMarshaller(getLocator(), this.getClass().getClassLoader(), map);
      if(marshaller == null)
      {
         marshaller = MarshalFactory.getMarshaller(getDataType(), getSerializationType());
      }
      return marshaller;
   }
   protected InvocationRequest createNewInvocationRequest(Map metadataObject payload)
   {
      // will try to use the same session id if possible to track
      String sessionId = getSessionId(metadata);
      String subSystem = (Stringmetadata.get();
      InvocationRequest request = null;
      Map responseMap = new HashMap();
      boolean isLeasQuery = checkForLeaseQuery(metadata);
      if(isLeasQuery)
      {
         addLeaseInfo(responseMap);
         request = new CreatedInvocationRequest(sessionIdsubSystem"$PING$"nullresponseMapnull);
      }
      else
      {
         request = new CreatedInvocationRequest(sessionIdsubSystempayloadmetadatanullnull);
      }
      request.setReturnPayload(responseMap);
      return request;
   }
   private boolean checkForLeaseQuery(Map headers)
   {
      boolean isLeaseQuery = false;
         if(headers != null)
         {
            Object val = headers.get(.);
            if(val != null && val instanceof String)
            {
               isLeaseQuery = Boolean.valueOf((String)val).booleanValue();
            }
            else
            {
               val = headers.get(.);
               if(val != null && val instanceof String)
               {
                  isLeaseQuery = Boolean.valueOf((String)val).booleanValue();
               }
            }
         }
      return isLeaseQuery;
   }
   private void addLeaseInfo(Map response)
   {
      boolean leaseManagement = isLeaseActivated();
      response.put("LEASING_ENABLED"new Boolean(leaseManagement));
      if(leaseManagement)
      {
         long leasePeriod = getLeasePeriod();
         response.put("LEASE_PERIOD"new Long(leasePeriod));
      }
   }
   protected String getSessionId(Map metadata)
   {
      String sessionId = (Stringmetadata.get();
      if(sessionId == null || sessionId.length() == 0)
      {
         String userAgent = (Stringmetadata.get("User-Agent");
         String host = (Stringmetadata.get("Host");
         String idSeed = userAgent + ":" + host;
         sessionId = Integer.toString(idSeed.hashCode());
      }
      return sessionId;
   }

   
Will write out the object to byte array and check size of byte array. This is VERY expensive, but need for the content length.

Parameters:
response
Returns:
   protected int getContentLength(Object responsethrows IOException
   {
      if(response != null)
      {
         
Am checking to see if type String because: 1. faster to just get the length compared to doing serialization 2. doing serialization adds extra bytes, so the value calculated is larger than the actual number of characters (and causes the client to wait for the extra characters that it will never get).
         if(response instanceof String)
         {
            return ((Stringresponse).length();
         }
         else
         {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(bos);
            oos.writeObject(response);
            oos.flush();
            bos.flush();
            byte buffer[] = bos.toByteArray();
            return buffer.length;
         }
      }
      else
      {
         return 0;
      }
   }
   static protected class CreatedInvocationRequest extends InvocationRequest
   {
      public CreatedInvocationRequest(String sessionIdString subsystemObject argMap requestPayloadMap returnPayloadInvokerLocator locator)
      {
         super(sessionIdsubsystemargrequestPayloadreturnPayloadlocator);
      }
   }
New to GrepCode? Check out our FAQ X