Package javax.resource

Examples of javax.resource.ResourceException


    public String getEISProductVersion() throws ResourceException {
        try {
            Connection con = mc.getJdbcConnection();
            return con.getMetaData().getDatabaseProductVersion();
        } catch (SQLException ex) {
            ResourceException re = new EISSystemException(ex.getMessage());
            re.setLinkedException(ex);
            throw re;
        }
    }
View Full Code Here


      throw new IllegalStateException("Non started resource adapter.");
    if (stopped)
      throw new IllegalStateException("Stopped resource adapter.");

    if (! (spec instanceof ActivationSpecImpl))
      throw new ResourceException("Provided ActivationSpec instance is not a JORAM activation spec.");
    ActivationSpecImpl specImpl = (ActivationSpecImpl) spec;

    if (! specImpl.getResourceAdapter().equals(this))
      throw new ResourceException("Supplied ActivationSpec instance associated to an other ResourceAdapter.");

    if (logger.isLoggable(BasicLevel.DEBUG))
      logger.log(BasicLevel.DEBUG, "Activating Endpoint on JORAM adapter.");

    boolean durable =
      specImpl.getSubscriptionDurability() != null
      && specImpl.getSubscriptionDurability().equalsIgnoreCase("Durable");

    boolean transacted = false;
    try {
      Class listenerClass = Class.forName("javax.jms.MessageListener");
      Class[] parameters = { Class.forName("javax.jms.Message") };
      Method meth = listenerClass.getMethod("onMessage", parameters);
      transacted = endpointFactory.isDeliveryTransacted(meth);
    } catch (Exception exc) {
      throw new ResourceException("Could not determine transactional context: " + exc);
    }

    int maxWorks = 10;
    try {
      maxWorks = Integer.parseInt(specImpl.getMaxNumberOfWorks());
    } catch (Exception exc) {
      throw new ResourceException("Invalid max number of works instances number: " + exc);
    }

    int maxMessages = 10;
    try {
      maxMessages = Integer.parseInt(specImpl.getMaxMessages());
    } catch (Exception exc) {
      throw new ResourceException("Invalid max messages number: " + exc);
    }

    int ackMode;
    try {
      if (ActivationSpecImpl.AUTO_ACKNOWLEDGE.equals(specImpl.getAcknowledgeMode())) {
        ackMode = Session.AUTO_ACKNOWLEDGE;
      } else if (ActivationSpecImpl.DUPS_OK_ACKNOWLEDGE.equals(specImpl.getAcknowledgeMode())) {
        ackMode = Session.DUPS_OK_ACKNOWLEDGE;
      } else {
        ackMode = Session.AUTO_ACKNOWLEDGE;
      }
    }  catch (Exception exc) {
      throw new ResourceException("Invalid acknowledge mode: " + exc);
    }

    String destType = specImpl.getDestinationType();
    String destName = specImpl.getDestination();

    try {
      Destination dest;
     
      try {
        Context ctx = new InitialContext();
        dest = (Destination) ctx.lookup(destName);
      } catch (javax.naming.NamingException exc) {
        String shortName = removePrefix(destName);
        if ("javax.jms.Queue".equals(destType))
          dest = AdminModule.createQueue(serverId,
                                         shortName,
                                         "org.objectweb.joram.mom.dest.Queue",
                                         null);
        else if ("javax.jms.Topic".equals(destType))
          dest = AdminModule.createTopic(serverId,
                                         shortName,
                                         "org.objectweb.joram.mom.dest.Topic",
                                         null);
        else
          throw new NotSupportedException("Invalid destination type provided as activation parameter: " + destType);
       
        dest.setFreeReading();
        dest.setFreeWriting();

        if (logger.isLoggable(BasicLevel.INFO))
          logger.log(BasicLevel.INFO,
                     "  - Destination [" + shortName + "] has been created.");

        bind(destName, dest);
      }

      if ("javax.jms.Queue".equals(destType)) {
        if (! (dest instanceof javax.jms.Queue))
          throw new NotSupportedException("Existing destination " + destName  + " does not provide correct type.");
      } else if ("javax.jms.Topic".equals(destType)) {
        if (! (dest instanceof javax.jms.Topic))
          throw new NotSupportedException("Existing destination " + destName  + " does not provide correct type.");
      } else
        throw new NotSupportedException("Invalid destination type provided as activation parameter: " + destType);

      String userName = specImpl.getUserName();
      String password = specImpl.getPassword();
      String identityClass = specImpl.getIdentityClass();

      createUser(userName, password, identityClass);

      ConnectionFactory cf = null;

      if (isHa) {
        if (collocated) {
          if (haURL != null) {
            cf = HATcpConnectionFactory.create(haURL);
          } else {
            cf = HALocalConnectionFactory.create();
          }
        } else {
          cf = HATcpConnectionFactory.create("hajoram://" + hostName + ':' + serverPort);
        }
      }  else {
        if (collocated)
          cf = LocalConnectionFactory.create();
        else
          cf = TcpConnectionFactory.create(hostName, serverPort);
      }

      cf.getParameters().connectingTimer = connectingTimer;
      cf.getParameters().cnxPendingTimer = cnxPendingTimer;
      cf.getParameters().txPendingTimer = txPendingTimer;

      if (queueMessageReadMax > 0) {
        cf.getParameters().queueMessageReadMax = queueMessageReadMax;
      }

      if (topicAckBufferMax > 0) {
        cf.getParameters().topicAckBufferMax = topicAckBufferMax;
      }

      if (topicPassivationThreshold > 0) {
        cf.getParameters().topicPassivationThreshold = topicPassivationThreshold;
      }

      if (topicActivationThreshold > 0) {
        cf.getParameters().topicActivationThreshold = topicActivationThreshold;
      }

      // set identity class for this connectionFactory.
      cf.setIdentityClassName(identityClass);

      XAConnection cnx = cf.createXAConnection(userName, password);
     
      // set Exception listener
      cnx.setExceptionListener(this);
     
      if (logger.isLoggable(BasicLevel.DEBUG))
        logger.log(BasicLevel.DEBUG, this + " endpointActivation cnx = " + cnx);

      // Creating and registering a consumer instance for this endpoint.
      InboundConsumer consumer =
        new InboundConsumer(workManager,
                            endpointFactory,
                            cnx,
                            dest,
                            specImpl.getMessageSelector(),
                            durable,
                            specImpl.getSubscriptionName(),
                            transacted,
                            maxWorks,
                            maxMessages,
                            ackMode,
                            deleteDurableSubscription);

      consumers.put(specImpl, consumer);
    } catch (javax.jms.JMSSecurityException exc) {
      throw new SecurityException("Invalid user identification: " + exc);
    } catch (javax.jms.JMSException exc) {
      throw new CommException("Could not connect to the JORAM server: " + exc);
    } catch (ConnectException exc) {
      throw new ResourceException("Problem when handling the JORAM destinations: " + exc);
    } catch (AdminException exc) {
      throw new ResourceException("Problem when handling the JORAM destinations: " + exc);
    }
  }
