Package org.jboss.remoting

Examples of org.jboss.remoting.InvocationResponse


   public Object receiveObject(InputStream inputStream, ClassLoader customClassLoader) throws IOException, ClassNotFoundException
   {
      Object object = super.receiveObject(inputStream, customClassLoader);
      if(object instanceof InvocationResponse)
      {
         InvocationResponse ir = (InvocationResponse)object;
         Object obj = ir.getResult();
         if(obj instanceof SealedObject)
         {
            try
            {
               object = new InvocationResponse(ir.getSessionId(),
                     (EncryptionUtil.unsealObject((SealedObject)obj)),
                               ir.isException(), ir.getPayload());
            }
            catch (Exception e)
            {
               e.printStackTrace();
            }
View Full Code Here


           
            if (checkForExceptionReturn(metadata))
            {
               String sessionId = invocationRequest.getSessionId();
               ServletThrowable st = new ServletThrowable(ex);
               responseObject = new InvocationResponse(sessionId, st, true, null);
            }
            else
            {
               isError = true;
            }
         }

         //Start with response code of 204 (no content), then if is a return from handler, change to 200 (ok)
         int status = 200;
         if(responseObject != null)
         {
            if(isError)
            {
               status = 500;
            }
         }
         else
         {
            if (!isRemotingUserAgent || "HEAD".equals(request.getMethod()))
            {
               status = 204;
            }
         }

         // extract response code/message if exists
         Map responseMap = invocationRequest.getReturnPayload();
         if(responseMap != null)
         {
            Integer handlerStatus = (Integer) responseMap.remove(HTTPMetadataConstants.RESPONSE_CODE);
            if(handlerStatus != null)
            {
               status = handlerStatus.intValue();
            }

            // add any response map headers
            Set entries = responseMap.entrySet();
            Iterator itr = entries.iterator();
            while(itr.hasNext())
            {
               Map.Entry entry = (Map.Entry)itr.next();
               response.addHeader(entry.getKey().toString(), entry.getValue().toString());
            }
         }



         // can't set message anymore as is deprecated
         response.setStatus(status);
        
         if (isRemotingUserAgent && !(invocationRequest instanceof CreatedInvocationRequest))
         {
            responseObject = new InvocationResponse(invocationRequest.getSessionId(),
                                                    responseObject, isError, responseMap);
         }

         if(responseObject != null)
         {
View Full Code Here

         // handle socket-specific invocations
         if ("$GET_CLIENT_LOCAL_ADDRESS$".equals(req.getParameter()))
         {
            Socket s = socketWrapper.getSocket();
            InetAddress a = s.getInetAddress();
            resp = new InvocationResponse(req.getSessionId(), a, false, null);
         }
         else
         {
             // call transport on the subclass, get the result to handback
             resp = invoker.invoke(req);
         }

         if(trace) { log.trace(invoker + ".invoke() returned " + resp); }
      }
      catch (Throwable ex)
      {
         resp = ex;
         isError = true;
         if (trace) log.trace(invoker + ".invoke() call failed", ex);
      }

      Thread.interrupted(); // clear interrupted state so we don't fail on socket writes

      if(isOneway(req.getRequestPayload()))
      {
         if(trace) { log.trace("oneway request, writing no reply on the wire"); }
      }
      else
      {
         if(!createdInvocationRequest)
         {
            // need to return invocation response
            if(trace) { log.trace("creating response instance"); }
            resp = new InvocationResponse(req.getSessionId(), resp, isError, req.getReturnPayload());
         }

         OutputStream outputStream = socketWrapper.getOutputStream();
         if (performVersioning)
         {
View Full Code Here

            res.setMessage(message);

            if (isRemotingUserAgent && ((Boolean)receivedInvocationRequest.get()).booleanValue())
            {
               responseMap = ((ResponseMap) responseMap).getMap();
               responseObject = new InvocationResponse(invocationRequest.getSessionId(),
                                                       responseObject, isError, responseMap);
            }

            if(responseObject != null)
            {
View Full Code Here

      return result;
   }

   private Object checkForLeasePing(HttpURLConnection conn, Object invocation, Map metadata) throws IOException
   {
      InvocationResponse response = null;
      boolean shouldLease = false;
      long leasePeriod = -1;

      if(invocation != null && invocation instanceof InvocationRequest)
      {
         InvocationRequest request = (InvocationRequest)invocation;

         Object payload = request.getParameter();
         // although a bit of a hack, this will determin if first time ping called by client.
         if(payload != null && payload instanceof String && "$PING$".equalsIgnoreCase((String)payload) && request.getReturnPayload() != null)
         {
            try
            {
               // now know is a ping request, so convert to be a HEAD method call
               conn.setDoOutput(false);
               conn.setDoInput(true);
               conn.setRequestMethod("HEAD");
               // set the remoting version
               conn.setRequestProperty(HTTPMetadataConstants.REMOTING_VERSION_HEADER, new Integer(getVersion()).toString());
               // set the user agent
               conn.setRequestProperty(HTTPMetadataConstants.REMOTING_USER_AGENT, "JBossRemoting - " + Version.VERSION);
               conn.setRequestProperty(HTTPMetadataConstants.REMOTING_LEASE_QUERY, "true");
               conn.setRequestProperty("sessionId", request.getSessionId());
               connect(conn);

               //InputStream is = (conn.getResponseCode() < 400) ? conn.getInputStream() : conn.getErrorStream();
               Map headers = conn.getHeaderFields();

               if(headers != null)
               {
                  Object leasingEnabled = headers.get("LEASING_ENABLED");
                  if(leasingEnabled != null && leasingEnabled instanceof List)
                  {
                     shouldLease = new Boolean((String)((List)leasingEnabled).get(0)).booleanValue();
                  }
                  Object leasingPeriod = headers.get("LEASE_PERIOD");
                  if(leasingPeriod != null && leasingPeriod instanceof List)
                  {
                     leasePeriod = new Long((String)((List)leasingPeriod).get(0)).longValue();
                  }
               }
            }
            catch (IOException e)
            {
               log.error("Error checking server for lease information.", e);
            }

            Map p = new HashMap();
            p.put("clientLeasePeriod", new Long(leasePeriod));
            InvocationResponse innterResponse = new InvocationResponse(null, new Boolean(shouldLease), false, p);
            response = new InvocationResponse(null, innterResponse, false, null);

         }
      }

      return response;
View Full Code Here

                     WebServerError ex = new WebServerError((String)result);
                     return ex;
                  }
                  else if (result instanceof InvocationResponse)
                  {
                     InvocationResponse response = (InvocationResponse) result;
                     Object innerResult = response.getResult();
                     if (innerResult instanceof ServletThrowable)
                     {
                        return ((ServletThrowable) innerResult).getCause();
                     }
                     else
                     {
                        return innerResult;
                     }
                  }
                  else
                  {
                     return result;
                  }
               }
            }
         }


         // if got here, wasn't configured to not throw exception, so will throw it.

         // In this case, MicroRemoteClientInvoker will throw the exception carried by
         // the InvocationResponse.
         if (result instanceof InvocationResponse)
         {
            if ((((InvocationResponse) result).getResult()) instanceof ServletThrowable)
            {
               InvocationResponse response = (InvocationResponse) result;
               ServletThrowable st = (ServletThrowable) response.getResult();
               Throwable t = st.getCause();
               InvocationResponse ir = new InvocationResponse(response.getSessionId(),
                                                              t,
                                                              response.isException(),
                                                              response.getPayload());
               return ir;
            }
View Full Code Here

      return result;
   }

   private Object checkForLeasePing(HttpURLConnection conn, Object invocation, Map metadata) throws IOException
   {
      InvocationResponse response = null;
      boolean shouldLease = false;
      long leasePeriod = -1;

      if(invocation != null && invocation instanceof InvocationRequest)
      {
         InvocationRequest request = (InvocationRequest)invocation;

         Object payload = request.getParameter();
         // although a bit of a hack, this will determin if first time ping called by client.
         if(payload != null && payload instanceof String && "$PING$".equalsIgnoreCase((String)payload) && request.getReturnPayload() != null)
         {
            try
            {
               // now know is a ping request, so convert to be a HEAD method call
               conn.setDoOutput(false);
               conn.setDoInput(true);
               conn.setRequestMethod("HEAD");
               // set the remoting version
               conn.setRequestProperty(HTTPMetadataConstants.REMOTING_VERSION_HEADER, new Integer(Version.getDefaultVersion()).toString());
               // set the user agent
               conn.setRequestProperty(HTTPMetadataConstants.REMOTING_USER_AGENT, "JBossRemoting - " + Version.VERSION);
               conn.setRequestProperty(HTTPMetadataConstants.REMOTING_LEASE_QUERY, "true");
               conn.setRequestProperty("sessionId", request.getSessionId());
               conn.connect();

               //InputStream is = (conn.getResponseCode() < 400) ? conn.getInputStream() : conn.getErrorStream();
               Map headers = conn.getHeaderFields();

               if(headers != null)
               {
                  Object leasingEnabled = headers.get("LEASING_ENABLED");
                  if(leasingEnabled != null && leasingEnabled instanceof List)
                  {
                     shouldLease = new Boolean((String)((List)leasingEnabled).get(0)).booleanValue();
                  }
                  Object leasingPeriod = headers.get("LEASE_PERIOD");
                  if(leasingPeriod != null && leasingPeriod instanceof List)
                  {
                     leasePeriod = new Long((String)((List)leasingPeriod).get(0)).longValue();
                  }
               }
            }
            catch (IOException e)
            {
               log.error("Error checking server for lease information.", e);
            }

            Map p = new HashMap();
            p.put("clientLeasePeriod", new Long(leasePeriod));
            InvocationResponse innterResponse = new InvocationResponse(null, new Boolean(shouldLease), false, p);
            response = new InvocationResponse(null, innterResponse, false, null);

         }
      }

      return response;
View Full Code Here

      {
         if(!createdInvocationRequest)
         {
            // need to return invocation response
            if(trace) { log.trace("creating response instance"); }
            resp = new InvocationResponse(req.getSessionId(), resp, isError, req.getReturnPayload());
         }

         if (performVersioning)
         {
            writeVersion(outputStream, version);
View Full Code Here

      return result;
   }

   private Object checkForLeasePing(HttpURLConnection conn, Object invocation, Map metadata) throws IOException
   {
      InvocationResponse response = null;
      boolean shouldLease = false;
      long leasePeriod = -1;

      if(invocation != null && invocation instanceof InvocationRequest)
      {
         InvocationRequest request = (InvocationRequest)invocation;

         Object payload = request.getParameter();
         // although a bit of a hack, this will determin if first time ping called by client.
         if(payload != null && payload instanceof String && "$PING$".equalsIgnoreCase((String)payload) && request.getReturnPayload() != null)
         {
            try
            {
               // now know is a ping request, so convert to be a HEAD method call
               conn.setDoOutput(false);
               conn.setDoInput(true);
               conn.setRequestMethod("HEAD");
               // set the remoting version
               conn.setRequestProperty(HTTPMetadataConstants.REMOTING_VERSION_HEADER, new Integer(getVersion()).toString());
               // set the user agent
               conn.setRequestProperty(HTTPMetadataConstants.REMOTING_USER_AGENT, "JBossRemoting - " + Version.VERSION);
               conn.setRequestProperty(HTTPMetadataConstants.REMOTING_LEASE_QUERY, "true");
               conn.setRequestProperty("sessionId", request.getSessionId());
               connect(conn);

               //InputStream is = (conn.getResponseCode() < 400) ? conn.getInputStream() : conn.getErrorStream();
               Map headers = conn.getHeaderFields();

               if(headers != null)
               {
                  Object leasingEnabled = headers.get("LEASING_ENABLED");
                  if(leasingEnabled != null && leasingEnabled instanceof List)
                  {
                     shouldLease = new Boolean((String)((List)leasingEnabled).get(0)).booleanValue();
                  }
                  Object leasingPeriod = headers.get("LEASE_PERIOD");
                  if(leasingPeriod != null && leasingPeriod instanceof List)
                  {
                     leasePeriod = new Long((String)((List)leasingPeriod).get(0)).longValue();
                  }
               }
            }
            catch (IOException e)
            {
               log.error("Error checking server for lease information.", e);
            }

            Map p = new HashMap();
            p.put("clientLeasePeriod", new Long(leasePeriod));
            InvocationResponse innterResponse = new InvocationResponse(null, new Boolean(shouldLease), false, p);
            response = new InvocationResponse(null, innterResponse, false, null);

         }
      }

      return response;
View Full Code Here

         // can't set message anymore as is deprecated
         response.setStatus(status);
        
         if (isRemotingUserAgent && !(invocationRequest instanceof CreatedInvocationRequest))
         {
            responseObject = new InvocationResponse(invocationRequest.getSessionId(),
                                                    responseObject, isError, responseMap);
         }

         if(responseObject != null)
         {
View Full Code Here

TOP

Related Classes of org.jboss.remoting.InvocationResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.