Package org.jboss.remoting

Examples of org.jboss.remoting.InvocationRequest


         else
            obj = unmarshaller.read(new ByteArrayInputStream(requestByte), metadata);
         inputStream.close();

         boolean isError = false;
         InvocationRequest invocationRequest = null;

         if(obj instanceof InvocationRequest)
         {
            invocationRequest = (InvocationRequest) obj;
           
            Map requestMap = invocationRequest.getRequestPayload();
            if (requestMap == null)
            {
               invocationRequest.setRequestPayload(metadata);
            }
            else
            {
               requestMap.putAll(metadata);
            }
         }
         else
         {
            if(WebUtil.isBinary(requestContentType))
            {
               invocationRequest = getInvocationRequest(metadata, obj);
            }
            else
            {
               invocationRequest = createNewInvocationRequest(metadata, obj);
            }
         }

         String remoteAddressString = request.getRemoteAddr();
         InetAddress remoteAddress = InetAddress.getByName(remoteAddressString);
         Map requestPayload = invocationRequest.getRequestPayload();
        
         if (requestPayload == null)
         {
            requestPayload = new HashMap();
            invocationRequest.setRequestPayload(requestPayload);
         }
        
         requestPayload.put(Remoting.CLIENT_ADDRESS, remoteAddress);
        
        
         try
         {
            // call transport on the subclass, get the result to handback
            responseObject = invoke(invocationRequest);
         }
         catch(Throwable ex)
         {
            log.debug("Error thrown calling invoke on server invoker.", ex);
           
            if (checkForNoExceptionReturn(metadata))
            {
               log.trace("Returning error message instead of Exception");
               response.sendError(500, "Error occurred processing invocation request. ");
               return retval;
            }
            else
            {
               responseObject = ex;
               isError = true;
            }
         }

         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


      }

      if (payload instanceof InvocationRequest)
      {
         InvocationRequest ir = (InvocationRequest) payload;
         Map metadata = ir.getRequestPayload();
         if (metadata == null)
         {
            metadata = new HashMap();
            ir.setRequestPayload(metadata);
         }
         try
         {
            String clientHost = RemoteServer.getClientHost();
            metadata.put(Remoting.CLIENT_ADDRESS, InetAddress.getByName(clientHost));
View Full Code Here

      {
         try
         {
            home = (Home) it.next();
            locator = new InvokerLocator(protocol, home.host, home.port, path, params);
            invoke(new InvocationRequest(null, null, ServerInvoker.ECHO, null, null, null));
            if (log.isTraceEnabled()) log.trace(this + " able to contact server at: " + home);
            return home;
         }
         catch (Throwable e)
         {
View Full Code Here

      Object obj = versionedRead(inputStream, invoker, classLoader, version);

      // setting timestamp since about to start processing
      lastRequestHandledTimestamp = System.currentTimeMillis();

      InvocationRequest req = null;
      boolean createdInvocationRequest = false;
      boolean isError = false;

      if(obj instanceof InvocationRequest)
      {
         req = (InvocationRequest)obj;
      }
      else
      {
         req = createInvocationRequest(obj, socketWrapper);
         createdInvocationRequest = true;
         performVersioning = false;
      }

      boolean isServerSideOnewayRequest = isServerSideOneway(req);
      InetAddress clientAddress = socketWrapper.getSocket().getInetAddress();
      Object resp = null;

      try
      {
         // Make absolutely sure thread interrupted is cleared.
         Thread.interrupted();

         if(trace) { log.trace("about to call " + invoker + ".invoke()"); }

         if (req.getRequestPayload() == null)
            req.setRequestPayload(new HashMap());

         req.getRequestPayload().put(Remoting.CLIENT_ADDRESS, clientAddress);

         // 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(isServerSideOnewayRequest)
      {
         if(trace) { log.trace("oneway request, writing no reply on the wire"); }
      }
      else if (isOneway(req))
      {
         if (useOnewayConnectionTimeout && performVersioning)
         {
            writeVersion(outputStream, version);
            outputStream.flush();
         }
      }
      else
      {
         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

      else
      {
         // need to wrap request with invocation request
         SocketAddress remoteAddress = socketWrapper.getSocket().getRemoteSocketAddress();

         return new InvocationRequest(remoteAddress.toString(),
                                      invoker.getSupportedSubsystems()[0],
                                      obj, new HashMap(), null, null);
      }
   }
View Full Code Here

   throws IOException, ConnectionFailedException, ClassNotFoundException
   {
      String listenerId = null;
      if (invocation instanceof InvocationRequest)
      {
         InvocationRequest ir = (InvocationRequest) invocation;
         Object o = ir.getParameter();
         if (o instanceof InternalInvocation)
         {
            InternalInvocation ii = (InternalInvocation) o;
            if (InternalInvocation.ADDLISTENER.equals(ii.getMethodName())
                && ir.getLocator() != null) // getLocator() == null for pull callbacks
            {
               Map requestPayload = ir.getRequestPayload();
               listenerId = (String) requestPayload.get(Client.LISTENER_ID_KEY);
               listenerIdToClientInvokerMap.put(listenerId, this);
               BisocketServerInvoker callbackServerInvoker;
               callbackServerInvoker = BisocketServerInvoker.getBisocketServerInvoker(listenerId);
               callbackServerInvoker.createControlConnection(listenerId, true);
View Full Code Here


   InvokerLocator getSecondaryLocator() throws Throwable
   {
      InternalInvocation ii = new InternalInvocation(Bisocket.GET_SECONDARY_INVOKER_LOCATOR, null);
      InvocationRequest r = new InvocationRequest(null, null, ii, null, null, null);
      log.debug("getting secondary locator");
      Exception savedException = null;
     
      for (int i = 0; i < maxRetries; i++)
      {
View Full Code Here

            obj = ((VersionedUnMarshaller)unmarshaller).read(inputStream, metadata, getVersion());
         else
            obj = unmarshaller.read(inputStream, metadata);
         inputStream.close();

         InvocationRequest invocationRequest = null;

         if(obj instanceof InvocationRequest)
         {
            invocationRequest = (InvocationRequest) obj;
         }
         else
         {
            if(WebUtil.isBinary(requestContentType))
            {
               invocationRequest = getInvocationRequest(metadata, obj);
            }
            else
            {
               invocationRequest = createNewInvocationRequest(metadata, obj);
            }
         }
        
         String remoteAddressString = request.getRemoteAddr();
         InetAddress remoteAddress = getAddressByName(remoteAddressString);
         Map requestPayload = invocationRequest.getRequestPayload();
        
         if (requestPayload == null)
         {
            requestPayload = new HashMap();
            invocationRequest.setRequestPayload(requestPayload);
         }
        
         requestPayload.put(Remoting.CLIENT_ADDRESS, remoteAddress);

         try
View Full Code Here

      String requestContentType = request.getContentType();


      try
      {
         InvocationRequest invocationRequest = null;
         Object responseObject = null;
         boolean isError = false;

         String method = request.getMethod();
         if (method.equals("GET") || method.equals("HEAD") || (method.equals("OPTIONS") && request.getContentLength() <= 0))
         {
            invocationRequest = createNewInvocationRequest(metadata, null);
         }
         else
         {
            ServletInputStream inputStream = request.getInputStream();
            UnMarshaller unmarshaller = getUnMarshaller();
            Object obj = null;
            if (unmarshaller instanceof VersionedUnMarshaller)
               obj = ((VersionedUnMarshaller)unmarshaller).read(new ByteArrayInputStream(requestByte), metadata, getVersion());
            else
               obj = unmarshaller.read(new ByteArrayInputStream(requestByte), metadata);
            inputStream.close();

            if(obj instanceof InvocationRequest)
            {
               invocationRequest = (InvocationRequest) obj;

               Map requestMap = invocationRequest.getRequestPayload();
               if (requestMap == null)
               {
                  invocationRequest.setRequestPayload(metadata);
               }
               else
               {
                  requestMap.putAll(metadata);
               }
            }
            else
            {
               if(WebUtil.isBinary(requestContentType))
               {
                  invocationRequest = getInvocationRequest(metadata, obj);
               }
               else
               {
                  invocationRequest = createNewInvocationRequest(metadata, obj);
               }
            }
         }

         String remoteAddressString = request.getRemoteAddr();
         InetAddress remoteAddress = getAddressByName(remoteAddressString);
         Map requestPayload = invocationRequest.getRequestPayload();
        
         if (requestPayload == null)
         {
            requestPayload = new HashMap();
            invocationRequest.setRequestPayload(requestPayload);
         }
        
         requestPayload.put(Remoting.CLIENT_ADDRESS, remoteAddress);
        
        
         try
         {
            // call transport on the subclass, get the result to handback
            responseObject = invoke(invocationRequest);
         }
         catch(Throwable ex)
         {
            log.debug("Error thrown calling invoke on server invoker.", ex);
           
            if (checkForNoExceptionReturn(metadata))
            {
               log.trace("Returning error message instead of Exception");
               response.sendError(500, "Error occurred processing invocation request. ");
               return retval;
            }
            else
            {
               responseObject = ex;
               isError = true;
            }
         }

         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

      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();
View Full Code Here

TOP

Related Classes of org.jboss.remoting.InvocationRequest

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.