View Full Code Here

    public int getMaxConnections() throws ResourceException {
        try {
            Connection con = mc.getJdbcConnection();
            return con.getMetaData().getMaxConnections();
        } catch (SQLException ex) {
            ResourceException re = new EISSystemException(ex.getMessage());
            re.setLinkedException(ex);
            throw re;
        }
    }
View Full Code Here

      connections = new Hashtable();

    try {
      for (int i = 0; i < specs.length; i++) {
        if (! (specs[i] instanceof ActivationSpecImpl))
          throw new ResourceException("Provided ActivationSpec instance is not a JORAM activation spec.");

        specImpl = (ActivationSpecImpl) specs[i];

        if (! specImpl.getResourceAdapter().equals(this))
          throw new ResourceException("Supplied ActivationSpec instance associated to an other ResourceAdapter.");

        userName = specImpl.getUserName();

        // The connection does not already exist: creating it.
        if (! connections.containsKey(userName)) {
View Full Code Here

                return ((JMSComponent) component).getResourceAdapter();
            }
            throw new IllegalArgumentException("The 'jms' component doesn't implement JMSComponent interface.");
        }

        throw new ResourceException("MDB is used but no resource service was started.");

    }
View Full Code Here

        Class<?> rarClass = null;
        // JOnAS 4 class
        try {
            rarClass = Thread.currentThread().getContextClassLoader().loadClass(JONAS_4_RAR_CLASS);
        } catch (ClassNotFoundException cnfe) {
            throw new ResourceException("Cannot find the JOnAS resource adapter class", cnfe);
        }

        // Get method for Rar.getRar(jndiName);
        Method getRarMethod = null;
        try {
            getRarMethod = rarClass.getMethod("getRar", new Class[] {String.class});
        } catch (SecurityException e) {
            throw new ResourceException("Cannot get the getRar method on the class '" + rarClass + "'.", e);
        } catch (NoSuchMethodException e) {
            throw new ResourceException("Cannot get the getRar method on the class '" + rarClass + "'.", e);
        }

        // invoke method (static method)
        Object rarObject = null;
        try {
            rarObject = getRarMethod.invoke(null, jndiName);
        } catch (IllegalArgumentException e) {
            throw new ResourceException("Cannot invoke method with jndiName '" + jndiName + "'.", e);
        } catch (IllegalAccessException e) {
            throw new ResourceException("Cannot invoke method with jndiName '" + jndiName + "'.", e);
        } catch (InvocationTargetException e) {
            throw new ResourceException("Cannot invoke method with jndiName '" + jndiName + "'.", e
                    .getTargetException());
        }

        // get the resource adapter on the given object
        Method getResourceAdapterMethod = null;
        try {
            getResourceAdapterMethod = rarObject.getClass().getMethod("getResourceAdapter", new Class[] {});
        } catch (SecurityException e) {
            throw new ResourceException("Cannot get the getResourceAdapter method on the class '"
                    + rarObject.getClass() + "'.", e);
        } catch (NoSuchMethodException e) {
            throw new ResourceException("Cannot get the getResourceAdapter method on the class '"
                    + rarObject.getClass() + "'.", e);
        }

        // invoke method
        Object resourceAdapterObj = null;
        try {
            resourceAdapterObj = getResourceAdapterMethod.invoke(rarObject, new Object[] {});
        } catch (IllegalArgumentException e) {
            throw new ResourceException("Cannot invoke method getResourceAdapter on the rar object.", e);
        } catch (IllegalAccessException e) {
            throw new ResourceException("Cannot invoke method getResourceAdapter on the rar object.", e);
        } catch (InvocationTargetException e) {
            throw new ResourceException("Cannot invoke method getResourceAdapter on the rar object.", e);
        }

        // cast object
        ResourceAdapter resourceAdapter = null;
        if (resourceAdapterObj instanceof ResourceAdapter) {
            resourceAdapter = (ResourceAdapter) resourceAdapterObj;
        } else {
            throw new ResourceException("Object found is not an instance of ResourceAdapter");
        }
        return resourceAdapter;
    }
