Search in sources :

Example 1 with InvalidPropertyException

use of javax.resource.spi.InvalidPropertyException in project activemq-artemis by apache.

the class ActiveMQActivationSpec method validate.

/**
 * Validate
 *
 * @throws InvalidPropertyException Thrown if a validation exception occurs
 */
@Override
public void validate() throws InvalidPropertyException {
    if (logger.isTraceEnabled()) {
        logger.trace("validate()");
    }
    List<String> errorMessages = new ArrayList<>();
    List<PropertyDescriptor> propsNotSet = new ArrayList<>();
    try {
        if (destination == null || destination.trim().equals("")) {
            propsNotSet.add(new PropertyDescriptor("destination", ActiveMQActivationSpec.class));
            errorMessages.add("Destination is mandatory.");
        }
        if (destinationType != null && !Topic.class.getName().equals(destinationType) && !Queue.class.getName().equals(destinationType)) {
            propsNotSet.add(new PropertyDescriptor("destinationType", ActiveMQActivationSpec.class));
            errorMessages.add("If set, the destinationType must be either 'javax.jms.Topic' or 'javax.jms.Queue'.");
        }
        if ((destinationType == null || destinationType.length() == 0 || Topic.class.getName().equals(destinationType)) && isSubscriptionDurable() && (subscriptionName == null || subscriptionName.length() == 0)) {
            propsNotSet.add(new PropertyDescriptor("subscriptionName", ActiveMQActivationSpec.class));
            errorMessages.add("If subscription is durable then subscription name must be specified.");
        }
    } catch (IntrospectionException e) {
        ActiveMQRALogger.LOGGER.unableToValidateProperties(e);
    }
    if (propsNotSet.size() > 0) {
        StringBuffer b = new StringBuffer();
        b.append("Invalid settings:");
        for (String errorMessage : errorMessages) {
            b.append(" ");
            b.append(errorMessage);
        }
        InvalidPropertyException e = new InvalidPropertyException(b.toString());
        final PropertyDescriptor[] descriptors = propsNotSet.toArray(new PropertyDescriptor[propsNotSet.size()]);
        e.setInvalidPropertyDescriptors(descriptors);
        throw e;
    }
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) ArrayList(java.util.ArrayList) IntrospectionException(java.beans.IntrospectionException) InvalidPropertyException(javax.resource.spi.InvalidPropertyException) Topic(javax.jms.Topic) Queue(javax.jms.Queue)

Example 2 with InvalidPropertyException

use of javax.resource.spi.InvalidPropertyException in project activemq-artemis by apache.

the class ActiveMQMessageHandlerTest method testBadDestinationType.

@Test
public void testBadDestinationType() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("badDestinationType");
    spec.setDestination("mdbTopic");
    spec.setSetupAttempts(1);
    spec.setShareSubscriptions(true);
    spec.setMaxSession(1);
    CountDownLatch latch = new CountDownLatch(5);
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    try {
        qResourceAdapter.endpointActivation(endpointFactory, spec);
        fail();
    } catch (Exception e) {
        assertTrue(e instanceof InvalidPropertyException);
        assertEquals("destinationType", ((InvalidPropertyException) e).getInvalidPropertyDescriptors()[0].getName());
    }
}
Also used : InvalidPropertyException(javax.resource.spi.InvalidPropertyException) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) ActiveMQActivationSpec(org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec) CountDownLatch(java.util.concurrent.CountDownLatch) ResourceException(javax.resource.ResourceException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) JMSException(javax.jms.JMSException) InvalidPropertyException(javax.resource.spi.InvalidPropertyException) Test(org.junit.Test)

Example 3 with InvalidPropertyException

use of javax.resource.spi.InvalidPropertyException in project activemq-artemis by apache.

the class ActiveMQMessageHandlerTest method testNullSubscriptionName.

@Test
public void testNullSubscriptionName() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestination("mdbTopic");
    spec.setSubscriptionDurability("Durable");
    spec.setClientID("id-1");
    spec.setSetupAttempts(1);
    spec.setShareSubscriptions(true);
    spec.setMaxSession(1);
    CountDownLatch latch = new CountDownLatch(5);
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    try {
        qResourceAdapter.endpointActivation(endpointFactory, spec);
        fail();
    } catch (Exception e) {
        assertTrue(e instanceof InvalidPropertyException);
        assertEquals("subscriptionName", ((InvalidPropertyException) e).getInvalidPropertyDescriptors()[0].getName());
    }
}
Also used : InvalidPropertyException(javax.resource.spi.InvalidPropertyException) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) ActiveMQActivationSpec(org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec) CountDownLatch(java.util.concurrent.CountDownLatch) ResourceException(javax.resource.ResourceException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) JMSException(javax.jms.JMSException) InvalidPropertyException(javax.resource.spi.InvalidPropertyException) Test(org.junit.Test)

