Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial version of EJB client (WIP)

  • Loading branch information...
commit d9f75ba6a0f0fe76793008b084a602ed5df3eeeb 0 parents
@jaikiran authored
32 .gitignore
@@ -0,0 +1,32 @@
+# ignore .svn metadata files
+.svn
+# ignore Maven generated target folders
+~
+target
+# ignore eclipse files
+.project
+.classpath
+.settings
+.metadata
+# ignore IDEA files
+*.iml
+*.ipr
+*.iws
+.idea
+maven-ant-tasks.jar
+test-output
+transaction.log
+# vim files
+*.swp
+/.gitk-tmp.*
+atlassian-ide-plugin.xml
+# temp files
+*~
+# maven versions plugin
+pom.xml.versionsBackup
+# hprof dumps
+/*.hprof
+# ignore 'randomly' strewn around logs
+server.log
+# ignore java crashes
+hs_err_pid*.log
83 pom.xml
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ ~ JBoss, Home of Professional Open Source.
+ ~ Copyright 2010, Red Hat, Inc., and individual contributors
+ ~ as indicated by the @author tags. See the copyright.txt file in the
+ ~ distribution for a full listing of individual contributors.
+ ~
+ ~ This is free software; you can redistribute it and/or modify it
+ ~ under the terms of the GNU Lesser General Public License as
+ ~ published by the Free Software Foundation; either version 2.1 of
+ ~ the License, or (at your option) any later version.
+ ~
+ ~ This software is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ ~ Lesser General Public License for more details.
+ ~
+ ~ You should have received a copy of the GNU Lesser General Public
+ ~ License along with this software; if not, write to the Free
+ ~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ ~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-parent</artifactId>
+ <version>6</version>
+ </parent>
+
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-ejb-client</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+
+ <name>JBoss EJB client</name>
+ <description>Client library for EJB applications working against JBoss AS</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.xnio</groupId>
+ <artifactId>xnio-api</artifactId>
+ <version>3.0.0.Beta3</version>
+ </dependency>
+
+ <!-- Re-evaluate this dependency -->
+ <dependency>
+ <groupId>org.jboss.xnio</groupId>
+ <artifactId>xnio-nio</artifactId>
+ <version>3.0.0.Beta3</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.remoting3</groupId>
+ <artifactId>jboss-remoting</artifactId>
+ <version>3.2.0.Beta2</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.sasl</groupId>
+ <artifactId>jboss-sasl</artifactId>
+ <version>1.0.0.Beta1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.logging</groupId>
+ <artifactId>jboss-logging</artifactId>
+ <version>3.0.0.GA</version>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.8.2</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
226 src/main/java/org/jboss/ejb/client/EJBClient.java
@@ -0,0 +1,226 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.ejb.client;
+
+import org.jboss.ejb.client.proxy.EJBProxyInvocationHandler;
+import org.jboss.logging.Logger;
+import org.jboss.remoting3.Channel;
+import org.jboss.remoting3.CloseHandler;
+import org.jboss.remoting3.Connection;
+import org.jboss.remoting3.Endpoint;
+import org.jboss.remoting3.Registration;
+import org.jboss.remoting3.Remoting;
+import org.jboss.remoting3.remote.RemoteConnectionProviderFactory;
+import org.jboss.sasl.JBossSaslProvider;
+import org.xnio.IoFuture;
+import org.xnio.OptionMap;
+import org.xnio.Options;
+import org.xnio.Xnio;
+
+import java.io.IOException;
+import java.lang.reflect.Proxy;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.security.Security;
+import java.util.Hashtable;
+import java.util.concurrent.CancellationException;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import static java.util.concurrent.TimeUnit.SECONDS;
+
+/**
+ * User: jpai
+ */
+public class EJBClient {
+
+ /**
+ * Logger
+ */
+ private static final Logger logger = Logger.getLogger(EJBClient.class);
+
+ // TODO: Make it configurable
+ private final ExecutorService executor = Executors.newFixedThreadPool(4);
+
+ private volatile Endpoint endpoint;
+
+ private Registration connectionProviderRegistration;
+
+ private volatile boolean channelOpened;
+
+ // TODO: Externalize
+ // Key to the EJB remote provider URL
+ public static final String EJB_REMOTE_PROVIDER_URI = "org.jboss.ejb.remote.provider.uri";
+
+ private final String remoteServerURI;
+
+ {
+ Security.addProvider(new JBossSaslProvider());
+ }
+
+ public EJBClient(final Hashtable<?, ?> environment) {
+ if (environment == null) {
+ throw new IllegalArgumentException("Environment cannot be null");
+ }
+ if (environment.get(EJB_REMOTE_PROVIDER_URI) == null) {
+ throw new RuntimeException("Need to specify " + EJB_REMOTE_PROVIDER_URI + " while creating a EJBClient");
+ }
+ this.remoteServerURI = (String) environment.get(EJB_REMOTE_PROVIDER_URI);
+ }
+
+ /**
+ * Creates and returns a proxy for a EJB identified by the <code>appName</code>, <code>moduleName</code>, <code>beanName</code>
+ * and the <code>beanInterfaceType</code>
+ *
+ * @param appName The application name of the deployment in which the EJB is deployed. This typically is the name of the enterprise
+ * archive (without the .ear suffix) in which the EJB is deployed on the server. The application name of the deployment
+ * is sometimes overridden through the use of application.xml. In such cases, the passed <code>appName</code> should match
+ * that name.
+ * <p/>
+ * The <code>appName</code> passed can be null if the EJB is <i>not</i> deployed an enterprise archive (.ear)
+ * @param moduleName The module name of the deployment in which the EJB is deployed. This typically is the name of the jar file (without the
+ * .jar suffix) or the name of the war file (without the .war suffix). The module name is allowed to be overridden through
+ * the use of deployment descriptors, in which case the passed <code>moduleName</code> should match that name.
+ * <p/>
+ * <code>moduleName</code> cannot be null or an empty value
+ * @param beanName The name of the EJB for which the proxy is being created
+ * @param beanInterfaceType The interface type exposed by the bean, for which we are creating the proxy. For example, if the bean exposes
+ * remote business interface view, then the client can pass that as the <code>beanInterfaceType</code>. Same applies
+ * for remote home interface.
+ * <p/>
+ * The <code>beanInterfaceType</code> cannot be null
+ * @param <T>
+ * @return
+ * @throws IllegalArgumentException If the moduleName is null or empty
+ * @throws IllegalArgumentException If the beanName is null or empty
+ * @throws IllegalArgumentException If the beanInterfaceType is null
+ * @throws IllegalArgumentException If the passed beanInterfaceType isn't a remote view of the bean
+ * @throws IllegalArgumentException If the passed combination of appName, moduleName, beanName and beanInterfaceType cannot identify
+ * an EJB deployed on the server
+ */
+ public <T> T getProxy(final String appName, final String moduleName, final String beanName, final Class<T> beanInterfaceType) {
+ if (!this.channelOpened) {
+ try {
+ this.connect();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ if (moduleName == null || moduleName.trim().isEmpty()) {
+ throw new IllegalArgumentException("Module name cannot be null or empty");
+ }
+ if (beanName == null || beanName.trim().isEmpty()) {
+ throw new IllegalArgumentException("Bean name cannot be null or empty");
+ }
+ if (beanInterfaceType == null) {
+ throw new IllegalArgumentException("Bean interface type cannot be null");
+ }
+ // TODO: Implement remoting protocol
+// final byte[] resolutionRequest = EJBRemoteProtocol.generateResolutionRequest(appName, moduleName, beanName, beanInterfaceType);
+// this.sendData(resolutionRequest);
+ if (beanInterfaceType == null) {
+ throw new UnsupportedOperationException("Proxy generation with a specific bean interface type not yet implemented");
+ }
+ return (T) Proxy.newProxyInstance(beanInterfaceType.getClassLoader(), new Class<?>[]{beanInterfaceType}, new EJBProxyInvocationHandler());
+ }
+
+ public void createSession(final Object proxy) {
+
+ }
+
+ private void sendData(final byte[] data) {
+
+ }
+
+ private synchronized void connect() throws IOException, URISyntaxException, InterruptedException, ExecutionException {
+ if (this.endpoint == null) {
+ this.endpoint = Remoting.createEndpoint("endpoint", executor, OptionMap.EMPTY);
+ final Xnio xnio = Xnio.getInstance();
+ this.connectionProviderRegistration = endpoint.addConnectionProvider("remote", new RemoteConnectionProviderFactory(xnio), OptionMap.create(Options.SSL_ENABLED, false));
+ }
+ final OptionMap clientOptions = OptionMap.create(Options.SASL_POLICY_NOANONYMOUS, Boolean.FALSE);
+ final IoFuture<Connection> futureConnection = endpoint.connect(new URI(remoteServerURI), clientOptions, new EndpointAuthenticationCallbackHandler());
+ final IoFuture.Status status = futureConnection.awaitInterruptibly(5, SECONDS);
+ Connection connection = null;
+ switch (status) {
+ case CANCELLED:
+ throw new CancellationException();
+ case FAILED:
+ throw new ExecutionException(futureConnection.getException());
+ case DONE:
+ connection = futureConnection.get();
+ break;
+ case WAITING:
+ throw new RuntimeException("Timed out waiting to connect to EJB endpoint");
+ default:
+ throw new RuntimeException("Unknow return status: " + status + " during an attempt to connect to EJB endpoint");
+ }
+ logger.info("Connected to remote EJB endpoint " + connection);
+ final Channel channel = this.openChannel(connection);
+ channel.addCloseHandler(new ChannelCloseHandler());
+ logger.info("Channel opened: " + channel);
+ this.channelOpened = true;
+
+ }
+
+ private Channel openChannel(final Connection connection) throws InterruptedException, IOException, ExecutionException {
+ final IoFuture<Channel> futureChannel = connection.openChannel("ejb3", OptionMap.EMPTY);
+ final IoFuture.Status status = futureChannel.awaitInterruptibly(5, SECONDS);
+ switch (status) {
+ case CANCELLED:
+ throw new CancellationException();
+ case FAILED:
+ throw new ExecutionException(futureChannel.getException());
+ case DONE:
+ return futureChannel.get();
+ case WAITING:
+ throw new RuntimeException("Timed out waiting to open a channel on EJB endpoint");
+ default:
+ throw new RuntimeException("Unknown status");
+ }
+ }
+
+ private class ChannelCloseHandler implements CloseHandler<Channel> {
+
+ @Override
+ public void handleClose(Channel closed, IOException exception) {
+ EJBClient.this.channelOpened = false;
+ }
+ }
+
+ private void cleanup() throws IOException {
+ if (endpoint != null) {
+ endpoint.close();
+ }
+ if (executor != null) {
+ executor.shutdown();
+ }
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ this.cleanup();
+ super.finalize();
+ }
+}
47 src/main/java/org/jboss/ejb/client/EndpointAuthenticationCallbackHandler.java
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.ejb.client;
+
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.NameCallback;
+import javax.security.auth.callback.UnsupportedCallbackException;
+import java.io.IOException;
+
+/**
+ * User: jpai
+ */
+public class EndpointAuthenticationCallbackHandler implements CallbackHandler {
+
+ @Override
+ public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
+ for (Callback current : callbacks) {
+ if (current instanceof NameCallback) {
+ NameCallback ncb = (NameCallback) current;
+ ncb.setName("anonymous");
+ } else {
+ throw new UnsupportedCallbackException(current);
+ }
+ }
+ }
+}
265 src/main/java/org/jboss/ejb/client/naming/InitialContext.java
@@ -0,0 +1,265 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.ejb.client.naming;
+
+import org.jboss.ejb.client.EJBClient;
+import org.jboss.logging.Logger;
+
+import javax.naming.Binding;
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NameClassPair;
+import javax.naming.NameParser;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import java.util.Hashtable;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * User: jpai
+ */
+class InitialContext implements Context {
+
+ private static final Logger logger = Logger.getLogger(InitialContext.class);
+
+ // TODO: This pattern needs to be fixed. For example, appName and moduleName can contain special characters
+ private static final Pattern GLOBAL_JNDI_NAME_PATTERN = Pattern.compile("(java:global/)([a-zA-Z]+[/])?([a-zA-Z]+[/])([a-zA-Z_\\$]+)([\\!][a-zA-Z_\\.\\$]+)?");
+
+ private final EJBClient ejbClient;
+
+ private final Hashtable environment;
+
+ public InitialContext(Hashtable<?, ?> environment) throws NamingException {
+ this.environment = environment;
+ // TODO: this is a hack for now
+ if (environment != null && environment.containsKey(EJBClient.EJB_REMOTE_PROVIDER_URI)) {
+ this.ejbClient = new EJBClient(environment);
+ } else {
+ this.ejbClient = null;
+ }
+ }
+
+ @Override
+ public Object lookup(String name) throws NamingException {
+ // TODO: Major hack for now! We only support java:global EJB3.1 jndi names
+ if (name == null) {
+ throw new IllegalArgumentException("Name cannot be null");
+ }
+ Matcher matcher = GLOBAL_JNDI_NAME_PATTERN.matcher(name);
+ if (!matcher.matches()) {
+ throw new IllegalArgumentException("Invalid jndi name, cannot lookup " + name);
+ }
+ if (this.ejbClient == null) {
+ throw new NamingException("Need to specify " + EJBClient.EJB_REMOTE_PROVIDER_URI + " while creating " + this.getClass().getName());
+ }
+ String appName = null;
+ String moduleName = null;
+ String beanName = null;
+ String beanInterface = null;
+ // strip off the "!" from the beginning of last group
+ if (matcher.group(5) != null) {
+ beanInterface = matcher.group(5).substring(1);
+ }
+
+ beanName = matcher.group(4);
+
+ final String moduleNameGroup = matcher.group(3);
+ if (moduleNameGroup != null) {
+ // strip off the "/" from the end
+ moduleName = moduleNameGroup.substring(0, moduleNameGroup.length() - 1);
+ }
+
+ final String appNameGroup = matcher.group(2);
+ if (appNameGroup != null) {
+ // strip off "/" from the end
+ appName = appNameGroup.substring(0, appNameGroup.length() - 1);
+ }
+ logger.debug("Creating proxy for appName: " + appName + " moduleName: " + moduleName + " beanName: " + beanName + " beanInterface " + beanInterface);
+ Class<?> beanInterfaceType = null;
+ if (beanInterface != null) {
+ try {
+ beanInterfaceType = this.loadClass(beanInterface);
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException("Cannot lookup " + name, e);
+ }
+ }
+ return this.ejbClient.getProxy(appName, moduleName, beanName, beanInterfaceType);
+ }
+
+ @Override
+ public Object lookup(Name name) throws NamingException {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+
+ @Override
+ public void bind(Name name, Object obj) throws NamingException {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public void bind(String name, Object obj) throws NamingException {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public void rebind(Name name, Object obj) throws NamingException {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public void rebind(String name, Object obj) throws NamingException {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public void unbind(Name name) throws NamingException {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public void unbind(String name) throws NamingException {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public void rename(Name oldName, Name newName) throws NamingException {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public void rename(String oldName, String newName) throws NamingException {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public NamingEnumeration<NameClassPair> list(Name name) throws NamingException {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public NamingEnumeration<NameClassPair> list(String name) throws NamingException {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public NamingEnumeration<Binding> listBindings(Name name) throws NamingException {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public NamingEnumeration<Binding> listBindings(String name) throws NamingException {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public void destroySubcontext(Name name) throws NamingException {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public void destroySubcontext(String name) throws NamingException {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public Context createSubcontext(Name name) throws NamingException {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public Context createSubcontext(String name) throws NamingException {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public Object lookupLink(Name name) throws NamingException {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public Object lookupLink(String name) throws NamingException {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public NameParser getNameParser(Name name) throws NamingException {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public NameParser getNameParser(String name) throws NamingException {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public Name composeName(Name name, Name prefix) throws NamingException {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public String composeName(String name, String prefix) throws NamingException {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public Object addToEnvironment(String propName, Object propVal) throws NamingException {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public Object removeFromEnvironment(String propName) throws NamingException {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public Hashtable<?, ?> getEnvironment() throws NamingException {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public void close() throws NamingException {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public String getNameInNamespace() throws NamingException {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ private Class<?> loadClass(final String klass) throws ClassNotFoundException {
+ if (klass == null) {
+ return null;
+ }
+ return Class.forName(klass, false, Thread.currentThread().getContextClassLoader());
+ }
+
+ public static void main(String[] args) throws Exception {
+ InitialContext ctx = new InitialContext(new Hashtable<Object, Object>());
+ ctx.lookup("java:global/app/module/bean!org.jboss.ejb.client.test.SimpleLookupTestCase$SimpleRemoteBusinessInterface");
+ ctx.lookup("java:global/b/c!d");
+ ctx.lookup("java:global/a/b/c");
+ }
+
+}
39 src/main/java/org/jboss/ejb/client/naming/InitialContextFactory.java
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.ejb.client.naming;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import java.util.Hashtable;
+
+/**
+ * User: jpai
+ */
+public class InitialContextFactory implements javax.naming.spi.InitialContextFactory {
+
+
+ @Override
+ public Context getInitialContext(Hashtable<?, ?> environment) throws NamingException {
+ return new org.jboss.ejb.client.naming.InitialContext(environment);
+ }
+}
34 src/main/java/org/jboss/ejb/client/protocol/EJBRemoteProtocol.java
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.ejb.client.protocol;
+
+/**
+ * User: jpai
+ */
+public class EJBRemoteProtocol {
+
+ public static byte[] generateResolutionRequest(final String appName, final String moduleName, final String beanName,
+ final Class<?> beanInterfaceType) {
+ return null;
+ }
+}
36 src/main/java/org/jboss/ejb/client/proxy/EJBProxyInvocationHandler.java
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.ejb.client.proxy;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+
+/**
+ * User: jpai
+ */
+public class EJBProxyInvocationHandler implements InvocationHandler {
+ @Override
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ throw new UnsupportedOperationException("Remoting invocation not yet implemented");
+ }
+}
1  src/main/resources/services/javax.naming.spi.InitialContextFactory
@@ -0,0 +1 @@
+org.jboss.ejb.client.naming.InitialContextFactory
60 src/test/java/org/jboss/ejb/client/test/SimpleLookupTestCase.java
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.ejb.client.test;
+
+import org.jboss.ejb.client.EJBClient;
+import org.junit.Assert;
+import org.junit.Test;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import java.util.Properties;
+
+/**
+ * User: jpai
+ */
+public class SimpleLookupTestCase {
+
+ @Test
+ public void testJndiLookup() throws Exception {
+ final Properties props = new Properties();
+ props.put(EJBClient.EJB_REMOTE_PROVIDER_URI, "remote://localhost:9999");
+ props.put(Context.INITIAL_CONTEXT_FACTORY, org.jboss.ejb.client.naming.InitialContextFactory.class.getName());
+
+ final Context ctx = new InitialContext(props);
+ final SimpleRemoteBusinessInterface proxy = (SimpleRemoteBusinessInterface) ctx.lookup("java:global/app/module/bean!" + SimpleRemoteBusinessInterface.class.getName());
+ try {
+ proxy.doNothing();
+ // temporary till we implement the remoting
+ Assert.fail("Remoting was expected to be non-functional");
+ } catch (UnsupportedOperationException uoe) {
+ // expected for now!
+ }
+
+ }
+
+ private interface SimpleRemoteBusinessInterface {
+
+ void doNothing();
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.