View Full Code Here

      log.info("getConnection " + this);

      checkDestroyedResourceException();

      if (param2 != null && ((TestConnectionRequestInfo) param2).failure.equals("getConnectionResource"))
         throw new ResourceException(this.toString());
      if (param2 != null && ((TestConnectionRequestInfo) param2).failure.equals("getConnectionRuntime"))
         throw new RuntimeException(this.toString());
      TestConnection c =  new TestConnection(this);
      handles.add(c);
      return c;
View Full Code Here

         ((TestConnection)p).setMc(this);
         handles.add(p);
      }
      else
      {
         throw new ResourceException("wrong kind of Connection " + p);
      }
   }
View Full Code Here

   }

   void checkDestroyedResourceException() throws ResourceException
   {
      if (destroyed.get())
         throw new ResourceException("Already destroyed " + this);
   }
View Full Code Here

      {
         this.isDeliveryTransacted = endpointFactory.isDeliveryTransacted(ONMESSAGE);
      }
      catch (Exception e)
      {
         throw new ResourceException(e);
      }
      if (endpointFactory instanceof JBossNotificationBroadcasterSupport)
         emitter = (JBossNotificationBroadcasterSupport) endpointFactory;
   }
View Full Code Here

TOP

Related Classes of javax.resource.ResourceException

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.