use of javax.resource.ResourceException in project javaee7-samples by javaee-samples.
the class FileSystemWatcherResourceAdapter method endpointActivation.
@Override
public void endpointActivation(MessageEndpointFactory endpointFactory, ActivationSpec activationSpec) throws ResourceException {
out.println(this.getClass().getSimpleName() + " resource adapater endpoint activated for " + endpointFactory.getEndpointClass());
FileSystemWatcherActivationSpec fsWatcherAS = (FileSystemWatcherActivationSpec) activationSpec;
try {
WatchKey watchKey = fileSystem.getPath(fsWatcherAS.getDir()).register(watchService, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
listeners.put(watchKey, endpointFactory);
endpointFactoryToBeanClass.put(endpointFactory, endpointFactory.getEndpointClass());
} catch (IOException e) {
throw new ResourceException(e);
}
}
use of javax.resource.ResourceException in project jackrabbit by apache.
the class JCAManagedConnection method openSession.
/**
* Create a new session.
*/
private Session openSession() throws ResourceException {
try {
Session session = mcf.getRepository().login(cri.getCredentials(), cri.getWorkspace());
log("Created session (" + session + ")");
return session;
} catch (RepositoryException e) {
log("Failed to create session", e);
ResourceException exception = new ResourceException("Failed to create session: " + e.getMessage());
exception.initCause(e);
throw exception;
}
}
use of javax.resource.ResourceException in project wildfly by wildfly.
the class MessageDrivenComponentCreateService method createActivationSpecs.
private ActivationSpec createActivationSpecs(final String resourceAdapterName, final Class<?> messageListenerInterface, final Properties activationConfigProperties, final ClassLoader classLoader) {
try {
// first get the ra "identifier" (with which it is registered in the resource adapter repository) for the
// ra name
final String raIdentifier = ConnectorServices.getRegisteredResourceAdapterIdentifier(resourceAdapterName);
if (raIdentifier == null) {
throw EjbLogger.ROOT_LOGGER.unknownResourceAdapter(resourceAdapterName);
}
final ResourceAdapterRepository resourceAdapterRepository = resourceAdapterRepositoryInjectedValue.getValue();
if (resourceAdapterRepository == null) {
throw EjbLogger.ROOT_LOGGER.resourceAdapterRepositoryUnAvailable();
}
// now get the message listeners for this specific ra identifier
final List<MessageListener> messageListeners = resourceAdapterRepository.getMessageListeners(raIdentifier);
if (messageListeners == null || messageListeners.isEmpty()) {
throw EjbLogger.ROOT_LOGGER.unknownMessageListenerType(messageListenerInterface.getName(), resourceAdapterName);
}
MessageListener requiredMessageListener = null;
// now find the expected message listener from the list of message listeners for this resource adapter
for (final MessageListener messageListener : messageListeners) {
if (messageListenerInterface.equals(messageListener.getType())) {
requiredMessageListener = messageListener;
break;
}
}
if (requiredMessageListener == null) {
throw EjbLogger.ROOT_LOGGER.unknownMessageListenerType(messageListenerInterface.getName(), resourceAdapterName);
}
// found the message listener, now finally create the activation spec
final Activation activation = requiredMessageListener.getActivation();
// filter out the activation config properties, specified on the MDB, which aren't accepted by the resource
// adaptor
final Properties validActivationConfigProps = this.filterUnknownActivationConfigProperties(resourceAdapterName, activation, activationConfigProperties);
// now set the activation config properties on the ActivationSpec
final ActivationSpec activationSpec = activation.createInstance();
BeanUtils.mapJavaBeanProperties(activationSpec, validActivationConfigProps);
return activationSpec;
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (ResourceException e) {
throw new RuntimeException(e);
} catch (InstantiationException e) {
throw new RuntimeException(e);
} catch (NotFoundException e) {
throw new RuntimeException(e);
} catch (IntrospectionException e) {
throw new RuntimeException(e);
}
}
use of javax.resource.ResourceException in project wildfly by wildfly.
the class SimpleResourceAdapter method endpointActivation.
/**
* Send a message to the MDB right after the MDB endpoint is activated.
* Using reflection to pick a method to invoke - see EJB 3.2 spec section 5.4.3
*/
@Override
public void endpointActivation(MessageEndpointFactory messageEndpointFactory, ActivationSpec activationSpec) throws ResourceException {
log.trace("SimpleResourceAdapter activating MDB endpoint and sending a message to it");
Class<?> endpointClass = messageEndpointFactory.getEndpointClass();
try {
Method methodToInvoke = endpointClass.getMethod(((SimpleActivationSpec) activationSpec).getMethodName(), String.class);
MessageEndpoint endpoint = messageEndpointFactory.createEndpoint(null);
this.endpoint = endpoint;
methodToInvoke.invoke(endpoint, "Hello world");
} catch (Exception e) {
throw new ResourceException(e);
}
}
use of javax.resource.ResourceException in project wildfly by wildfly.
the class TelnetResourceAdapter method endpointActivation.
@Override
public void endpointActivation(MessageEndpointFactory messageEndpointFactory, ActivationSpec activationSpec) throws ResourceException {
final TelnetActivationSpec telnetActivationSpec = (TelnetActivationSpec) activationSpec;
final MessageEndpoint messageEndpoint = messageEndpointFactory.createEndpoint(null);
// This messageEndpoint instance is also castable to the ejbClass of the MDB
final TelnetListener telnetListener = (TelnetListener) messageEndpoint;
try {
final TelnetServer telnetServer = new TelnetServer(telnetActivationSpec, telnetListener, port);
workManager.scheduleWork(new Work() {
@Override
public void release() {
}
@Override
public void run() {
try {
telnetServer.activate();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}, 0, null, null);
activated.put(port, telnetServer);
} catch (IOException e) {
throw new ResourceException(e);
}
}
Aggregations