use of org.glassfish.hk2.api.MultiException in project Payara by payara.
the class ArchiveFactory method createArchive.
public WritableArchive createArchive(String protocol, URI path) throws IOException {
try {
WritableArchive archive = habitat.getService(WritableArchive.class, protocol);
if (archive == null) {
deplLogger.log(Level.SEVERE, IMPLEMENTATION_NOT_FOUND, protocol);
throw new MalformedURLException("Protocol not supported : " + protocol);
}
archive.create(path);
return archive;
} catch (MultiException e) {
LogRecord lr = new LogRecord(Level.SEVERE, IMPLEMENTATION_NOT_FOUND);
lr.setParameters(new Object[] { protocol });
lr.setThrown(e);
deplLogger.log(lr);
throw new MalformedURLException("Protocol not supported : " + protocol);
}
}
use of org.glassfish.hk2.api.MultiException in project Payara by payara.
the class ConnectionPool method resourceClosed.
/**
* this method is called to indicate that the resource is
* not used by a bean/application anymore
*/
@Override
public void resourceClosed(ResourceHandle h) throws IllegalStateException {
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Pool: resourceClosed: " + h);
}
ResourceState state = getResourceState(h);
if (state == null) {
throw new IllegalStateException("State is null");
}
if (!state.isBusy()) {
// throw new IllegalStateException("state.isBusy() : false");
_logger.log(Level.WARNING, "state.isBusy already set to false for {0}#{1}", new Object[] { h.getName(), h.getId() });
if (_logger.isLoggable(Level.FINE)) {
MultiException noBusyException = new MultiException(state.getBusyStackException());
noBusyException.addError(new IllegalStateException("state.isBusy() : false"));
_logger.log(Level.WARNING, null, noBusyException);
}
}
// mark as not busy
setResourceStateToFree(h);
state.touchTimestamp();
if (state.isUnenlisted() || (poolTxHelper.isNonXAResource(h) && poolTxHelper.isLocalTransactionInProgress() && poolTxHelper.isLocalResourceEligibleForReuse(h))) {
freeUnenlistedResource(h);
}
if (poolLifeCycleListener != null) {
poolLifeCycleListener.connectionReleased(h.getId());
}
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Pool: resourceFreed: " + h);
}
}
use of org.glassfish.hk2.api.MultiException in project Payara by payara.
the class InjectionManager method syncDoInject.
/**
* Initializes the component by performing injection.
*
* @param component component instance to inject
* @param onBehalfOf the inhabitant to do injection on behalf of
* @param type component class
* @param targets the injection resolvers to resolve all injection points
* @throws ComponentException
* if injection failed for some reason.
*/
protected void syncDoInject(Object component, Class type, InjectionResolver... targets) {
assert component != null;
try {
Class currentClass = type;
while (currentClass != null && Object.class != currentClass) {
// get the list of the instances variable
for (Field field : currentClass.getDeclaredFields()) {
Annotation nonOptionalAnnotation = null;
boolean injected = false;
for (InjectionResolver target : targets) {
Annotation inject = field.getAnnotation(target.type);
if (inject == null)
continue;
Type genericType = field.getGenericType();
Class fieldType = field.getType();
try {
Object value = target.getValue(component, field, genericType, fieldType);
if (value != null) {
AccessController.doPrivileged(new PrivilegedAction<Field>() {
@Override
public Field run() {
field.setAccessible(true);
return field;
}
});
field.set(component, value);
injected = true;
break;
} else {
if (!target.isOptional(field, inject)) {
nonOptionalAnnotation = inject;
}
}
} catch (MultiException e) {
error_injectionException(target, inject, field, e);
} catch (IllegalAccessException e) {
error_injectionException(target, inject, field, e);
} catch (RuntimeException e) {
error_injectionException(target, inject, field, e);
} catch (Exception ex) {
error_injectionException(target, inject, field, ex);
}
}
// exhausted all injection managers,
if (!injected && nonOptionalAnnotation != null) {
throw new UnsatisfiedDependencyException(field, nonOptionalAnnotation);
}
}
for (Method method : currentClass.getDeclaredMethods()) {
for (InjectionResolver target : targets) {
Annotation inject = method.getAnnotation(target.type);
if (inject == null)
continue;
Method setter = target.getSetterMethod(method, inject);
if (setter.getReturnType() != void.class) {
if (Collection.class.isAssignableFrom(setter.getReturnType())) {
injectCollection(component, setter, target.getValue(component, method, null, setter.getReturnType()));
continue;
}
error_InjectMethodIsNotVoid(method);
}
Class<?>[] paramTypes = setter.getParameterTypes();
Type[] genericParamTypes = setter.getGenericParameterTypes();
if (allowInjection(method, paramTypes)) {
try {
if (1 == paramTypes.length) {
Object value = target.getValue(component, method, genericParamTypes[0], paramTypes[0]);
if (value != null) {
AccessController.doPrivileged(new PrivilegedAction<Method>() {
@Override
public Method run() {
setter.setAccessible(true);
return setter;
}
});
setter.invoke(component, value);
} else {
if (!target.isOptional(method, inject)) {
throw new UnsatisfiedDependencyException(method, inject);
}
}
} else {
// multi params
AccessController.doPrivileged(new PrivilegedAction<Method>() {
@Override
public Method run() {
setter.setAccessible(true);
return setter;
}
});
Type[] gparamType = setter.getGenericParameterTypes();
Object[] params = new Object[paramTypes.length];
for (int i = 0; i < paramTypes.length; i++) {
Object value = target.getValue(component, method, gparamType[i], paramTypes[i]);
if (value != null) {
params[i] = value;
} else {
if (!target.isOptional(method, inject)) {
throw new UnsatisfiedDependencyException(method, inject);
}
}
}
setter.invoke(component, params);
}
} catch (MultiException e) {
error_injectionException(target, inject, setter, e);
} catch (IllegalAccessException e) {
error_injectionException(target, inject, setter, e);
} catch (InvocationTargetException e) {
error_injectionException(target, inject, setter, e);
} catch (RuntimeException e) {
error_injectionException(target, inject, setter, e);
}
}
}
}
currentClass = currentClass.getSuperclass();
}
} catch (final LinkageError e) {
// reflection could trigger additional classloading and resolution, so it can cause linkage error.
// report more information to assist diagnosis.
// can't trust component.toString() as the object could be in an inconsistent state.
final Class<?> cls = type;
AccessController.doPrivileged(new PrivilegedAction<Object>() {
@Override
public Object run() {
LinkageError x = new LinkageError("injection failed on " + cls + " from " + cls.getClassLoader());
x.initCause(e);
throw x;
}
});
}
}
use of org.glassfish.hk2.api.MultiException in project Payara by payara.
the class ActiveJmsResourceAdapter method destroy.
@Override
public void destroy() {
try {
JmsService jmsService = getJmsService();
if (jmsService != null && jmsService.getType().equals("DISABLED")) {
return;
}
if (connectorRuntime.isServer() && grizzlyListenerInit && jmsService != null && EMBEDDED.equalsIgnoreCase(jmsService.getType())) {
GrizzlyService grizzlyService = null;
try {
grizzlyService = Globals.get(GrizzlyService.class);
} catch (MultiException rle) {
// if GrizzlyService was shut down already, skip removing the proxy.
}
if (grizzlyService != null) {
synchronized (grizzlyListeners) {
if (grizzlyListeners.size() > 0) {
String[] listeners = grizzlyListeners.toArray(new String[grizzlyListeners.size()]);
for (String listenerName : listeners) {
try {
grizzlyService.removeNetworkProxy(listenerName);
grizzlyListeners.remove(listenerName);
} catch (Exception e) {
LogHelper.log(_logger, Level.WARNING, JMSLoggerInfo.SHUTDOWN_FAIL_GRIZZLY, e, listenerName);
}
}
}
}
}
grizzlyListenerInit = false;
}
} catch (Throwable th) {
if (_logger.isLoggable(Level.WARNING)) {
_logger.log(Level.WARNING, JMSLoggerInfo.SHUTDOWN_FAIL_JMSRA, new Object[] { th.getMessage() });
}
throw new RuntimeException(th);
}
super.destroy();
}
use of org.glassfish.hk2.api.MultiException in project jersey by jersey.
the class JerseyClassAnalyzer method getConstructor.
@SuppressWarnings("unchecked")
@Override
public <T> Constructor<T> getConstructor(final Class<T> clazz) throws MultiException, NoSuchMethodException {
if (clazz.isLocalClass()) {
throw new NoSuchMethodException(LocalizationMessages.INJECTION_ERROR_LOCAL_CLASS_NOT_SUPPORTED(clazz.getName()));
}
if (clazz.isMemberClass() && !Modifier.isStatic(clazz.getModifiers())) {
throw new NoSuchMethodException(LocalizationMessages.INJECTION_ERROR_NONSTATIC_MEMBER_CLASS_NOT_SUPPORTED(clazz.getName()));
}
final Constructor<T> retVal;
try {
retVal = defaultAnalyzer.getConstructor(clazz);
final Class<?>[] args = retVal.getParameterTypes();
if (args.length != 0) {
return retVal;
}
// Is zero length, but is it specifically marked?
final Inject i = retVal.getAnnotation(Inject.class);
if (i != null) {
return retVal;
}
// In this case, the default chose a zero-arg constructor since it could find no other
} catch (final NoSuchMethodException ignored) {
// In this case, the default failed because it found no constructor it could use
} catch (final MultiException me) {
if (me.getErrors().size() != 1 && !(me.getErrors().get(0) instanceof IllegalArgumentException)) {
throw me;
}
// Otherwise, the default failed because it found more than one constructor
}
// At this point, we simply need to find the constructor with the largest number of parameters
final Constructor<?>[] constructors = AccessController.doPrivileged(new PrivilegedAction<Constructor<?>[]>() {
@Override
public Constructor<?>[] run() {
return clazz.getDeclaredConstructors();
}
});
Constructor<?> selected = null;
int selectedSize = 0;
int maxParams = -1;
for (final Constructor<?> constructor : constructors) {
final Class<?>[] params = constructor.getParameterTypes();
if (params.length >= maxParams && isCompatible(constructor)) {
if (params.length > maxParams) {
maxParams = params.length;
selectedSize = 0;
}
selected = constructor;
selectedSize++;
}
}
if (selectedSize == 0) {
throw new NoSuchMethodException(LocalizationMessages.INJECTION_ERROR_SUITABLE_CONSTRUCTOR_NOT_FOUND(clazz.getName()));
}
if (selectedSize > 1) {
// Found {0} constructors with {1} parameters in {2} class. Selecting the first found constructor: {3}
Errors.warning(clazz, LocalizationMessages.MULTIPLE_MATCHING_CONSTRUCTORS_FOUND(selectedSize, maxParams, clazz.getName(), selected.toGenericString()));
}
return (Constructor<T>) selected;
}
Aggregations