Search in sources :

Example 31 with OpenEJBRuntimeException

use of org.apache.openejb.OpenEJBRuntimeException in project tomee by apache.

the class JaxWsUtils method getName.

public static String getName(final Class<?> clazz) {
    final WebService webService = clazz.getAnnotation(WebService.class);
    if (webService != null) {
        final String sei = webService.endpointInterface();
        if (sei != null && sei.trim().length() != 0) {
            try {
                final Class seiClass = clazz.getClassLoader().loadClass(sei.trim());
                return getNameFromInterface(seiClass);
            } catch (final ClassNotFoundException e) {
                throw new OpenEJBRuntimeException("Unable to load SEI class: " + sei, e);
            }
        }
        return getName(clazz, webService.name());
    }
    final WebServiceProvider webServiceProvider = clazz.getAnnotation(WebServiceProvider.class);
    if (webServiceProvider != null) {
        return clazz.getName();
    }
    throw new IllegalArgumentException("The " + clazz.getName() + " is not annotated");
}
Also used : OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) WebServiceProvider(javax.xml.ws.WebServiceProvider) WebService(javax.jws.WebService)

Example 32 with OpenEJBRuntimeException

use of org.apache.openejb.OpenEJBRuntimeException in project tomee by apache.

the class UrlCache method createCacheDir.

private static File createCacheDir() {
    try {
        final FileUtils openejbBase = SystemInstance.get().getBase();
        File dir = null;
        // if we are not embedded, cache (temp) dir is under base dir
        if (SystemInstance.get().getConf(null).exists()) {
            try {
                dir = openejbBase.getDirectory("temp");
            } catch (final IOException e) {
            // Ignore
            }
        }
        // if we are embedded, tmp dir is in the system tmp dir
        if (dir == null) {
            dir = Files.tmpdir();
        }
        // If the cache dir already exists then empty its contents
        if (dir.exists()) {
            final File[] files = dir.listFiles();
            if (null != files) {
                for (final File f : files) {
                    deleteDir(f);
                }
            }
        } else {
            dir = createCacheDir(new File(dir.getAbsolutePath()));
        }
        return dir;
    } catch (final IOException e) {
        throw new OpenEJBRuntimeException(e);
    }
}
Also used : OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) FileUtils(org.apache.openejb.loader.FileUtils) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 33 with OpenEJBRuntimeException

use of org.apache.openejb.OpenEJBRuntimeException in project tomee by apache.

the class DynamicProxyImplFactory method newProxy.

public static Object newProxy(final BeanContext context, final InvocationHandler invocationHandler) {
    if (QueryProxy.class.isInstance(invocationHandler)) {
        EntityManager em = null;
        for (final Injection injection : context.getInjections()) {
            if (QueryProxy.class.equals(injection.getTarget())) {
                try {
                    em = (EntityManager) context.getJndiEnc().lookup(injection.getJndiName());
                } catch (final NamingException e) {
                    throw new OpenEJBRuntimeException("a dynamic bean should reference at least one correct PersistenceContext", e);
                }
            }
        }
        if (em == null) {
            throw new OpenEJBRuntimeException("can't find the entity manager to use for the dynamic bean " + context.getEjbName());
        }
        QueryProxy.class.cast(invocationHandler).setEntityManager(em);
    }
    return newProxy(context.getBeanClass(), invocationHandler);
}
Also used : OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) EntityManager(javax.persistence.EntityManager) NamingException(javax.naming.NamingException) Injection(org.apache.openejb.Injection)

Example 34 with OpenEJBRuntimeException

use of org.apache.openejb.OpenEJBRuntimeException in project tomee by apache.

the class AbstractTomEEMojo method addJavaagents.

