You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jl...@apache.org on 2008/03/07 21:58:21 UTC
svn commit: r634818 - in /openejb/trunk/openejb3/server/openejb-client/src:
main/java/org/apache/openejb/client/JNDIContext.java
test/java/org/apache/openejb/client/JNDIContextTest.java
Author: jlaskowski
Date: Fri Mar 7 12:58:21 2008
New Revision: 634818
URL: http://svn.apache.org/viewvc?rev=634818&view=rev
Log:
OPENEJB-607 Cannot access server(s): null:-1 when InitialContext.PROVIDER_URL is hostname not IP address
Added:
openejb/trunk/openejb3/server/openejb-client/src/test/java/org/apache/openejb/client/JNDIContextTest.java (with props)
Modified:
openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIContext.java
Modified: openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIContext.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIContext.java?rev=634818&r1=634817&r2=634818&view=diff
==============================================================================
--- openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIContext.java (original)
+++ openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIContext.java Fri Mar 7 12:58:21 2008
@@ -19,9 +19,11 @@
import org.omg.CORBA.ORB;
import java.io.Serializable;
+import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.ConnectException;
+import java.net.URL;
import java.rmi.RemoteException;
import java.util.Hashtable;
import java.util.Properties;
@@ -49,6 +51,8 @@
*/
public class JNDIContext implements Serializable, InitialContextFactory, Context {
+ public static final String DEFAULT_PROVIDER_URL = "ejbd://localhost:4201";
+
private static final long serialVersionUID = 1L;
private transient String tail = "/";
@@ -110,26 +114,35 @@
String userID = (String) env.get(Context.SECURITY_PRINCIPAL);
String psswrd = (String) env.get(Context.SECURITY_CREDENTIALS);
- Object serverURI = env.get(Context.PROVIDER_URL);
+ String serverURI = (String) env.get(Context.PROVIDER_URL);
moduleId = (String) env.get("openejb.client.moduleId");
- if (serverURI == null) serverURI = "ejbd://localhost:4201";
- // if (userID == null) userID = "anonymous";
- // if (psswrd == null) psswrd = "anon";
-
- String uriString = (String) serverURI;
- URI location = null;
+ URI location;
try {
- location = new URI(uriString);
- } catch (Exception e) {
- if (uriString.indexOf("://") == -1) {
- try {
- location = new URI("foo://" + uriString);
- } catch (URISyntaxException giveUp) {
- // Was worth a try, let's give up and throw the original exception.
- throw (ConfigurationException) new ConfigurationException("Context property value error for " + Context.PROVIDER_URL + " :" + e.getMessage()).initCause(e);
+ if (serverURI == null || serverURI.length() == 0) {
+ serverURI = DEFAULT_PROVIDER_URL;
+ } else {
+ URI serverURL = new URI(serverURI);
+
+ // very first check per URI's rules has passed
+ // let's check for common "mistakes"
+ // TODO: Move the check to a place where it really belongs - ConnectionManager, ConnectionFactory or such
+ // This class doesn't really know what is required as far as connection details go
+
+ int colonIndex = serverURI.indexOf(":");
+ int slashesIndex = serverURI.indexOf("//");
+ // hostname only
+ if (colonIndex == -1 && slashesIndex == -1) {
+ serverURI = "ejbd://" + serverURI + ":4201";
+ } else if (colonIndex == -1) {
+ serverURI = serverURI + ":4201";
+ } else if (slashesIndex == -1) {
+ serverURI = "ejbd://" + serverURI;
}
}
+ location = new URI(serverURI);
+ } catch (URISyntaxException e) {
+ throw (ConfigurationException) new ConfigurationException("Property value for " + Context.PROVIDER_URL + " invalid: " + serverURI + ":" + e.getMessage()).initCause(e);
}
this.server = new ServerMetaData(location);
//TODO:1: Either aggressively initiate authentication or wait for the
@@ -142,7 +155,7 @@
return this;
}
-
+
public void authenticate(String userID, String psswrd) throws AuthenticationException {
// May be null
Added: openejb/trunk/openejb3/server/openejb-client/src/test/java/org/apache/openejb/client/JNDIContextTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-client/src/test/java/org/apache/openejb/client/JNDIContextTest.java?rev=634818&view=auto
==============================================================================
--- openejb/trunk/openejb3/server/openejb-client/src/test/java/org/apache/openejb/client/JNDIContextTest.java (added)
+++ openejb/trunk/openejb3/server/openejb-client/src/test/java/org/apache/openejb/client/JNDIContextTest.java Fri Mar 7 12:58:21 2008
@@ -0,0 +1,65 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.client;
+
+import static org.junit.Assert.*;
+
+import java.util.Hashtable;
+
+import javax.naming.ConfigurationException;
+import javax.naming.Context;
+
+import org.junit.Test;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JNDIContextTest {
+
+ @Test
+ public void testGetInitialContext() throws Exception {
+ JNDIContext jndiContext = new JNDIContext();
+ Hashtable<String, String> env = new Hashtable<String, String>();
+
+ env.put(Context.PROVIDER_URL, "ejbd://localhost:4201");
+ jndiContext.getInitialContext(env);
+
+ env.put(Context.PROVIDER_URL, "anything://localhost:4201");
+ jndiContext.getInitialContext(env);
+
+ env.put(Context.PROVIDER_URL, "//localhost:4201");
+ jndiContext.getInitialContext(env);
+
+ env.put(Context.PROVIDER_URL, "localhost:4201");
+ jndiContext.getInitialContext(env);
+
+ env.put(Context.PROVIDER_URL, "localhost");
+ jndiContext.getInitialContext(env);
+
+ env.put(Context.PROVIDER_URL, "");
+ jndiContext.getInitialContext(env);
+
+ try {
+ env.put(Context.PROVIDER_URL, "ejbd:");
+ jndiContext.getInitialContext(env);
+ fail("ConfigurationException expected due to malformed " + Context.PROVIDER_URL);
+ } catch (ConfigurationException expected) {
+ // do nothing
+ }
+ }
+
+}
Propchange: openejb/trunk/openejb3/server/openejb-client/src/test/java/org/apache/openejb/client/JNDIContextTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: openejb/trunk/openejb3/server/openejb-client/src/test/java/org/apache/openejb/client/JNDIContextTest.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: openejb/trunk/openejb3/server/openejb-client/src/test/java/org/apache/openejb/client/JNDIContextTest.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: openejb/trunk/openejb3/server/openejb-client/src/test/java/org/apache/openejb/client/JNDIContextTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Re: Client connection URLs (Re: svn commit: r634818)
Posted by Dain Sundstrom <da...@iq80.com>.
I checked in a temporary fix to this, so I could continue my tests on
Windows.
-dain
On Mar 8, 2008, at 3:07 AM, Jacek Laskowski wrote:
> On Sat, Mar 8, 2008 at 1:04 AM, David Blevins
> <da...@visi.com> wrote:
>
>> On Mar 7, 2008, at 12:58 PM, jlaskowski@apache.org wrote:
>>
>>> + // TODO: Move the check to a place where it really
>>> belongs - ConnectionManager, ConnectionFactory or such
>>> + // This class doesn't really know what is
>>> required as far as connection details go
>>
>> Definitely. On this note, we should only default the port to 4201 if
>> the protocol is ejbd. Http and https are supported and each has it's
>> own default port.
>>
>>>
>>> +
>>> + int colonIndex = serverURI.indexOf(":");
>>> + int slashesIndex = serverURI.indexOf("//");
>>> + // hostname only
>>> + if (colonIndex == -1 && slashesIndex == -1) {
>>> + serverURI = "ejbd://" + serverURI + ":4201";
>>> + } else if (colonIndex == -1) {
>>> + serverURI = serverURI + ":4201";
>>> + } else if (slashesIndex == -1) {
>>> + serverURI = "ejbd://" + serverURI;
>>> }
>>
>> We could likely keep the part that defaults the protocol here, then
>> leave the port defaulting to the ConnectionFactory for that protocol.
>> For ejbd that's the SocketConnectionFactory, which maybe should be
>> renamed to EjbdConnectionFactory now that I think of it.
>
> Will change it with the other changes for the issue Dain reported.
>
> Jacek
>
> --
> Jacek Laskowski
> http://www.JacekLaskowski.pl
Re: Client connection URLs (Re: svn commit: r634818)
Posted by Jacek Laskowski <ja...@laskowski.net.pl>.
On Sat, Mar 8, 2008 at 1:04 AM, David Blevins <da...@visi.com> wrote:
> On Mar 7, 2008, at 12:58 PM, jlaskowski@apache.org wrote:
>
> > + // TODO: Move the check to a place where it really
> > belongs - ConnectionManager, ConnectionFactory or such
> > + // This class doesn't really know what is
> > required as far as connection details go
>
> Definitely. On this note, we should only default the port to 4201 if
> the protocol is ejbd. Http and https are supported and each has it's
> own default port.
>
> >
> > +
> > + int colonIndex = serverURI.indexOf(":");
> > + int slashesIndex = serverURI.indexOf("//");
> > + // hostname only
> > + if (colonIndex == -1 && slashesIndex == -1) {
> > + serverURI = "ejbd://" + serverURI + ":4201";
> > + } else if (colonIndex == -1) {
> > + serverURI = serverURI + ":4201";
> > + } else if (slashesIndex == -1) {
> > + serverURI = "ejbd://" + serverURI;
> > }
>
> We could likely keep the part that defaults the protocol here, then
> leave the port defaulting to the ConnectionFactory for that protocol.
> For ejbd that's the SocketConnectionFactory, which maybe should be
> renamed to EjbdConnectionFactory now that I think of it.
Will change it with the other changes for the issue Dain reported.
Jacek
--
Jacek Laskowski
http://www.JacekLaskowski.pl
Re: Client connection URLs (Re: svn commit: r634818)
Posted by Jacek Laskowski <ja...@laskowski.net.pl>.
On Sat, Mar 8, 2008 at 2:14 AM, Dain Sundstrom <da...@iq80.com> wrote:
> I think this change broke the standalone itests. When I start them I
> get the errors after this message. If you want to try it for
> yourself, build the server with assemblies (mvn clean install -
> Dmaven.test.skip -Dassemble) and run "ant test" in the assembly/test
> directory.
Thanks Dain. I built the assemblies before I committed the change, but
didn't know I should've run the itests too. Let me fix it.
Jacek
--
Jacek Laskowski
http://www.JacekLaskowski.pl
Re: Client connection URLs (Re: svn commit: r634818)
Posted by Dain Sundstrom <da...@iq80.com>.
I think this change broke the standalone itests. When I start them I
get the errors after this message. If you want to try it for
yourself, build the server with assemblies (mvn clean install -
Dmaven.test.skip -Dassemble) and run "ant test" in the assembly/test
directory.
-dain
itests.openejb.run:
[java] _________________________________________________
[java] |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|
[java]
[java] Running EJB compliance tests on Remote Server
[java] _________________________________________________
[java] WARNING: No test suite configuration file specified,
assuming system properties contain all needed information. To specify
a test suite configuration file by setting its location using the
system property "openejb.testsuite.properties"
[java] Cannot start the test database:
java.lang.IllegalStateException Cannot create initial context:
javax.naming.ConfigurationException Property value for
java.naming.provider.url invalid: 127.0.0.1:4201:Illegal character in
scheme name at index 0: 127.0.0.1:4201
[java] java.lang.IllegalStateException: Cannot create initial
context: javax.naming.ConfigurationException Property value for
java.naming.provider.url invalid: 127.0.0.1:4201:Illegal character in
scheme name at index 0: 127.0.0.1:4201
[java] Cannot initialize the test environment:
java.lang.IllegalStateException Cannot create initial context:
javax.naming.ConfigurationException Property value for
java.naming.provider.url invalid: 127.0.0.1:4201:Illegal character in
scheme name at index 0: 127.0.0.1:4201
[java] at
org
.apache.openejb.test.HsqldbTestDatabase.start(HsqldbTestDatabase.java:
178)
[java] at
org.apache.openejb.test.TestManager.start(TestManager.java:88)
[java] at
org.apache.openejb.test.TestRunner.start(TestRunner.java:188)
[java] at
org.apache.openejb.test.TestRunner.main(TestRunner.java:86)
[java] at org.apache.openejb.test.Main.main(Main.java:31)
[java] Caused by: javax.naming.ConfigurationException: Property
value for java.naming.provider.url invalid: 127.0.0.1:4201:Illegal
character in scheme name at index 0: 127.0.0.1:4201 [Root exception is
java.net.URISyntaxException: Illegal character in scheme name at index
0: 127.0.0.1:4201]
[java] at
org
.apache.openejb.client.JNDIContext.getInitialContext(JNDIContext.java:
145)
[java] at
javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
[java] at
javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
[java] at javax.naming.InitialContext.init(InitialContext.java:
223)
[java] at
javax.naming.InitialContext.<init>(InitialContext.java:197)
[java] at
org
.apache.openejb.test.HsqldbTestDatabase.start(HsqldbTestDatabase.java:
176)
[java] ... 4 more
[java] Caused by: java.net.URISyntaxException: Illegal character
in scheme name at index 0: 127.0.0.1:4201
[java] at java.net.URI$Parser.fail(URI.java:2816)
[java] at java.net.URI$Parser.checkChars(URI.java:2989)
[java] at java.net.URI$Parser.checkChar(URI.java:2999)
[java] at java.net.URI$Parser.parse(URI.java:3015)
[java] at java.net.URI.<init>(URI.java:578)
[java] at
org
.apache.openejb.client.JNDIContext.getInitialContext(JNDIContext.java:
125)
[java] ... 9 more
[java] Cannot create initial context:
javax.naming.ConfigurationException Property value for
java.naming.provider.url invalid: 127.0.0.1:4201:Illegal character in
scheme name at index 0: 127.0.0.1:4201
[java] Java Result: 2
On Mar 7, 2008, at 4:04 PM, David Blevins wrote:
> Good change!
>
> On Mar 7, 2008, at 12:58 PM, jlaskowski@apache.org wrote:
>
>> + // TODO: Move the check to a place where it really
>> belongs - ConnectionManager, ConnectionFactory or such
>> + // This class doesn't really know what is
>> required as far as connection details go
>
> Definitely. On this note, we should only default the port to 4201
> if the protocol is ejbd. Http and https are supported and each has
> it's own default port.
>
>>
>> +
>> + int colonIndex = serverURI.indexOf(":");
>> + int slashesIndex = serverURI.indexOf("//");
>> + // hostname only
>> + if (colonIndex == -1 && slashesIndex == -1) {
>> + serverURI = "ejbd://" + serverURI + ":4201";
>> + } else if (colonIndex == -1) {
>> + serverURI = serverURI + ":4201";
>> + } else if (slashesIndex == -1) {
>> + serverURI = "ejbd://" + serverURI;
>> }
>
> We could likely keep the part that defaults the protocol here, then
> leave the port defaulting to the ConnectionFactory for that
> protocol. For ejbd that's the SocketConnectionFactory, which maybe
> should be renamed to EjbdConnectionFactory now that I think of it.
>
> -David
>
Client connection URLs (Re: svn commit: r634818)
Posted by David Blevins <da...@visi.com>.
Good change!
On Mar 7, 2008, at 12:58 PM, jlaskowski@apache.org wrote:
> + // TODO: Move the check to a place where it really
> belongs - ConnectionManager, ConnectionFactory or such
> + // This class doesn't really know what is
> required as far as connection details go
Definitely. On this note, we should only default the port to 4201 if
the protocol is ejbd. Http and https are supported and each has it's
own default port.
>
> +
> + int colonIndex = serverURI.indexOf(":");
> + int slashesIndex = serverURI.indexOf("//");
> + // hostname only
> + if (colonIndex == -1 && slashesIndex == -1) {
> + serverURI = "ejbd://" + serverURI + ":4201";
> + } else if (colonIndex == -1) {
> + serverURI = serverURI + ":4201";
> + } else if (slashesIndex == -1) {
> + serverURI = "ejbd://" + serverURI;
> }
We could likely keep the part that defaults the protocol here, then
leave the port defaulting to the ConnectionFactory for that protocol.
For ejbd that's the SocketConnectionFactory, which maybe should be
renamed to EjbdConnectionFactory now that I think of it.
-David