Example 4 with InvalidPropertyException

use of javax.resource.spi.InvalidPropertyException in project teiid by teiid.

the class MongoDBManagedConnectionFactory method getServers.

protected List<ServerAddress> getServers() throws ResourceException {
    String serverlist = getRemoteServerList();
    if (!serverlist.startsWith("mongodb://")) {
        // $NON-NLS-1$
        List<ServerAddress> addresses = new ArrayList<ServerAddress>();
        // $NON-NLS-1$
        StringTokenizer st = new StringTokenizer(serverlist, ";");
        while (st.hasMoreTokens()) {
            String token = st.nextToken();
            int idx = token.indexOf(':');
            if (idx < 0) {
                // $NON-NLS-1$
                throw new InvalidPropertyException(UTIL.getString("no_database"));
            }
            addresses.add(new ServerAddress(token.substring(0, idx), Integer.valueOf(token.substring(idx + 1))));
        }
        return addresses;
    }
    return null;
}
Also used : StringTokenizer(java.util.StringTokenizer) ServerAddress(com.mongodb.ServerAddress) ArrayList(java.util.ArrayList) InvalidPropertyException(javax.resource.spi.InvalidPropertyException)

Example 5 with InvalidPropertyException

use of javax.resource.spi.InvalidPropertyException in project teiid by teiid.

the class WSManagedConnectionFactory method createConnectionFactory.

@SuppressWarnings("serial")
@Override
public BasicConnectionFactory<WSConnectionImpl> createConnectionFactory() throws ResourceException {
    if (this.endPointName == null) {
        this.endPointName = WSManagedConnectionFactory.DEFAULT_LOCAL_NAME;
    }
    if (this.serviceName == null) {
        this.serviceName = WSManagedConnectionFactory.DEFAULT_LOCAL_NAME;
    }
    if (this.namespaceUri == null) {
        this.namespaceUri = WSManagedConnectionFactory.DEFAULT_NAMESPACE_URI;
    }
    this.portQName = new QName(this.namespaceUri, this.endPointName);
    this.serviceQName = new QName(this.namespaceUri, this.serviceName);
    if (this.wsdl != null) {
        try {
            this.wsdlUrl = new URL(this.wsdl);
        } catch (MalformedURLException e) {
            File f = new File(this.wsdl);
            try {
                this.wsdlUrl = f.toURI().toURL();
            } catch (MalformedURLException e1) {
                throw new InvalidPropertyException(e1);
            }
        }
    }
    if (this.configFile != null) {
        this.bus = new SpringBusFactory().createBus(this.configFile);
        JaxWsClientFactoryBean instance = new JaxWsClientFactoryBean();
        if (this.wsdl == null) {
            Configurer configurer = this.bus.getExtension(Configurer.class);
            if (null != configurer) {
                // $NON-NLS-1$
                configurer.configureBean(this.portQName.toString() + ".jaxws-client.proxyFactory", instance);
            }
            this.outInterceptors = instance.getOutInterceptors();
        }
    }
    return new BasicConnectionFactory<WSConnectionImpl>() {

        @Override
        public WSConnectionImpl getConnection() throws ResourceException {
            return new WSConnectionImpl(WSManagedConnectionFactory.this);
        }
    };
}
Also used : JaxWsClientFactoryBean(org.apache.cxf.jaxws.JaxWsClientFactoryBean) MalformedURLException(java.net.MalformedURLException) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) BasicConnectionFactory(org.teiid.resource.spi.BasicConnectionFactory) QName(javax.xml.namespace.QName) InvalidPropertyException(javax.resource.spi.InvalidPropertyException) Configurer(org.apache.cxf.configuration.Configurer) File(java.io.File) URL(java.net.URL)

Aggregations

InvalidPropertyException (javax.resource.spi.InvalidPropertyException)8 ArrayList (java.util.ArrayList)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 JMSException (javax.jms.JMSException)2 ResourceException (javax.resource.ResourceException)2 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)2 ActiveMQResourceAdapter (org.apache.activemq.artemis.ra.ActiveMQResourceAdapter)2 ActiveMQActivationSpec (org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec)2 Test (org.junit.Test)2 BasicConnectionFactory (org.teiid.resource.spi.BasicConnectionFactory)2 CouchbaseEnvironment (com.couchbase.client.java.env.CouchbaseEnvironment)1 DefaultCouchbaseEnvironment (com.couchbase.client.java.env.DefaultCouchbaseEnvironment)1 ScanConsistency (com.couchbase.client.java.query.consistency.ScanConsistency)1 ServerAddress (com.mongodb.ServerAddress)1 IntrospectionException (java.beans.IntrospectionException)1 PropertyDescriptor (java.beans.PropertyDescriptor)1 File (java.io.File)1 Method (java.lang.reflect.Method)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1