private void addJavaagents(final List<String> strings) {
    final String existingJavaagent = "\\\"-javaagent:$CATALINA_HOME/lib/openejb-javaagent.jar\\\"";
    final StringBuilder javaagentString = new StringBuilder(existingJavaagent);
    for (final String rawJavaagent : javaagents) {
        final String javaagent;
        final String args;
        int argsIdx = rawJavaagent.indexOf('=');
        if (argsIdx < 0) {
            argsIdx = rawJavaagent.indexOf('?');
        }
        if (argsIdx > 0) {
            javaagent = rawJavaagent.substring(0, argsIdx);
            args = rawJavaagent.substring(argsIdx);
        } else {
            javaagent = rawJavaagent;
            args = "";
        }
        String path = javaagent;
        if (!new File(javaagent).isFile()) {
            try {
                final FileWithMavenMeta jar = mvnToFile(javaagent, "jar");
                if (persistJavaagents) {
                    final File javaagentFolder = new File(catalinaBase, "javaagent");
                    Files.mkdirs(javaagentFolder);
                    String name = jar.resolved.getName();
                    if (stripVersion) {
                        name = jar.stripVersion(true);
                    }
                    path = "$CATALINA_HOME/javaagent/" + name;
                    IO.copy(jar.resolved, new File(javaagentFolder, name));
                }
                strings.add("-javaagent:" + jar.resolved.getAbsolutePath() + args);
            } catch (final Exception e) {
                getLog().warn("Can't find " + javaagent);
                strings.add("-javaagent:" + javaagent + args);
            }
        } else {
            strings.add("-javaagent:" + javaagent + args);
        }
        if (persistJavaagents) {
            javaagentString.append(" -javaagent:").append(path).append(args);
        }
    }
    if (persistJavaagents) {
        try {
            {
                final File catalinaSh = new File(catalinaBase, "bin/catalina.sh");
                final String content = IO.slurp(catalinaSh).replace(existingJavaagent, javaagentString.toString());
                doWrite(catalinaSh, content);
            }
            {
                final File catalinaBat = new File(catalinaBase, "bin/catalina.bat");
                final String content = IO.slurp(catalinaBat).replace("\"-javaagent:%CATALINA_HOME%\\lib\\openejb-javaagent.jar\"", javaagentString.toString().replace('\'', '"').replace('/', '\\').replace("$CATALINA_HOME", "%CATALINA_HOME%"));
                doWrite(catalinaBat, content);
            }
        } catch (final IOException ioe) {
            throw new OpenEJBRuntimeException(ioe);
        }
    }
}
Also used : OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) IOException(java.io.IOException) ZipFile(java.util.zip.ZipFile) File(java.io.File) URISyntaxException(java.net.URISyntaxException) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) ScriptException(javax.script.ScriptException) OpenEJBException(org.apache.openejb.OpenEJBException) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchElementException(java.util.NoSuchElementException) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException)

Example 35 with OpenEJBRuntimeException

use of org.apache.openejb.OpenEJBRuntimeException in project tomee by apache.

the class UpdatableTomEEMojo method deployer.

private Deployer deployer() {
    if (removeTomeeWebapp && !ejbRemote) {
        throw new OpenEJBRuntimeException("Can't use reload feature without TomEE Webapp, please set removeTomeeWebapp to false or ejbRemote to true");
    }
    final Properties properties = new Properties();
    properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName());
    properties.setProperty(Context.PROVIDER_URL, "http://" + tomeeHost + ":" + tomeeHttpPort + "/tomee/ejb");
    try {
        final Context context = new InitialContext(properties);
        return (Deployer) context.lookup("openejb/DeployerBusinessRemote");
    } catch (final NamingException e) {
        throw new OpenEJBRuntimeException("Can't lookup Deployer", e);
    }
}
Also used : OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) RemoteInitialContextFactory(org.apache.openejb.client.RemoteInitialContextFactory) NamingException(javax.naming.NamingException) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) Deployer(org.apache.openejb.assembler.Deployer)

Aggregations

OpenEJBRuntimeException (org.apache.openejb.OpenEJBRuntimeException)55 IOException (java.io.IOException)20 OpenEJBException (org.apache.openejb.OpenEJBException)17 ArrayList (java.util.ArrayList)13 Properties (java.util.Properties)12 NamingException (javax.naming.NamingException)9 MalformedURLException (java.net.MalformedURLException)8 BeanContext (org.apache.openejb.BeanContext)8 ObjectStreamException (java.io.ObjectStreamException)6 URISyntaxException (java.net.URISyntaxException)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 File (java.io.File)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 Method (java.lang.reflect.Method)4 URL (java.net.URL)4 ApplicationException (org.apache.openejb.ApplicationException)4 InvalidObjectException (java.io.InvalidObjectException)3 AccessException (java.rmi.AccessException)3 RemoteException (java.rmi.RemoteException)3