Embedded mode remote access

1,272 views
Skip to first unread message

Feuerbach

unread,
Nov 10, 2009, 7:52:35 PM11/10/09
to H2 Database
Hi,

I am embedding H2 and starting it via the servlet listener. The web
console comes up with the error "Sorry, remote connections
('webAllowOthers') are disabled on this server."

Is it possible somehow to enable remote access using the embedded/
servlet method. Note, I am not starting this up using the bat script.

Thanks.

Kerry Sainsbury

unread,
Nov 11, 2009, 12:34:06 AM11/11/09
to h2-da...@googlegroups.com
http://www.h2database.com/html/tutorial.html?highlight=servlet&search=getServletContext#firstFound shows that you can embed "parameters" in the web.xml, eg:

<context-param>
    <param-name>db.tcpServer</param-name>
    <param-value>-tcpAllowOthers</param-value>
</context-param>

You can also pass the "command line" arguments directly to the class:
  
     Server server = Server.createTcpServer(new String[] {"-tcpAllowOthers" });
     server.start()

Cheers,
Kerry

Feuerbach

unread,
Nov 11, 2009, 5:04:33 AM11/11/09
to H2 Database
Awesome, thanks for that.

On Nov 11, 4:34 pm, Kerry Sainsbury <ke...@fidelma.com> wrote:
> http://www.h2database.com/html/tutorial.html?highlight=servlet&search...
> shows
> that you can embed "parameters" in the web.xml, eg:
>
> <context-param>
>     <param-name>db.tcpServer</param-name>
>     <param-value>-tcpAllowOthers</param-value>
> </context-param>
>
> You can also pass the "command line" arguments directly to the class:
>
>      Server server = Server.createTcpServer(new String[] {"-tcpAllowOthers"});
>
>      server.start()
>
> Cheers,
> Kerry
>

Feuerbach

unread,
Nov 11, 2009, 6:20:01 PM11/11/09
to H2 Database
Just on another related note, when I start tomcat (Windows) using
startup.bat all goes well, but when I start tomcat using the windows
service, I get errors:

org.h2.jdbc.JdbcSQLException: Table "HMAP" not found; SQL statement:
SELECT URL FROM HMAP WHERE HID=? [42102-123]

Any ideas?
> shows
> that you can embed "parameters" in the web.xml, eg:
>
> <context-param>
>     <param-name>db.tcpServer</param-name>
>     <param-value>-tcpAllowOthers</param-value>
> </context-param>
>
> You can also pass the "command line" arguments directly to the class:
>
>      Server server = Server.createTcpServer(new String[] {"-tcpAllowOthers"});
>
>      server.start()
>
> Cheers,
> Kerry
>

Thomas Mueller

unread,
Nov 13, 2009, 11:52:59 AM11/13/09
to h2-da...@googlegroups.com
Hi,

> Just on another related note, when I start tomcat (Windows) using
> startup.bat all goes well, but when I start tomcat using the windows
> service, I get errors:
>
> org.h2.jdbc.JdbcSQLException: Table "HMAP" not found; SQL statement:
> SELECT URL FROM HMAP WHERE HID=? [42102-123]

A common cause is that the wrong database was opened.
What is our database URL? Try using an absolute URL such as:

jdbc:h2:tcp://localhost//data/test

