Package nexj.core.rpc

Examples of nexj.core.rpc.RPCException


               sPrevPassword = sPassword;
               prevTrust = trust;
            }
            catch (Throwable t)
            {
               throw new RPCException("err.rpc.tcp", t);
            }
         }
      }
      finally
      {
View Full Code Here


    */
   public void send(final Collection col)
   {
      if (!m_channel.isSendable())
      {
         throw new RPCException("err.rpc.notSender", new Object[]{m_channel.getName()});
      }

      if (s_logger.isDebugEnabled())
      {
         s_logger.debug("Sending " + col.size() + " message(s) on channel \"" +
            m_channel.getName() + "\" to destination \"" + m_sDestination + "\"");

         if (s_logger.isDumpEnabled())
         {
            int nCount = 0;

            for (Iterator itr = col.iterator(); itr.hasNext();)
            {
               s_logger.dump("Message [" + nCount++ + "]: " + ((TransferObject)itr.next()));
            }
         }
      }

      if (m_bEnabled)
      {
         boolean bRetry = true;
         ConnectionFactory factory;
         Destination destination;

         synchronized (this)
         {
            if (m_destination == null)
            {
               try
               {
                  bind();
               }
               catch (Exception t)
               {
                  s_logger.error("Failed to bind to " + m_sTypeName + " \"" +
                     m_sDestination + "\" (CF=\"" + m_sConnectionFactory + "\")", t);

                  throw new RPCException("err.rpc.jms", t);
               }
            }

            factory = m_connectionFactory;
            destination = m_destination;
         }

      retry:
         do
         {
            try
            {
               Connection connection = null;
               Session session = null;
               MessageProducer producer = null;

               try
               {
                  if (m_sUser == null)
                  {
                     connection = factory.createConnection();
                  }
                  else
                  {
                     connection = factory.createConnection(m_sUser, m_sPassword);
                  }

                  session = m_jmsStrategy.createSession(connection);
                  producer = session.createProducer(destination);
                  bRetry = false;

                  for (Iterator itr = col.iterator(); itr.hasNext();)
                  {
                     TransferObject tobj = (TransferObject)itr.next();
                     Boolean persistent = (Boolean)tobj.findValue(PERSISTENT);
                     int nPersistenceMode =
                        ((persistent == null) ? m_channel.isPersistent() : persistent.booleanValue()) ?
                        DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT;
                     Number priority = (Number)tobj.findValue(PRIORITY);
                     int nPriority = (priority == null) ? m_channel.getPriority() : priority.intValue();
                     Number ttl = (Number)tobj.findValue(TTL);
                     long lTTL = (ttl == null) ? m_channel.getTimeToLive() : ttl.longValue();

                     m_sentCounter.add(1);
                     producer.send(createMessage(session, tobj), nPersistenceMode, nPriority, lTTL);
                  }
               }
               finally
               {
                  if (producer != null)
                  {
                     try
                     {
                        producer.close();
                     }
                     catch (Exception e)
                     {
                        s_logger.error("Error closing the producer for destination \"" + m_sDestination + "\"", e);
                     }
                  }

                  if (session != null)
                  {
                     try
                     {
                        m_jmsStrategy.closeSession(session);
                     }
                     catch (Exception e)
                     {
                        s_logger.error("Error closing the session for connection factory \"" +
                           m_sConnectionFactory + "\"", e);
                     }
                  }

                  if (connection != null)
                  {
                     try
                     {
                        connection.close();
                     }
                     catch (Exception e)
                     {
                        s_logger.error("Error closing the connection for connection factory \"" +
                           m_sConnectionFactory + "\"", e);
                     }
                  }
               }
            }
            catch (Exception e)
            {
               if (bRetry)
               {
                  bRetry = false;
                 
                  for (Throwable x = e.getCause(); x != null; x = x.getCause())
                  {
                     if (x instanceof ResourceException || x instanceof IOException)
                     {
                        // The connection factory is stale, get a new one
  
                        if (s_logger.isInfoEnabled())
                        {
                           s_logger.info("Rebinding the stale " + m_sTypeName + " \"" +
                              m_sDestination + "\" (CF=\"" + m_sConnectionFactory + "\")");
                        }

                        try
                        {
                           synchronized (this)
                           {
                              if (m_connectionFactory == factory &&
                                 m_destination == destination)
                              {
                                 bind();
                              }

                              factory = m_connectionFactory;
                              destination = m_destination;
                           }
                        }
                        catch (Exception mx)
                        {
                           s_logger.error("Failed to bind to " + m_sTypeName + " \"" +
                              m_sDestination + "\" (CF=\"" + m_sConnectionFactory + "\")", mx);

                           throw new RPCException("err.rpc.jms", e);
                        }

                        continue retry;
                     }
                  }
               }

               throw new RPCException("err.rpc.jms", e);
            }
         }
         while (bRetry);
      }
      else
View Full Code Here

            {
               correlationId = ((Binary)correlationId).toString();
            }
            else
            {
               throw new RPCException("err.rpc.jms.correlationIdType");
            }
         }

         message.setJMSCorrelationID((String)correlationId);
      }
