Author: andygumbrecht
Date: Mon Dec 17 09:37:53 2012
New Revision: 1422816
URL: http://svn.apache.org/viewvc?rev=1422816&view=rev
Log:
Use 'ejbd.port'.
Use 'equals' over '=='.
Finals and overrides.
Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/VmDeploymentManager.java
openejb/trunk/openejb/examples/telephone-stateful/src/main/java/org/superbiz/telephone/TelephoneBean.java
openejb/trunk/openejb/examples/telephone-stateful/src/test/java/org/superbiz/telephone/TelephoneTest.java
openejb/trunk/openejb/itests/failover/src/main/java/org/apache/openejb/server/control/StandaloneServer.java
openejb/trunk/openejb/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIContext.java
openejb/trunk/openejb/server/openejb-client/src/test/java/org/apache/openejb/client/JNDIContextTest.java
Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java?rev=1422816&r1=1422815&r2=1422816&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java
(original)
+++
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java
Mon Dec 17 09:37:53 2012
@@ -84,7 +84,8 @@ public class RemoteServer {
properties = props;
props.put("java.naming.factory.initial",
"org.apache.openejb.client.RemoteInitialContextFactory");
- props.put("java.naming.provider.url",
options.get("java.naming.provider.url", "127.0.0.1:4201"));
+ final int port = options.get("ejbd.port", 4201);
+ props.put("java.naming.provider.url",
options.get("java.naming.provider.url", "127.0.0.1:" + port));
props.put("java.naming.security.principal", "testuser");
props.put("java.naming.security.credentials", "testpassword");
}
Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/VmDeploymentManager.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/VmDeploymentManager.java?rev=1422816&r1=1422815&r2=1422816&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/VmDeploymentManager.java
(original)
+++
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/VmDeploymentManager.java
Mon Dec 17 09:37:53 2012
@@ -129,10 +129,12 @@ public class VmDeploymentManager impleme
return deployerLocal;
}
+ @Override
public void release() {
connected = false;
}
+ @Override
public Target[] getTargets() {
if (!connected) throw new IllegalStateException("Deployment manager is
disconnected");
@@ -140,6 +142,7 @@ public class VmDeploymentManager impleme
}
+ @Override
public TargetModuleID[] getAvailableModules(ModuleType moduleType,
Target[] targetList) throws TargetException {
if (!connected) throw new IllegalStateException("Deployment manager is
disconnected");
@@ -175,48 +178,48 @@ public class VmDeploymentManager impleme
InfoObject infoObject = infos.get(0);
if (infoObject instanceof ClientInfo) {
ClientInfo clientInfo = (ClientInfo) infoObject;
- if (appInfo.path.equals(clientInfo.path)) {
+ if (null != appInfo.path &&
appInfo.path.equals(clientInfo.path)) {
// are client modules allowed
if (allowedModuleType != null &&
!allowedModuleType.equals(ModuleType.CAR)) {
return null;
}
- if (clientInfo.moduleId == appInfo.path) {
+ if (null != clientInfo.moduleId &&
clientInfo.moduleId.equals(appInfo.path)) {
return new TargetModuleIDImpl(DEFAULT_TARGET,
clientInfo.moduleId);
}
}
}
if (infoObject instanceof EjbJarInfo) {
EjbJarInfo ejbJarInfo = (EjbJarInfo) infoObject;
- if (appInfo.path.equals(ejbJarInfo.path)) {
+ if (null != appInfo.path &&
appInfo.path.equals(ejbJarInfo.path)) {
// are ejb modules allowed
if (allowedModuleType != null &&
!allowedModuleType.equals(ModuleType.EJB)) {
return null;
}
- if (ejbJarInfo.moduleName == appInfo.appId) {
+ if (null !=
ejbJarInfo.moduleName&&ejbJarInfo.moduleName.equals(appInfo.appId)) {
return new TargetModuleIDImpl(DEFAULT_TARGET,
ejbJarInfo.moduleName);
}
}
}
if (infoObject instanceof ConnectorInfo) {
ConnectorInfo connectorInfo = (ConnectorInfo) infoObject;
- if (appInfo.path.equals(connectorInfo.path)) {
+ if (null !=
appInfo.path&&appInfo.path.equals(connectorInfo.path)) {
// are connector modules allowed
if (allowedModuleType != null &&
!allowedModuleType.equals(ModuleType.RAR)) {
return null;
}
- if (connectorInfo.moduleId == appInfo.path) {
+ if (null !=connectorInfo.moduleId&&
connectorInfo.moduleId.equals(appInfo.path)) {
return new TargetModuleIDImpl(DEFAULT_TARGET,
connectorInfo.moduleId);
}
}
}
if (infoObject instanceof WebAppInfo) {
WebAppInfo webAppInfo = (WebAppInfo) infoObject;
- if (appInfo.path.equals(webAppInfo.path)) {
+ if (null !=appInfo.path&&appInfo.path.equals(webAppInfo.path))
{
// are web app modules allowed
if (allowedModuleType != null &&
!allowedModuleType.equals(ModuleType.WAR)) {
return null;
}
- if (webAppInfo.moduleId == appInfo.path) {
+ if (null
!=webAppInfo.moduleId&&webAppInfo.moduleId.equals(appInfo.path)) {
return new TargetModuleIDImpl(DEFAULT_TARGET,
webAppInfo.moduleId); //todo web module
}
}
@@ -251,6 +254,7 @@ public class VmDeploymentManager impleme
return earModuleId;
}
+ @Override
public TargetModuleID[] getNonRunningModules(ModuleType moduleType,
Target[] targetList) throws TargetException {
if (!connected) throw new IllegalStateException("Deployment manager is
disconnected");
@@ -261,6 +265,7 @@ public class VmDeploymentManager impleme
return new TargetModuleIDImpl[0];
}
+ @Override
public TargetModuleID[] getRunningModules(ModuleType moduleType, Target[]
targetList) throws TargetException {
if (!connected) throw new IllegalStateException("Deployment manager is
disconnected");
@@ -272,6 +277,7 @@ public class VmDeploymentManager impleme
return targetModuleIds.toArray(new
TargetModuleID[targetModuleIds.size()]);
}
+ @Override
public ProgressObject distribute(Target[] targetList, File moduleFile,
File planFile) {
if (!connected) throw new IllegalStateException("Deployment manager is
disconnected");
@@ -289,10 +295,10 @@ public class VmDeploymentManager impleme
}
}
- ProgressObject progressObject = deploy(targetList, properties);
- return progressObject;
+ return deploy(targetList, properties);
}
+ @Override
public ProgressObject distribute(Target[] targetList, InputStream
moduleStream, InputStream planStream) {
if (!connected) throw new IllegalStateException("Deployment manager is
disconnected");
@@ -315,8 +321,7 @@ public class VmDeploymentManager impleme
}
}
- ProgressObject progressObject = deploy(targetList, properties);
- return progressObject;
+ return deploy(targetList, properties);
}
private ProgressObject deploy(Target[] targetList, Properties properties) {
@@ -351,15 +356,15 @@ public class VmDeploymentManager impleme
protected void print(ValidationException[] exceptions, PrintStream out,
int level) {
- for (int i = 0; i < exceptions.length; i++) {
+ for (final ValidationException exception : exceptions) {
out.print(" ");
- out.print(exceptions[i].getPrefix());
+ out.print(exception.getPrefix());
out.print(" ... ");
- if (!(exceptions[i] instanceof ValidationError)) {
- out.print(exceptions[i].getComponentName());
+ if (!(exception instanceof ValidationError)) {
+ out.print(exception.getComponentName());
out.print(": ");
}
- out.println(exceptions[i].getMessage(level));
+ out.println(exception.getMessage(level));
}
}
@@ -371,6 +376,7 @@ public class VmDeploymentManager impleme
return false;
}
+ @Override
public ProgressObject start(TargetModuleID[] moduleIdList) {
if (!connected) throw new IllegalStateException("Deployment manager is
disconnected");
@@ -381,12 +387,14 @@ public class VmDeploymentManager impleme
return new ProgressObjectImpl(CommandType.START, targetModuleIds);
}
+ @Override
public ProgressObject stop(TargetModuleID[] moduleIdList) {
if (!connected) throw new IllegalStateException("Deployment manager is
disconnected");
return new ProgressObjectImpl(CommandType.START,
Collections.<TargetModuleID>emptySet());
}
+ @Override
public ProgressObject undeploy(TargetModuleID[] moduleIdList) {
if (!connected) throw new IllegalStateException("Deployment manager is
disconnected");
@@ -412,54 +420,66 @@ public class VmDeploymentManager impleme
}
}
+ @Override
public boolean isRedeploySupported() {
return false;
}
+ @Override
public ProgressObject redeploy(TargetModuleID[] moduleIDList, File
moduleArchive, File deploymentPlan) {
throw new UnsupportedOperationException("redeploy is not supported");
}
+ @Override
public ProgressObject redeploy(TargetModuleID[] moduleIDList, InputStream
moduleArchive, InputStream deploymentPlan) {
throw new UnsupportedOperationException("redeploy is not supported");
}
+ @Override
public Locale[] getSupportedLocales() {
return new Locale[]{getDefaultLocale()};
}
+ @Override
public Locale getCurrentLocale() {
return getDefaultLocale();
}
+ @Override
public Locale getDefaultLocale() {
return LOCALE;
}
+ @Override
public boolean isLocaleSupported(Locale locale) {
return getDefaultLocale().equals(locale);
}
+ @Override
public void setLocale(Locale locale) {
if (!isLocaleSupported(locale)) {
throw new UnsupportedOperationException("Unsupported locale");
}
}
+ @Override
public DConfigBeanVersionType getDConfigBeanVersion() {
return DCONFIG_BEAN_VERSION;
}
+ @Override
public boolean isDConfigBeanVersionSupported(DConfigBeanVersionType
version) {
return DCONFIG_BEAN_VERSION.equals(version);
}
+ @Override
public void setDConfigBeanVersion(DConfigBeanVersionType version) throws
DConfigBeanVersionUnsupportedException {
if (!isDConfigBeanVersionSupported(version)) {
throw new DConfigBeanVersionUnsupportedException("Version not
supported " + version);
}
}
+ @Override
public DeploymentConfiguration createConfiguration(DeployableObject
deployableObject) throws InvalidModuleException {
throw new InvalidModuleException("Not supported: " +
deployableObject.getType());
}
@@ -472,6 +492,7 @@ public class VmDeploymentManager impleme
}
}
+ @SuppressWarnings("UnusedDeclaration")
public static class TargetImpl implements Target, Comparable, Serializable
{
private static final long serialVersionUID = -7257857314911948377L;
private final String name;
@@ -487,10 +508,12 @@ public class VmDeploymentManager impleme
this.description = description;
}
+ @Override
public String getName() {
return name;
}
+ @Override
public String getDescription() {
return description;
}
@@ -511,6 +534,7 @@ public class VmDeploymentManager impleme
return name.hashCode();
}
+ @Override
public int compareTo(Object o) {
TargetImpl target = (TargetImpl) o;
return name.compareTo(target.name);
@@ -539,14 +563,17 @@ public class VmDeploymentManager impleme
this.webUrl = webUrl;
}
+ @Override
public Target getTarget() {
return target;
}
+ @Override
public String getModuleID() {
return moduleId;
}
+ @Override
public TargetModuleID getParentTargetModuleID() {
return parentTargetModuleId;
}
@@ -556,10 +583,12 @@ public class VmDeploymentManager impleme
parentTargetModuleId.children.add(this);
}
+ @Override
public TargetModuleID[] getChildTargetModuleID() {
return children.toArray(new TargetModuleID[children.size()]);
}
+ @Override
public String getWebURL() {
return webUrl;
}
@@ -584,6 +613,7 @@ public class VmDeploymentManager impleme
return result;
}
+ @Override
public int compareTo(Object o) {
TargetModuleIDImpl targetModuleID = (TargetModuleIDImpl) o;
@@ -613,39 +643,48 @@ public class VmDeploymentManager impleme
event = new ProgressEvent(this, null, deploymentStatus);
}
+ @Override
public synchronized TargetModuleID[] getResultTargetModuleIDs() {
if (targetModuleIds == null) return new TargetModuleID[0];
return targetModuleIds.toArray(new
TargetModuleID[targetModuleIds.size()]);
}
+ @Override
public synchronized DeploymentStatus getDeploymentStatus() {
return deploymentStatus;
}
+ @Override
public ClientConfiguration getClientConfiguration(TargetModuleID id) {
return null;
}
+ @Override
public boolean isCancelSupported() {
return false;
}
+ @Override
public void cancel() throws OperationUnsupportedException {
throw new OperationUnsupportedException("cancel is not supported");
}
+ @Override
public boolean isStopSupported() {
return false;
}
+ @Override
public void stop() throws OperationUnsupportedException {
throw new OperationUnsupportedException("stop is not supported");
}
+ @Override
public void addProgressListener(ProgressListener pol) {
pol.handleProgressEvent(event);
}
+ @Override
public void removeProgressListener(ProgressListener pol) {
}
@@ -671,30 +710,37 @@ public class VmDeploymentManager impleme
this.message = writer.toString();
}
+ @Override
public CommandType getCommand() {
return command;
}
+ @Override
public ActionType getAction() {
return ActionType.EXECUTE;
}
+ @Override
public String getMessage() {
return message;
}
+ @Override
public StateType getState() {
return state;
}
+ @Override
public boolean isRunning() {
return StateType.RUNNING.equals(state);
}
+ @Override
public boolean isCompleted() {
return StateType.COMPLETED.equals(state);
}
+ @Override
public boolean isFailed() {
return StateType.FAILED.equals(state);
}
Modified:
openejb/trunk/openejb/examples/telephone-stateful/src/main/java/org/superbiz/telephone/TelephoneBean.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/telephone-stateful/src/main/java/org/superbiz/telephone/TelephoneBean.java?rev=1422816&r1=1422815&r2=1422816&view=diff
==============================================================================
---
openejb/trunk/openejb/examples/telephone-stateful/src/main/java/org/superbiz/telephone/TelephoneBean.java
(original)
+++
openejb/trunk/openejb/examples/telephone-stateful/src/main/java/org/superbiz/telephone/TelephoneBean.java
Mon Dec 17 09:37:53 2012
@@ -38,18 +38,20 @@ public class TelephoneBean implements Te
"You don't say!",
};
- private List<String> conversation = new ArrayList<String>();
+ private final List<String> conversation = new ArrayList<String>();
- public void speak(String words) {
+ @Override
+ public void speak(final String words) {
conversation.add(words);
}
+ @Override
public String listen() {
if (conversation.size() == 0) {
return "Nothing has been said";
}
- String lastThingSaid = conversation.get(conversation.size() - 1);
+ final String lastThingSaid = conversation.get(conversation.size() - 1);
return answers[Math.abs(lastThingSaid.hashCode()) % answers.length];
}
}
Modified:
openejb/trunk/openejb/examples/telephone-stateful/src/test/java/org/superbiz/telephone/TelephoneTest.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/telephone-stateful/src/test/java/org/superbiz/telephone/TelephoneTest.java?rev=1422816&r1=1422815&r2=1422816&view=diff
==============================================================================
---
openejb/trunk/openejb/examples/telephone-stateful/src/test/java/org/superbiz/telephone/TelephoneTest.java
(original)
+++
openejb/trunk/openejb/examples/telephone-stateful/src/test/java/org/superbiz/telephone/TelephoneTest.java
Mon Dec 17 09:37:53 2012
@@ -29,8 +29,9 @@ public class TelephoneTest extends TestC
//START SNIPPET: setup
+ @Override
protected void setUp() throws Exception {
- Properties properties = new Properties();
+ final Properties properties = new Properties();
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.core.LocalInitialContextFactory");
properties.setProperty("openejb.embedded.remotable", "true");
// Uncomment these properties to change the defaults
@@ -52,23 +53,21 @@ public class TelephoneTest extends TestC
//START SNIPPET: localcontext
public void testTalkOverLocalNetwork() throws Exception {
- Properties properties = new Properties();
+ final Properties properties = new Properties();
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.core.LocalInitialContextFactory");
- InitialContext localContext = new InitialContext(properties);
+ final InitialContext localContext = new InitialContext(properties);
- Telephone telephone = (Telephone)
localContext.lookup("TelephoneBeanRemote");
+ final Telephone telephone = (Telephone)
localContext.lookup("TelephoneBeanRemote");
telephone.speak("Did you know I am talking directly through the
embedded container?");
assertEquals("Interesting.", telephone.listen());
-
telephone.speak("Yep, I'm using the bean's remote interface but since
the ejb container is embedded " +
- "in the same vm I'm just using the
LocalInitialContextFactory.");
+ "in the same vm I'm just using the
LocalInitialContextFactory.");
assertEquals("Really?", telephone.listen());
-
telephone.speak("Right, you really only have to use the
RemoteInitialContextFactory if you're in a different vm.");
assertEquals("Oh, of course.", telephone.listen());
@@ -82,28 +81,25 @@ public class TelephoneTest extends TestC
*/
//START SNIPPET: remotecontext
public void testTalkOverRemoteNetwork() throws Exception {
- Properties properties = new Properties();
+ final Properties properties = new Properties();
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.RemoteInitialContextFactory");
- properties.setProperty(Context.PROVIDER_URL, "ejbd://localhost:4201");
- InitialContext remoteContext = new InitialContext(properties);
+ properties.setProperty(Context.PROVIDER_URL, "ejbd://localhost:" +
Integer.parseInt(System.getProperty("ejbd.port", "4201")));
+ final InitialContext remoteContext = new InitialContext(properties);
- Telephone telephone = (Telephone)
remoteContext.lookup("TelephoneBeanRemote");
+ final Telephone telephone = (Telephone)
remoteContext.lookup("TelephoneBeanRemote");
telephone.speak("Is this a local call?");
assertEquals("No.", telephone.listen());
-
telephone.speak("This would be a lot cooler if I was connecting from
another VM then, huh?");
assertEquals("I wondered about that.", telephone.listen());
-
telephone.speak("I suppose I should hangup and call back over the
LocalInitialContextFactory.");
assertEquals("Good idea.", telephone.listen());
-
telephone.speak("I'll remember this though in case I ever have to call
you accross a network.");
assertEquals("Definitely.", telephone.listen());
Modified:
openejb/trunk/openejb/itests/failover/src/main/java/org/apache/openejb/server/control/StandaloneServer.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/itests/failover/src/main/java/org/apache/openejb/server/control/StandaloneServer.java?rev=1422816&r1=1422815&r2=1422816&view=diff
==============================================================================
---
openejb/trunk/openejb/itests/failover/src/main/java/org/apache/openejb/server/control/StandaloneServer.java
(original)
+++
openejb/trunk/openejb/itests/failover/src/main/java/org/apache/openejb/server/control/StandaloneServer.java
Mon Dec 17 09:37:53 2012
@@ -467,7 +467,7 @@ public class StandaloneServer {
final ServerService ejbd = getServerService("ejbd");
int port = ejbd.getPort();
- if (port == 0) port = 4201;
+ if (port == 0) port = Integer.parseInt(System.getProperty("ejbd.port",
"4201"));
String host = ejbd.getBind();
if (host == null || host.length() == 0) host = "localhost";
Modified:
openejb/trunk/openejb/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIContext.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIContext.java?rev=1422816&r1=1422815&r2=1422816&view=diff
==============================================================================
---
openejb/trunk/openejb/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIContext.java
(original)
+++
openejb/trunk/openejb/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIContext.java
Mon Dec 17 09:37:53 2012
@@ -19,21 +19,8 @@ package org.apache.openejb.client;
import org.apache.openejb.client.event.RemoteInitialContextCreated;
import org.omg.CORBA.ORB;
-import javax.naming.AuthenticationException;
-import javax.naming.Binding;
-import javax.naming.CompoundName;
-import javax.naming.ConfigurationException;
+import javax.naming.*;
import javax.naming.Context;
-import javax.naming.InvalidNameException;
-import javax.naming.Name;
-import javax.naming.NameClassPair;
-import javax.naming.NameNotFoundException;
-import javax.naming.NameParser;
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
-import javax.naming.OperationNotSupportedException;
-import javax.naming.Reference;
-import javax.naming.ServiceUnavailableException;
import javax.naming.spi.InitialContextFactory;
import javax.naming.spi.NamingManager;
import javax.sql.DataSource;
@@ -47,9 +34,10 @@ import java.util.Hashtable;
import java.util.List;
import java.util.Properties;
-/**
+/**
* @version $Rev$ $Date$
*/
+@SuppressWarnings("UseOfObsoleteCollectionType")
public class JNDIContext implements InitialContextFactory, Context {
public static final String DEFAULT_PROVIDER_URL = "ejbd://localhost:4201";
@@ -67,7 +55,7 @@ public class JNDIContext implements Init
/*
* A neater version of clone
*/
- public JNDIContext(JNDIContext that) {
+ public JNDIContext(final JNDIContext that) {
this.tail = that.tail;
this.server = that.server;
this.client = that.client;
@@ -76,10 +64,10 @@ public class JNDIContext implements Init
this.clientIdentity = that.clientIdentity;
}
- private JNDIResponse request(JNDIRequest req) throws Exception {
+ private JNDIResponse request(final JNDIRequest req) throws Exception {
req.setServerHash(server.buildHash());
-
- JNDIResponse response = new JNDIResponse();
+
+ final JNDIResponse response = new JNDIResponse();
Client.request(req, response, server);
if (null != response.getServer()) {
server.merge(response.getServer());
@@ -87,19 +75,20 @@ public class JNDIContext implements Init
return response;
}
- protected AuthenticationResponse
requestAuthorization(AuthenticationRequest req) throws RemoteException {
+ protected AuthenticationResponse requestAuthorization(final
AuthenticationRequest req) throws RemoteException {
return (AuthenticationResponse) Client.request(req, new
AuthenticationResponse(), server);
}
- public Context getInitialContext(Hashtable environment) throws
NamingException {
+ @Override
+ public Context getInitialContext(final Hashtable environment) throws
NamingException {
if (environment == null) {
throw new NamingException("Invalid argument, hashtable cannot be
null.");
} else {
env = (Hashtable) environment.clone();
}
- String userID = (String) env.get(Context.SECURITY_PRINCIPAL);
- String psswrd = (String) env.get(Context.SECURITY_CREDENTIALS);
+ final String userID = (String) env.get(Context.SECURITY_PRINCIPAL);
+ final String psswrd = (String) env.get(Context.SECURITY_CREDENTIALS);
String providerUrl = (String) env.get(Context.PROVIDER_URL);
moduleId = (String) env.get("openejb.client.moduleId");
@@ -133,7 +122,7 @@ public class JNDIContext implements Init
/**
* Add missing parts - expected only part of the required providerUrl
- *
+ * <p/>
* TODO: Move the check to a place where it really belongs -
ConnectionManager, ConnectionFactory or such
* This method (class in general) doesn't really know what is required as
far as connection details go
* Assuming that java.net.URI or java.net.URL are going to be used is
overly stated
@@ -142,15 +131,19 @@ public class JNDIContext implements Init
if (providerUrl == null || providerUrl.length() == 0) {
providerUrl = DEFAULT_PROVIDER_URL;
} else {
- int colonIndex = providerUrl.indexOf(":");
- int slashesIndex = providerUrl.indexOf("//");
+
+ final int colonIndex = providerUrl.indexOf(":");
+ final int slashesIndex = providerUrl.indexOf("//");
+
+ final int port = Integer.parseInt(System.getProperty("ejbd.port",
"4201"));
+
if (colonIndex == -1 && slashesIndex == -1) { // hostname or ip
address only
- providerUrl = "ejbd://" + providerUrl + ":4201";
+ providerUrl = "ejbd://" + providerUrl + ":" + port;
} else if (colonIndex == -1) {
- URI providerUri = new URI(providerUrl);
- String scheme = providerUri.getScheme();
+ final URI providerUri = new URI(providerUrl);
+ final String scheme = providerUri.getScheme();
if (!(scheme.equals("http") || scheme.equals("https"))) {
- providerUrl = providerUrl + ":4201";
+ providerUrl = providerUrl + ":" + port;
}
} else if (slashesIndex == -1) {
providerUrl = "ejbd://" + providerUrl;
@@ -158,14 +151,14 @@ public class JNDIContext implements Init
}
return providerUrl;
}
-
- public void authenticate(String userID, String psswrd) throws
AuthenticationException {
+
+ public void authenticate(final String userID, final String psswrd) throws
AuthenticationException {
// May be null
- String realmName = (String)
env.get("openejb.authentication.realmName");
+ final String realmName = (String)
env.get("openejb.authentication.realmName");
- AuthenticationRequest req = new AuthenticationRequest(realmName,
userID, psswrd);
- AuthenticationResponse res = null;
+ final AuthenticationRequest req = new AuthenticationRequest(realmName,
userID, psswrd);
+ final AuthenticationResponse res;
try {
res = requestAuthorization(req);
@@ -186,31 +179,36 @@ public class JNDIContext implements Init
}
}
- public EJBHomeProxy createEJBHomeProxy(EJBMetaDataImpl ejbData) {
- EJBHomeHandler handler = EJBHomeHandler.createEJBHomeHandler(ejbData,
server, client);
- EJBHomeProxy proxy = handler.createEJBHomeProxy();
+ public EJBHomeProxy createEJBHomeProxy(final EJBMetaDataImpl ejbData) {
+ final EJBHomeHandler handler =
EJBHomeHandler.createEJBHomeHandler(ejbData, server, client);
+ final EJBHomeProxy proxy = handler.createEJBHomeProxy();
handler.ejb.ejbHomeProxy = proxy;
return proxy;
}
- private Object createBusinessObject(Object result) {
- EJBMetaDataImpl ejb = (EJBMetaDataImpl) result;
- Object primaryKey = ejb.getPrimaryKey();
+ private Object createBusinessObject(final Object result) {
+ final EJBMetaDataImpl ejb = (EJBMetaDataImpl) result;
+ final Object primaryKey = ejb.getPrimaryKey();
- EJBObjectHandler handler =
EJBObjectHandler.createEJBObjectHandler(ejb, server, client, primaryKey);
+ final EJBObjectHandler handler =
EJBObjectHandler.createEJBObjectHandler(ejb, server, client, primaryKey);
return handler.createEJBObjectProxy();
}
+ @Override
public Object lookup(String name) throws NamingException {
- if (name == null) throw new InvalidNameException("The name cannot be
null");
- else if (name.equals("")) return new JNDIContext(this);
- else if (name.startsWith("java:")) name = name.replaceFirst("^java:",
"");
- else if (!name.startsWith("/")) name = tail + name;
+ if (name == null)
+ throw new InvalidNameException("The name cannot be null");
+ else if (name.equals(""))
+ return new JNDIContext(this);
+ else if (name.startsWith("java:"))
+ name = name.replaceFirst("^java:", "");
+ else if (!name.startsWith("/"))
+ name = tail + name;
- String prop = name.replaceFirst("comp/env/", "");
+ final String prop = name.replaceFirst("comp/env/", "");
String value = System.getProperty(prop);
if (value != null) {
return parseEntry(prop, value);
@@ -220,12 +218,12 @@ public class JNDIContext implements Init
return getDefaultOrb();
}
- JNDIRequest req = new JNDIRequest();
+ final JNDIRequest req = new JNDIRequest();
req.setRequestMethod(RequestMethodCode.JNDI_LOOKUP);
req.setRequestString(name);
req.setModuleId(moduleId);
- JNDIResponse res = null;
+ final JNDIResponse res;
try {
res = request(req);
} catch (Exception e) {
@@ -250,8 +248,9 @@ public class JNDIContext implements Init
return res.getResult();
case ResponseCodes.JNDI_CONTEXT:
- JNDIContext subCtx = new JNDIContext(this);
- if (!name.endsWith("/")) name += '/';
+ final JNDIContext subCtx = new JNDIContext(this);
+ if (!name.endsWith("/"))
+ name += '/';
subCtx.tail = name;
return subCtx;
@@ -262,7 +261,7 @@ public class JNDIContext implements Init
return createWebservice((WsMetaData) res.getResult());
case ResponseCodes.JNDI_RESOURCE:
- String type = (String) res.getResult();
+ final String type = (String) res.getResult();
value = System.getProperty("Resource/" + type);
if (value == null) {
return null;
@@ -270,7 +269,7 @@ public class JNDIContext implements Init
return parseEntry(prop, value);
case ResponseCodes.JNDI_REFERENCE:
- Reference ref = (Reference)res.getResult();
+ final Reference ref = (Reference) res.getResult();
try {
return NamingManager.getObjectInstance(ref,
getNameParser(name).parse(name), this, env);
} catch (Exception e) {
@@ -281,7 +280,7 @@ public class JNDIContext implements Init
throw new NameNotFoundException(name + " does not exist in the
system. Check that the app was successfully deployed.");
case ResponseCodes.JNDI_NAMING_EXCEPTION:
- Throwable throwable = ((ThrowableArtifact)
res.getResult()).getThrowable();
+ final Throwable throwable = ((ThrowableArtifact)
res.getResult()).getThrowable();
if (throwable instanceof NamingException) {
throw (NamingException) throwable;
}
@@ -298,10 +297,10 @@ public class JNDIContext implements Init
}
}
- private Object parseEntry(String name, String value) throws
NamingException {
+ private Object parseEntry(final String name, String value) throws
NamingException {
try {
URI uri = new URI(value);
- String scheme = uri.getScheme();
+ final String scheme = uri.getScheme();
if (scheme.equals("link")) {
value = System.getProperty(uri.getSchemeSpecificPart());
if (value == null) {
@@ -310,8 +309,8 @@ public class JNDIContext implements Init
return parseEntry(name, value);
} else if (scheme.equals("datasource")) {
uri = new URI(uri.getSchemeSpecificPart());
- String driver = uri.getScheme();
- String url = uri.getSchemeSpecificPart();
+ final String driver = uri.getScheme();
+ final String url = uri.getSchemeSpecificPart();
return new ClientDataSource(driver, url, null, null);
} else if (scheme.equals("connectionfactory")) {
return build(uri);
@@ -333,11 +332,13 @@ public class JNDIContext implements Init
private Object build(final URI inputUri) throws URISyntaxException {
final URI uri = new URI(inputUri.getSchemeSpecificPart());
- String driver = uri.getScheme();
- String url = uri.getSchemeSpecificPart();
- ClassLoader classLoader =
Thread.currentThread().getContextClassLoader();
- if (classLoader == null) getClass().getClassLoader();
- if (classLoader == null) ClassLoader.getSystemClassLoader();
+ final String driver = uri.getScheme();
+ final String url = uri.getSchemeSpecificPart();
+ final ClassLoader classLoader =
Thread.currentThread().getContextClassLoader();
+ if (classLoader == null)
+ getClass().getClassLoader();
+ if (classLoader == null)
+ ClassLoader.getSystemClassLoader();
try {
final Class<?> clazz = Class.forName(driver, true, classLoader);
final Constructor<?> constructor =
clazz.getConstructor(String.class);
@@ -347,11 +348,11 @@ public class JNDIContext implements Init
}
}
- private DataSource createDataSource(DataSourceMetaData dataSourceMetaData)
{
+ private DataSource createDataSource(final DataSourceMetaData
dataSourceMetaData) {
return new ClientDataSource(dataSourceMetaData);
}
- private Object createWebservice(WsMetaData webserviceMetaData) throws
NamingException {
+ private Object createWebservice(final WsMetaData webserviceMetaData)
throws NamingException {
try {
return webserviceMetaData.createWebservice();
} catch (Exception e) {
@@ -363,19 +364,25 @@ public class JNDIContext implements Init
return ORB.init();
}
- public Object lookup(Name name) throws NamingException {
+ @Override
+ public Object lookup(final Name name) throws NamingException {
return lookup(name.toString());
}
+ @SuppressWarnings("unchecked")
+ @Override
public NamingEnumeration<NameClassPair> list(String name) throws
NamingException {
- if (name == null) throw new InvalidNameException("The name cannot be
null");
- else if (name.startsWith("java:")) name = name.replaceFirst("^java:",
"");
- else if (!name.startsWith("/")) name = tail + name;
+ if (name == null)
+ throw new InvalidNameException("The name cannot be null");
+ else if (name.startsWith("java:"))
+ name = name.replaceFirst("^java:", "");
+ else if (!name.startsWith("/"))
+ name = tail + name;
- JNDIRequest req = new JNDIRequest(RequestMethodCode.JNDI_LIST, name);
+ final JNDIRequest req = new JNDIRequest(RequestMethodCode.JNDI_LIST,
name);
req.setModuleId(moduleId);
- JNDIResponse res = null;
+ final JNDIResponse res;
try {
res = request(req);
} catch (Exception e) {
@@ -398,7 +405,7 @@ public class JNDIContext implements Init
throw new NameNotFoundException(name);
case ResponseCodes.JNDI_NAMING_EXCEPTION:
- Throwable throwable = ((ThrowableArtifact)
res.getResult()).getThrowable();
+ final Throwable throwable = ((ThrowableArtifact)
res.getResult()).getThrowable();
if (throwable instanceof NamingException) {
throw (NamingException) throwable;
}
@@ -413,19 +420,22 @@ public class JNDIContext implements Init
}
- public NamingEnumeration<NameClassPair> list(Name name) throws
NamingException {
+ @Override
+ public NamingEnumeration<NameClassPair> list(final Name name) throws
NamingException {
return list(name.toString());
}
- public NamingEnumeration<Binding> listBindings(String name) throws
NamingException {
- Object o = lookup(name);
+ @SuppressWarnings("unchecked")
+ @Override
+ public NamingEnumeration<Binding> listBindings(final String name) throws
NamingException {
+ final Object o = lookup(name);
if (o instanceof Context) {
- Context context = (Context) o;
- NamingEnumeration<NameClassPair> enumeration = context.list("");
- List<NameClassPair> bindings = new ArrayList<NameClassPair>();
+ final Context context = (Context) o;
+ final NamingEnumeration<NameClassPair> enumeration =
context.list("");
+ final List<NameClassPair> bindings = new
ArrayList<NameClassPair>();
while (enumeration.hasMoreElements()) {
- NameClassPair pair = enumeration.nextElement();
+ final NameClassPair pair = enumeration.nextElement();
bindings.add(new LazyBinding(pair.getName(),
pair.getClassName(), context));
}
@@ -438,140 +448,168 @@ public class JNDIContext implements Init
}
private static class LazyBinding extends Binding {
+
private static final long serialVersionUID = 1L;
private RuntimeException failed;
private Context context;
- public LazyBinding(String name, String className, Context context) {
+ public LazyBinding(final String name, final String className, final
Context context) {
super(name, className, null);
this.context = context;
}
+ @Override
public synchronized Object getObject() {
- if (super.getObject() == null){
- if (failed != null) throw failed;
+ if (super.getObject() == null) {
+ if (failed != null)
+ throw failed;
try {
super.setObject(context.lookup(getName()));
} catch (NamingException e) {
- throw failed = new ClientRuntimeException("Failed to
lazily fetch the binding '"+getName()+"'", e);
+ throw failed = new ClientRuntimeException("Failed to
lazily fetch the binding '" + getName() + "'", e);
}
}
return super.getObject();
}
}
- public NamingEnumeration<Binding> listBindings(Name name) throws
NamingException{
+ @Override
+ public NamingEnumeration<Binding> listBindings(final Name name) throws
NamingException {
return listBindings(name.toString());
}
- public Object lookupLink(String name) throws NamingException {
+ @Override
+ public Object lookupLink(final String name) throws NamingException {
return lookup(name);
}
- public Object lookupLink(Name name) throws NamingException {
+ @Override
+ public Object lookupLink(final Name name) throws NamingException {
return lookupLink(name.toString());
}
- public NameParser getNameParser(String name) throws NamingException {
+ @Override
+ public NameParser getNameParser(final String name) throws NamingException {
return new SimpleNameParser();
}
- public NameParser getNameParser(Name name) throws NamingException {
+ @Override
+ public NameParser getNameParser(final Name name) throws NamingException {
return new SimpleNameParser();
}
- public String composeName(String name, String prefix) throws
NamingException {
+ @Override
+ public String composeName(final String name, final String prefix) throws
NamingException {
throw new OperationNotSupportedException("TODO: Needs to be
implemented");
}
- public Name composeName(Name name, Name prefix) throws NamingException {
+ @Override
+ public Name composeName(final Name name, final Name prefix) throws
NamingException {
throw new OperationNotSupportedException("TODO: Needs to be
implemented");
}
- public Object addToEnvironment(String key, Object value) throws
NamingException {
+ @SuppressWarnings("unchecked")
+ @Override
+ public Object addToEnvironment(final String key, final Object value)
throws NamingException {
return env.put(key, value);
}
- public Object removeFromEnvironment(String key) throws NamingException {
+ @Override
+ public Object removeFromEnvironment(final String key) throws
NamingException {
return env.remove(key);
}
+ @Override
public Hashtable getEnvironment() throws NamingException {
return (Hashtable) env.clone();
}
+ @Override
public String getNameInNamespace() throws NamingException {
return "";
}
+ @Override
public void close() throws NamingException {
}
- public void bind(String name, Object obj) throws NamingException {
+ @Override
+ public void bind(final String name, final Object obj) throws
NamingException {
throw new OperationNotSupportedException();
}
- public void bind(Name name, Object obj) throws NamingException {
+ @Override
+ public void bind(final Name name, final Object obj) throws NamingException
{
bind(name.toString(), obj);
}
- public void rebind(String name, Object obj) throws NamingException {
+ @Override
+ public void rebind(final String name, final Object obj) throws
NamingException {
throw new OperationNotSupportedException();
}
- public void rebind(Name name, Object obj) throws NamingException {
+ @Override
+ public void rebind(final Name name, final Object obj) throws
NamingException {
rebind(name.toString(), obj);
}
- public void unbind(String name) throws NamingException {
+ @Override
+ public void unbind(final String name) throws NamingException {
throw new OperationNotSupportedException();
}
- public void unbind(Name name) throws NamingException {
+ @Override
+ public void unbind(final Name name) throws NamingException {
unbind(name.toString());
}
- public void rename(String oldname, String newname) throws NamingException {
+ @Override
+ public void rename(final String oldname, final String newname) throws
NamingException {
throw new OperationNotSupportedException();
}
- public void rename(Name oldname, Name newname) throws NamingException {
+ @Override
+ public void rename(final Name oldname, final Name newname) throws
NamingException {
rename(oldname.toString(), newname.toString());
}
- public void destroySubcontext(String name) throws NamingException {
+ @Override
+ public void destroySubcontext(final String name) throws NamingException {
throw new OperationNotSupportedException();
}
- public void destroySubcontext(Name name) throws NamingException {
+ @Override
+ public void destroySubcontext(final Name name) throws NamingException {
destroySubcontext(name.toString());
}
- public Context createSubcontext(String name) throws NamingException {
+ @Override
+ public Context createSubcontext(final String name) throws NamingException {
throw new OperationNotSupportedException();
}
- public Context createSubcontext(Name name) throws NamingException {
+ @Override
+ public Context createSubcontext(final Name name) throws NamingException {
return createSubcontext(name.toString());
}
private static final class SimpleNameParser implements NameParser {
- private static final Properties PARSER_PROPERTIES = new Properties();
- static {
- PARSER_PROPERTIES.put("jndi.syntax.direction", "left_to_right");
- PARSER_PROPERTIES.put("jndi.syntax.separator", "/");
- }
+ private static final Properties PARSER_PROPERTIES = new Properties();
+ static {
+ PARSER_PROPERTIES.put("jndi.syntax.direction", "left_to_right");
+ PARSER_PROPERTIES.put("jndi.syntax.separator", "/");
+ }
- private SimpleNameParser() {
- }
-
- public Name parse(String name) throws NamingException {
- return new CompoundName(name, PARSER_PROPERTIES);
- }
- }
+ private SimpleNameParser() {
+ }
+ @Override
+ public Name parse(final String name) throws NamingException {
+ return new CompoundName(name, PARSER_PROPERTIES);
+ }
+ }
}
Modified:
openejb/trunk/openejb/server/openejb-client/src/test/java/org/apache/openejb/client/JNDIContextTest.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-client/src/test/java/org/apache/openejb/client/JNDIContextTest.java?rev=1422816&r1=1422815&r2=1422816&view=diff
==============================================================================
---
openejb/trunk/openejb/server/openejb-client/src/test/java/org/apache/openejb/client/JNDIContextTest.java
(original)
+++
openejb/trunk/openejb/server/openejb-client/src/test/java/org/apache/openejb/client/JNDIContextTest.java
Mon Dec 17 09:37:53 2012
@@ -16,59 +16,62 @@
*/
package org.apache.openejb.client;
-import java.util.Hashtable;
+import org.junit.Test;
import javax.naming.Context;
-
-import org.junit.Test;
+import java.util.Hashtable;
/**
* @version $Rev$ $Date$
*/
+@SuppressWarnings("UseOfObsoleteCollectionType")
public class JNDIContextTest {
@Test
public void testGetInitialContext() throws Exception {
- JNDIContext jndiContext = new JNDIContext();
- Hashtable<String, String> env = new Hashtable<String, String>();
- assertEquals(jndiContext, "ejbd://localhost:4201");
+ final int port = Integer.parseInt(System.getProperty("ejbd.port",
"4201"));
+
+ final JNDIContext jndiContext = new JNDIContext();
+ final Hashtable<String, String> env = new Hashtable<String, String>();
+
+ assertEquals(jndiContext, "ejbd://localhost:" + port);
assertEquals(jndiContext, "http://localhost");
- assertEquals(jndiContext, "anything://localhost:4201");
+ assertEquals(jndiContext, "anything://localhost:" + port);
- assertEquals(jndiContext, "//localhost:4201");
+ assertEquals(jndiContext, "//localhost:" + port);
- assertEquals(jndiContext, "localhost", "ejbd://localhost:4201");
+ assertEquals(jndiContext, "localhost", "ejbd://localhost:" + port);
- assertEquals(jndiContext, "localhost:4201", "ejbd://localhost:4201");
+ assertEquals(jndiContext, "localhost:" + port, "ejbd://localhost:" +
port);
- assertEquals(jndiContext, "", "ejbd://localhost:4201");
+ assertEquals(jndiContext, "", "ejbd://localhost:" + port);
- assertEquals(jndiContext, "ejbd://127.0.0.1:4201");
+ assertEquals(jndiContext, "ejbd://127.0.0.1:" + port);
assertEquals(jndiContext, "http://127.0.0.1");
- assertEquals(jndiContext, "anything://127.0.0.1:4201");
+ assertEquals(jndiContext, "anything://127.0.0.1:" + port);
- assertEquals(jndiContext, "//127.0.0.1:4201");
+ assertEquals(jndiContext, "//127.0.0.1:" + port);
- assertEquals(jndiContext, "127.0.0.1", "ejbd://127.0.0.1:4201");
+ assertEquals(jndiContext, "127.0.0.1", "ejbd://127.0.0.1:" + port);
- assertEquals(jndiContext, "127.0.0.1:4201", "ejbd://127.0.0.1:4201");
+ assertEquals(jndiContext, "127.0.0.1:" + port, "ejbd://127.0.0.1:" +
port);
}
- private void assertEquals(JNDIContext jndiContext, String providerUrl)
throws Exception {
+ private void assertEquals(final JNDIContext jndiContext, final String
providerUrl) throws Exception {
assertEquals(jndiContext, providerUrl, providerUrl);
}
- private void assertEquals(JNDIContext jndiContext, String providerUrl,
String expectedProviderUrl) throws Exception {
- Hashtable<String, String> env = new Hashtable<String, String>();
+ private void assertEquals(final JNDIContext jndiContext, final String
providerUrl, final String expectedProviderUrl) throws Exception {
+ final Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.PROVIDER_URL, providerUrl);
- JNDIContext ctx = (JNDIContext) jndiContext.getInitialContext(env);
- String actualProviderUrl = ctx.addMissingParts(providerUrl);
+ final JNDIContext ctx = (JNDIContext)
jndiContext.getInitialContext(env);
+ final String actualProviderUrl = ctx.addMissingParts(providerUrl);
assert expectedProviderUrl.equals(actualProviderUrl) : "Expected " +
expectedProviderUrl + " but was " + actualProviderUrl;
}
}