The following URL should be avoided: jdbc:h2:tcp://localhost/data/test
because it is relative to the current working directory (and within an
application server I don't know where that is).

See also http://www.h2database.com/html/features.html#database_url

Regards,
Thomas

Feuerbach

unread,
Nov 15, 2009, 7:40:58 PM11/15/09
to H2 Database
Thanks,

But nothing I do seems to help. I'm running in embedded mode, here is
the web.xml config:

<context-param>
<param-name>db.url</param-name>
<param-value>jdbc:h2:~/handle</param-value>
</context-param>
<context-param>
<param-name>db.user</param-name>
<param-value>sa</param-value>
</context-param>
<context-param>
<param-name>db.password</param-name>
<param-value>sa</param-value>
</context-param>
<context-param>
<param-name>db.tcpServer</param-name>
<param-value>-tcpAllowOthers</param-value>
</context-param>

Using startup.bat all is good, but running Tomcat as windows service
is causing serious problems.

On Nov 14, 3:52 am, Thomas Mueller <thomas.tom.muel...@gmail.com>
wrote:

Feuerbach

unread,
Nov 15, 2009, 7:55:00 PM11/15/09
to H2 Database
I noted that startup.bat uses the handle.db from the tomcat/bin dir.
so I changed the config to:

<param-name>db.url</param-name>
<param-value>jdbc:h2:file:C://tomcat/bin/handle</param-value>

Works ok using startup.bat, but as windows service h2 cannot be found.

Thomas Mueller

unread,
Nov 17, 2009, 2:22:19 PM11/17/09
to h2-da...@googlegroups.com
Hi,

> <param-name>db.url</param-name>
>      <param-value>jdbc:h2:file:C://tomcat/bin/handle</param-value>
>
> Works ok using startup.bat, but as windows service h2 cannot be found.

Could you explain what you mean with "not found"? Is there an exception?

Regards,
Thomas

Feuerbach

unread,
Nov 17, 2009, 5:25:50 PM11/17/09
to H2 Database
Hi Thomas,

The basic problem is that I'm loading the servlet with the -
tcpAllowOthers and I still get the error:

Sorry, remote connections ('webAllowOthers') are disabled on this
server.

This is now on a clean install, here is web.xml:

<listener>
<listener-class>org.h2.server.web.DbStarter</listener-class>
</listener>

<servlet>
<servlet-name>H2Console</servlet-name>
<servlet-class>org.h2.server.web.WebServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<description>
</description>
<display-name>Handler</display-name>
<servlet-name>Handler</servlet-name>
<servlet-class>au.edu.unsw.lrs.handle.Handler</servlet-class>
</servlet>

<context-param>
<param-name>db.url</param-name>
<param-value>jdbc:h2:file:C:/data/handle</param-value>
</context-param>
<context-param>
<param-name>db.user</param-name>
<param-value>sa</param-value>
</context-param>
<context-param>
<param-name>db.password</param-name>
<param-value></param-value>
</context-param>
<context-param>
<param-name>db.tcpServer</param-name>
<param-value>-tcpAllowOthers</param-value>
</context-param>

I've tried with and without password "sa"

Cheers.

Louis.

On Nov 18, 6:22 am, Thomas Mueller <thomas.tom.muel...@gmail.com>
wrote:

Feuerbach

unread,
Nov 17, 2009, 6:41:01 PM11/17/09
to H2 Database
Ok, this is getting frustrating.

To explain what I'm trying to do. I simply want to embed H2 inside a
web application. I do NOT need tcp access. But I do want to be able to
access the H2 console servlet from within that same web application. I
want to be able to access the console locally and remotely. So, I
guess the console app needs to be able to talk to the embedded
database (which will physically reside in WEB-INF/data), but it seems
to console is trying to connect via TCP and whenever i point to it I
keep getting "Sorry, remote connections ('webAllowOthers') are
disabled on this
server."

I do not want a remote connection, I want a local connection from the
console servlet, and to be able to access the console from a remote
URL.

I hope that helps explain my situation.
Thanks in advance.

Feuerbach

unread,
Nov 17, 2009, 6:45:06 PM11/17/09
to H2 Database
I have also done a "build warConsole" to generate a new .jar file, but
I altered the DbStarter.java as follows:

public void contextInitialized(ServletContextEvent
servletContextEvent) {
try {
org.h2.Driver.load();

// This will get the setting from a context-param in
web.xml if defined:
ServletContext servletContext =
servletContextEvent.getServletContext();
String url = getParameter(servletContext, "db.url", null);
String user = getParameter(servletContext, "db.user",
null);
String password = getParameter(servletContext,
"db.password", null);

conn = DriverManager.getConnection(url, user, password);
servletContext.setAttribute("connection", conn);

} catch (Exception e) {
e.printStackTrace();
}
}

note, that I am forcing the config to reside in the web.xml, which is:

<context-param>
<param-name>db.url</param-name>
<param-value>jdbc:h2:file:D:/Java/apache-tomcat-6.0.20/webapps/
handle/WEB-INF/data/handle</param-value>
</context-param>
<context-param>
<param-name>db.user</param-name>
<param-value>sa</param-value>
</context-param>
<context-param>
<param-name>db.password</param-name>
<param-value>test123?</param-value>
</context-param>

This all works fine on my local machine, pointing to tomcat server
"localhost:8080/handle/console", but when I port it to the dev server,
and go to "remoteIP:8080/handle/console" I keep getting that pesky
"Sorry, remote connections ('webAllowOthers') are disabled on this
server. " . I simply need to find a way of allowing access to the
console servlet on a locally available embedded h2, and stop it from
trying to use a tcp connection.

Thanks.

On Nov 18, 9:25 am, Feuerbach <feuerbac...@gmail.com> wrote:

Thomas Mueller

unread,
Nov 18, 2009, 12:19:31 AM11/18/09
to h2-da...@googlegroups.com
Hi,

> Sorry, remote connections ('webAllowOthers') are disabled on this
> server.

As the exception says, the problem is the -webAllowOthers setting. Not
the -tcpAllowOthers setting.

You don't need the DbStarter. It starts the TCP Server, which you
don't need. You want the Console.

The -webAllowOthers setting is set in web.xml here:

<servlet>
<servlet-name>H2Console</servlet-name>
<servlet-class>org.h2.server.web.WebServlet</servlet-class>
<init-param>
<param-name>-webAllowOthers</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

Regards,
Thomas
> --
>
> You received this message because you are subscribed to the Google Groups "H2 Database" group.
> To post to this group, send email to h2-da...@googlegroups.com.
> To unsubscribe from this group, send email to h2-database...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/h2-database?hl=.
>
>
>
Reply all
Reply to author
Forward
0 new messages