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;
}
}
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());
}
}
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());
}
}
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;
}
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);
}
};
}
Aggregations