use of javax.validation.ValidationException in project apex-core by apache.
the class LogicalPlanTest method testLocalityValidation.
@Test
public void testLocalityValidation() {
TestGeneratorInputOperator input1 = dag.addOperator("input1", TestGeneratorInputOperator.class);
GenericTestOperator o1 = dag.addOperator("o1", GenericTestOperator.class);
StreamMeta s1 = dag.addStream("input1.outport", input1.outport, o1.inport1).setLocality(Locality.THREAD_LOCAL);
dag.validate();
TestGeneratorInputOperator input2 = dag.addOperator("input2", TestGeneratorInputOperator.class);
dag.addStream("input2.outport", input2.outport, o1.inport2);
try {
dag.validate();
Assert.fail("Exception expected for " + o1);
} catch (ValidationException ve) {
Assert.assertThat("", ve.getMessage(), RegexMatcher.matches("Locality THREAD_LOCAL invalid for operator .* with multiple input streams .*"));
}
s1.setLocality(null);
dag.validate();
}
use of javax.validation.ValidationException in project tomee by apache.
the class ValidatorBuilder method getConfig.
@SuppressWarnings("unchecked")
private static Configuration<?> getConfig(final ValidationInfo info) {
Configuration<?> target = null;
final Thread thread = Thread.currentThread();
final ClassLoader classLoader = thread.getContextClassLoader();
String providerClassName = info.providerClassName;
if (providerClassName == null) {
providerClassName = SystemInstance.get().getOptions().get(VALIDATION_PROVIDER_KEY, (String) null);
}
if (providerClassName != null) {
try {
@SuppressWarnings({ "unchecked", "rawtypes" }) final Class clazz = classLoader.loadClass(providerClassName);
target = Validation.byProvider(clazz).configure();
logger.info("Using " + providerClassName + " as validation provider.");
} catch (final ClassNotFoundException e) {
logger.warning("Unable to load provider class " + providerClassName, e);
} catch (final ValidationException ve) {
logger.warning("Unable create validator factory with provider " + providerClassName + " (" + ve.getMessage() + ")." + " Default one will be used.");
}
}
if (target == null) {
// force to use container provider to ignore any conflicting configuration
thread.setContextClassLoader(ValidatorBuilder.class.getClassLoader());
target = Validation.byDefaultProvider().configure();
thread.setContextClassLoader(classLoader);
}
final Set<ExecutableType> types = new HashSet<>();
for (final String type : info.validatedTypes) {
types.add(ExecutableType.valueOf(type));
}
final Map<String, String> props = new HashMap<>();
for (final Map.Entry<Object, Object> entry : info.propertyTypes.entrySet()) {
final PropertyType property = new PropertyType();
property.setName((String) entry.getKey());
property.setValue((String) entry.getValue());
props.put(property.getName(), property.getValue());
if (logger.isDebugEnabled()) {
logger.debug("Found property '" + property.getName() + "' with value '" + property.getValue());
}
target.addProperty(property.getName(), property.getValue());
}
final OpenEjbBootstrapConfig bootstrapConfig = new OpenEjbBootstrapConfig(providerClassName, info.constraintFactoryClass, info.messageInterpolatorClass, info.traversableResolverClass, info.parameterNameProviderClass, new HashSet<>(info.constraintMappings), info.executableValidationEnabled, types, props);
final OpenEjbConfig config = new OpenEjbConfig(bootstrapConfig, target);
target.ignoreXmlConfiguration();
final String messageInterpolatorClass = info.messageInterpolatorClass;
if (messageInterpolatorClass != null) {
try {
@SuppressWarnings("unchecked") final Class<MessageInterpolator> clazz = (Class<MessageInterpolator>) classLoader.loadClass(messageInterpolatorClass);
target.messageInterpolator(newInstance(config, clazz));
} catch (final Exception e) {
logger.warning("Unable to set " + messageInterpolatorClass + " as message interpolator.", e);
}
logger.info("Using " + messageInterpolatorClass + " as message interpolator.");
}
final String traversableResolverClass = info.traversableResolverClass;
if (traversableResolverClass != null) {
try {
@SuppressWarnings("unchecked") final Class<TraversableResolver> clazz = (Class<TraversableResolver>) classLoader.loadClass(traversableResolverClass);
target.traversableResolver(newInstance(config, clazz));
} catch (final Exception e) {
logger.warning("Unable to set " + traversableResolverClass + " as traversable resolver.", e);
}
logger.info("Using " + traversableResolverClass + " as traversable resolver.");
}
final String constraintFactoryClass = info.constraintFactoryClass;
if (constraintFactoryClass != null) {
try {
@SuppressWarnings("unchecked") final Class<ConstraintValidatorFactory> clazz = (Class<ConstraintValidatorFactory>) classLoader.loadClass(constraintFactoryClass);
target.constraintValidatorFactory(newInstance(config, clazz));
} catch (final Exception e) {
logger.warning("Unable to set " + constraintFactoryClass + " as constraint factory.", e);
}
logger.info("Using " + constraintFactoryClass + " as constraint factory.");
}
for (final String mappingFileName : info.constraintMappings) {
if (logger.isDebugEnabled()) {
logger.debug("Opening input stream for " + mappingFileName);
}
final InputStream in = classLoader.getResourceAsStream(mappingFileName);
if (in == null) {
logger.warning("Unable to open input stream for mapping file " + mappingFileName + ". It will be ignored");
} else {
target.addMapping(in);
}
}
if (info.parameterNameProviderClass != null) {
try {
final Class<ParameterNameProvider> clazz = (Class<ParameterNameProvider>) classLoader.loadClass(info.parameterNameProviderClass);
target.parameterNameProvider(newInstance(config, clazz));
} catch (final Exception e) {
logger.warning("Unable to set " + info.parameterNameProviderClass + " as parameter name provider.", e);
}
logger.info("Using " + info.parameterNameProviderClass + " as parameter name provider.");
}
return config;
}
use of javax.validation.ValidationException in project tomee by apache.
the class DeployerEjb method deploy.
@Override
public AppInfo deploy(final String inLocation, Properties properties) throws OpenEJBException {
String rawLocation = inLocation;
if (rawLocation == null && properties == null) {
throw new NullPointerException("location and properties are null");
}
if (rawLocation == null) {
rawLocation = properties.getProperty(FILENAME);
}
if (properties == null) {
properties = new Properties();
}
AppModule appModule = null;
final File file;
if ("true".equalsIgnoreCase(properties.getProperty(OPENEJB_USE_BINARIES, "false"))) {
file = copyBinaries(properties);
} else {
file = new File(realLocation(rawLocation).iterator().next());
}
final boolean autoDeploy = Boolean.parseBoolean(properties.getProperty(OPENEJB_APP_AUTODEPLOY, "false"));
final String host = properties.getProperty(OPENEJB_DEPLOYER_HOST, null);
if (WebAppDeployer.Helper.isWebApp(file) && !oldWarDeployer) {
AUTO_DEPLOY.set(autoDeploy);
try {
final AppInfo appInfo = SystemInstance.get().getComponent(WebAppDeployer.class).deploy(host, contextRoot(properties, file.getAbsolutePath()), file);
if (appInfo != null) {
saveIfNeeded(properties, file, appInfo);
return appInfo;
}
throw new OpenEJBException("can't deploy " + file.getAbsolutePath());
} finally {
AUTO_DEPLOY.remove();
}
}
AppInfo appInfo = null;
try {
appModule = deploymentLoader.load(file, null);
// Add any alternate deployment descriptors to the modules
final Map<String, DeploymentModule> modules = new TreeMap<>();
for (final DeploymentModule module : appModule.getEjbModules()) {
modules.put(module.getModuleId(), module);
}
for (final DeploymentModule module : appModule.getClientModules()) {
modules.put(module.getModuleId(), module);
}
for (final WebModule module : appModule.getWebModules()) {
final String contextRoot = contextRoot(properties, module.getJarLocation());
if (contextRoot != null) {
module.setContextRoot(contextRoot);
module.setHost(host);
}
modules.put(module.getModuleId(), module);
}
for (final DeploymentModule module : appModule.getConnectorModules()) {
modules.put(module.getModuleId(), module);
}
for (final Map.Entry<Object, Object> entry : properties.entrySet()) {
String name = (String) entry.getKey();
if (name.startsWith(ALT_DD + "/")) {
name = name.substring(ALT_DD.length() + 1);
final DeploymentModule module;
final int slash = name.indexOf('/');
if (slash > 0) {
final String moduleId = name.substring(0, slash);
name = name.substring(slash + 1);
module = modules.get(moduleId);
} else {
module = appModule;
}
if (module != null) {
final String value = (String) entry.getValue();
final File dd = new File(value);
if (dd.canRead()) {
module.getAltDDs().put(name, dd.toURI().toURL());
} else {
module.getAltDDs().put(name, value);
}
}
}
}
appInfo = configurationFactory.configureApplication(appModule);
appInfo.autoDeploy = autoDeploy;
if (properties != null && properties.containsKey(OPENEJB_DEPLOYER_FORCED_APP_ID_PROP)) {
appInfo.appId = properties.getProperty(OPENEJB_DEPLOYER_FORCED_APP_ID_PROP);
}
if (!appInfo.webApps.isEmpty()) {
appInfo.properties.setProperty("tomcat.unpackWar", "false");
}
assembler.createApplication(appInfo);
saveIfNeeded(properties, file, appInfo);
return appInfo;
} catch (final Throwable e) {
// destroy the class loader for the failed application
if (appModule != null) {
ClassLoaderUtil.destroyClassLoader(appModule.getJarLocation());
}
if (null != appInfo) {
ClassLoaderUtil.destroyClassLoader(appInfo.appId, appInfo.path);
}
LOGGER.error("Can't deploy " + inLocation, e);
if (e instanceof ValidationException) {
throw (ValidationException) e;
}
final Throwable ex;
final DeploymentExceptionManager dem = SystemInstance.get().getComponent(DeploymentExceptionManager.class);
if (dem != null) {
if (dem.hasDeploymentFailed()) {
ex = dem.getLastException();
} else {
ex = e;
}
if (appInfo != null) {
dem.clearLastException(appInfo);
}
} else {
ex = e;
}
if (ex instanceof OpenEJBException) {
if (ex.getCause() instanceof ValidationException) {
throw (ValidationException) ex.getCause();
}
throw (OpenEJBException) ex;
}
throw new OpenEJBException(ex);
}
}
use of javax.validation.ValidationException in project tomee by apache.
the class ContainersImpl method deploy.
@Override
public boolean deploy(final InputStream archive, final String name) {
if (!OpenEJB.isInitialized())
stuck = name;
else
System.out.println("STUCK " + stuck);
exception = null;
final Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
ThreadSingletonServiceImpl.exit(null);
if (assembler != null) {
assembler.destroy();
}
try {
final File file = writeToFile(archive, name);
final Map<String, Object> map = new HashMap<String, Object>();
map.put(EJBContainer.MODULES, file);
map.put(EJBContainer.APP_NAME, name);
originalClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(new URLClassLoader(new URL[] { file.toURI().toURL() }, originalClassLoader));
container = EJBContainer.createEJBContainer(map);
// final WebBeansContext webBeansContext = ThreadSingletonServiceImpl.get();
// dump(webBeansContext.getBeanManagerImpl());
} catch (Exception e) {
if (e instanceof EJBException && e.getCause() instanceof ValidationException) {
exception = ValidationException.class.cast(e.getCause());
} else {
exception = e;
}
return false;
}
return true;
}
Aggregations