View Full Code Here

    */
   protected Destination getDestination(Channel channel) throws RPCException
   {
      if (!(channel instanceof MessageQueue))
      {
         throw new RPCException("err.rpc.jms.channel", new Object[]{channel.getName()});
      }
     
      return getDestination((MessageQueue)channel);
   }
View Full Code Here

            // end-of-file?
            if (nNewByteCount == -1)
            {
               if (bFoundSB)
               {
                  throw new RPCException("err.rpc.tcp.mllp.unexpectedEOF");
               }
               else
               {
                  return false;
               }
            }

            m_nLastIndex = nPos + nNewByteCount;
         }

         if (!bFoundSB)
         {
            for (; nPos < m_nLastIndex; ++nPos)
            {
               // read and discard until
               // we find the start byte
               n = m_nBuffer[nPos];

               // start byte?
               if (n == m_factory.getStartBlock())
               {
                  bFoundSB = true;

                  break;
               }
            }

            // resize buffer if necessary
            nPos = checkAndResizeBuffer(nPos, bFoundSB);

            if (!bFoundSB)
            {
               continue;
            }

            m_nBufStartPos = ++nPos;
         }

         // read until we get an end byte followed by message separator
         for (; nPos < m_nLastIndex; ++nPos)
         {
            n = m_nBuffer[nPos];

            // start byte?
            if (n == m_factory.getStartBlock())
            {
               // ignore all currently buffered bytes
               m_nBufStartPos = nPos + 1;

               continue;
            }

            // message separator?
            if (bFoundEB)
            {
               if (n == m_factory.getMessageSeparator())
               {
                  // We've read (and buffered) a complete message
                  m_nBufEndPos = nPos - 2;
                  m_nBufReadPos = m_nBufStartPos;

                  return true;
               }

               throw new RPCException("err.rpc.tcp.mllp.noCRAfterEB",
                  new Object[] { new Integer(m_factory.getMessageSeparator()), new Integer(n) });
            }

            // end byte?
            if (n == m_factory.getEndBlock())
            {
               bFoundEB = true;

               continue;
            }

            // invalid byte?
            if (!m_factory.isValidByte(n))
            {
               throw new RPCException("err.rpc.tcp.mllp.invalidByte",
                  new Object[] { new Integer(n), new Integer(m_factory.getMinByte()) });
            }

            // resize buffer if necessary
            nPos = checkAndResizeBuffer(nPos, bFoundSB);
View Full Code Here

            if (nNewSize <= m_nBuffer.length)
            {
               // We can't continue, since we've reached the
               // maximum buffer size (according to the settings).
               throw new RPCException("err.rpc.tcp.mllp.noBufferSpace");
            }

            byte[] newBuffer = new byte[nNewSize];
            System.arraycopy(m_nBuffer, 0, newBuffer, 0, m_nBuffer.length);
            m_nBuffer = newBuffer;
View Full Code Here

    */
   public void send(TransferObject tobj) throws IntegrationException
   {
      if (!m_channel.isSendable())
      {
         throw new RPCException("err.rpc.notSender", new Object[]{m_channel.getName()});
      }

      if (s_logger.isDebugEnabled())
      {
         s_logger.debug("Sending a message on channel \"" + m_channel.getName() + "\"");
         s_logger.dump(tobj);
      }

      UDPConnection con = null;
     
      try
      {
         String sHost = (String)tobj.findValue(HOST, m_channel.getHost());
         Number port = (Number)tobj.findValue(PORT);
         int nPort = (port == null) ? m_channel.getPort() : port.intValue();
  
         if (sHost == null)
         {
            throw new RPCException("err.integration.udp.unspecifiedHost");
         }
  
         if (nPort < 0)
         {
            throw new RPCException("err.integration.udp.unspecifiedPort");
         }

         SocketAddress address = new InetSocketAddress(sHost, nPort);
         String sLocalHost = (String)tobj.findValue(LOCAL_HOST, m_channel.getLocalHost());
         Number localPort = (Number)tobj.findValue(LOCAL_PORT);
         int nLocalPort = (localPort == null) ? m_channel.getLocalPort() : localPort.intValue();
         SocketAddress bindAddress = null;

         if (sLocalHost != null || nLocalPort > 0)
         {
            if (sLocalHost == null)
            {
               bindAddress = new InetSocketAddress((InetAddress)null, nLocalPort);
            }
            else
            {
               bindAddress = new InetSocketAddress(sLocalHost, nLocalPort);
            }
         }

         Number ttl = (Number)tobj.findValue(TTL);
         int nTTL = (ttl == null) ? m_channel.getTTL() : ttl.intValue();

         Number tos = (Number)tobj.findValue(TOS);
         int nTOS = (tos == null) ? m_channel.getTOS() : tos.intValue();
        
         Object body = tobj.findValue(BODY);
         byte[] data;

         if (body == null)
         {
            data = new byte[0];
         }
         else if (body instanceof String)
         {
            data = ((String)body).getBytes((m_channel.getEncoding() == null) ?
               XMLUtil.ENCODING : m_channel.getEncoding());
         }
         else
         {
            data = ((Binary)body).getData();
         }

         con = m_factory.open(bindAddress);
         m_sentCounter.add(1);
         con.send(address, data, 0, data.length, nTOS, nTTL);
      }
      catch (IntegrationException e)
      {
         throw e;
      }
      catch (Exception e)
      {
         throw new RPCException("err.rpc.udp", e);
      }
      finally
      {
         if (con != null)
         {
View Full Code Here

    */
   public void write(int n) throws IOException
   {
      if (!m_factory.isValidByte(n))
      {
         throw new RPCException("err.rpc.tcp.mllp.invalidByte",
            new Object[] { new Integer(n), new Integer(m_factory.getMinByte()) });
      }

      m_ostream.write(n);
   }
View Full Code Here

         e = new LoginException("err.auth.login");
      }

      if (e == null || e.getCause() == null)
      {
         RPCException x = new HTTPException(nStatus, client.getResponseMessage());

         if (e == null)
         {
            e = x;
         }
View Full Code Here

      Metadata metadata = m_context.getMetadata();
      Channel channel = metadata.getChannel(sChannel);

      if (!(channel instanceof HTTPChannel) || !channel.isReceivable())
      {
         throw new RPCException("err.rpc.http.notReceiver", new Object[]{sChannel});
      }
     
      HTTPChannel http = (HTTPChannel)channel;

      if (http.isSecure() && !m_request.isSecure())
View Full Code Here

TOP

Related Classes of nexj.core.rpc.RPCException

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.