RoR problems with JRuby 1.1.4

Hi all,

I’m trying to run a Ruby on Rails application in a Tomcat Java EE
container using the latest JRuby (1.1.4). First of all, my environment
is the following:

OS: Mac OS X 10.5.4 (Intel)
Java: Java™ 2 Runtime Environment, Standard Edition (build 1.5.0_13-
b05-237)
Java HotSpot™ Client VM (build 1.5.0_13-119, mixed mode, sharing)
Rails: 2.1.1 (latest!)

I use the latest version of warbler (0.9.11) to make a .war archive
for deployment in Tomcat. My config/environment.rb is customized with
the following soap4r calls:

require ‘rubygems’
gem ‘soap4r’
gem ‘fastercsv’

Bootstrap the Rails environment, frameworks, and default configuration

require File.join(File.dirname(FILE), ‘boot’)

Rails::Initializer.run do |config|

[ … configuration section skipped …]

puts ‘=> Booting Kernel…’
require File.join(File.dirname(FILE), ‘…’, ‘kernel’,
‘configurator’)
require File.join(File.dirname(FILE), ‘…’, ‘kernel’, ‘xmir_proxy’)
require File.join(File.dirname(FILE), ‘…’, ‘kernel’,
‘xmir_service’)

require File.join(File.dirname(FILE), ‘…’, ‘kernel’,

‘xmir_service_client’)
require File.join(File.dirname(FILE), ‘…’, ‘kernel’,
‘xmir_service_driver’)
require File.join(File.dirname(FILE), ‘…’, ‘kernel’,
'xmir_service_mapping_registr

configurator = Kernel::Configurator.instance
configurator.load_config

puts “=> Reading web app configuration from #{configurator.config_file}”
configurator.config.each do |xk, xv|
puts “section #{xk} {”
xv.each do |ik, iv|
puts " #{ik} = #{iv}"
end
puts “}”
end

xmir = Kernel::XmirProxy.new
begin
puts " identity = #{xmir.identify}"
puts " major version = #{xmir.major_version}"
puts " minor version = #{xmir.minor_version}"
puts “=> Boot OK”
rescue Exception => ex
puts “=> Caught error while testing the web service: #{ex}”
puts “=> Did you remember to start the web service?”
end

… where the XmirProxy is a proxy class that wraps the underlying
soap4r logic for doing XML-RPC to a remote server. environment.rb
checks the availability of the remote web service when booting the
application. This works absolutely brilliant in C Ruby. I have the
following jruby gems installed (as stated and checked by warbler):

actionmailer (2.1.1)
actionpack (2.1.1)
activerecord (2.1.1)
activerecord-jdbc-adapter (0.8.2)
activerecord-jdbcpostgresql-adapter (0.8.2)
activeresource (2.1.1)
activesupport (2.1.1)
fastercsv (1.2.3)
hoe (1.7.0)
httpclient (2.1.2)
jdbc-postgres (8.2)
jruby-openssl (0.3)
memcache-client (1.5.0)
rails (2.1.1)
rake (0.8.1)
rspec (1.1.4)
rubyforge (1.0.0)
soap4r (1.5.8)
sources (0.0.1)
warbler (0.9.11)
ZenTest (3.10.0)

When doing jruby -S warble war, I get the following exception
stacktrace: http://pastie.org/270258 (put into pastie for the sake of
reading…)

The war file is compressed, though, and I get the last following error
when deploying the war file afterwards in Tomcat:

Sep 11, 2008 12:26:33 AM org.apache.catalina.core.ApplicationContext log
SEVERE: Exception caught
org.jruby.rack.RackInitializationException: Could not find RubyGem
soap4r (>= 0)

from file:/Users/aj/jruby/apache-tomcat-6.0.18/webapps/meeho/WEB-
INF/lib/jruby-comple
from file:/Users/aj/jruby/apache-tomcat-6.0.18/webapps/meeho/WEB-
INF/lib/jruby-comple
from /Users/aj/jruby/apache-tomcat-6.0.18/webapps/meeho/WEB-INF/
config/environment.rb
from /Users/aj/jruby/apache-tomcat-6.0.18/webapps/meeho/WEB-INF/
config/environment.rb
from file:/Users/aj/jruby/apache-tomcat-6.0.18/webapps/meeho/WEB-
INF/lib/jruby-rack-0
from file:/Users/aj/jruby/apache-tomcat-6.0.18/webapps/meeho/WEB-
INF/lib/jruby-rack-0
from :3
from file:/Users/aj/jruby/apache-tomcat-6.0.18/webapps/meeho/WEB-
INF/lib/jruby-rack-0
from file:/Users/aj/jruby/apache-tomcat-6.0.18/webapps/meeho/WEB-
INF/lib/jruby-rack-0
from :3

at org.jruby.rack.DefaultRackApplicationFactory
$4.init(DefaultRackApplicationFactory.
at
org
.jruby
.rack
.DefaultRackApplicationFactory.getApplication(DefaultRackApplication
at
org
.jruby
.rack
.PoolingRackApplicationFactory.getApplication(PoolingRackApplication
at
org
.jruby.rack.DefaultRackDispatcher.process(DefaultRackDispatcher.java:31)
at org.jruby.rack.RackFilter.doFilter(RackFilter.java:51)
at
org
.apache
.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilter
at
org
.apache
.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.ja
at
org
.apache
.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233
at
org
.apache
.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191
at
org
.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:
128)
at
org
.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:
102)
at
org
.apache
.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:
286)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:
845)
at org.apache.coyote.http11.Http11Protocol
$Http11ConnectionHandler.process(Http11Prot
at org.apache.tomcat.util.net.JIoEndpoint
$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:613)
Caused by: org.jruby.exceptions.RaiseException
at Kernel.raise(file:/Users/aj/jruby/apache-tomcat-6.0.18/webapps/
meeho/WEB-INF/lib/j
at #Class:01xf1b05c.report_activate_error(file:/Users/aj/jruby/
apache-tomcat-6.0.18
at #Class:01xf1b05c.activate(file:/Users/aj/jruby/apache-
tomcat-6.0.18/webapps/meeh
at Kernel.gem(/Users/aj/jruby/apache-tomcat-6.0.18/webapps/meeho/
WEB-INF/config/envir
at (unknown).(unknown)(/Users/aj/jruby/apache-tomcat-6.0.18/webapps/
meeho/WEB-INF/con
at Kernel.load(file:/Users/aj/jruby/apache-tomcat-6.0.18/webapps/
meeho/WEB-INF/lib/jr
at JRuby::Rack::RailsServletHelper.load_environment(file:/Users/aj/
jruby/apache-tomca
at #Class:01x34d2f7.new(:3)
at (unknown).(unknown)(file:/Users/aj/jruby/apache-tomcat-6.0.18/
webapps/meeho/WEB-IN
at Kernel.instance_eval(file:/Users/aj/jruby/apache-tomcat-6.0.18/
webapps/meeho/WEB-I
at Kernel.instance_eval(file:/Users/aj/jruby/apache-tomcat-6.0.18/
webapps/meeho/WEB-I
at Rack::Builder.initialize(:3)
at (unknown).(unknown)(:1)

soap4r is installed, but I think it might be related to the httpclient/
openssl problem when packing the application. This is getting really
odd.

I hope to hear from you guys soon, as I would really like to run my
current C/Ruby production environment on Java.


Mvh. / Best Regards

Anders Østergaard Jensen, B.Sc.
Partner & CTO, Meeho! ApS

Phone: +45 21 28 68 69
E-mail: [email protected]
Web: http://www.meeho.dk/

Did you tell warbler to add the soap4r gem to the WARfile?
something like

cd yourapp; jruby -S warble config
and add

config.gems << “soap4r”

to config/warble.rb

Then rebuild the war and redeploy.

On Thu, Sep 11, 2008 at 7:29 AM, Anders Østergaard Jensen
[email protected] wrote:

Hi all,
I’m trying to run a Ruby on Rails application in a Tomcat Java EE container
using the latest JRuby (1.1.4). First of all, my environment is the
following:
OS: Mac OS X 10.5.4 (Intel)
r_version}"
puts “=> Boot OK”
rescue Exception => ex
puts “=> Caught error while testing the web service: #{ex}”
puts “=> Did you remember to start the web service?”
end

Sep 11, 2008 12:26:33 AM org.apache.catalina.core.ApplicationContext log
SEVERE: Exception caught
org.jruby.rack.RackInitializationException: Could not find RubyGem soap4r
(>= 0)


Rasputnik :: Jack of All Trades - Master of Nuns
http://number9.hellooperator.net/


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

I did that. The error still pops up in the warbler output when running
the ‘war’ target, but the Tomcat deployment yields a different error:

Sep 11, 2008 10:48:41 AM org.apache.catalina.startup.HostConfig
deployWAR
INFO: Deploying web application archive meeho.war
java.lang.VerifyError: (class: org/jruby/ext/openssl/ASN1$ASN1Data,
method: toASN1 signature: ()Lorg/bouncycastle/asn1/ASN1Encodable;)
Wrong return type in function
at org.jruby.ext.openssl.ASN1.createASN1(ASN1.java:269)
at org.jruby.ext.openssl.OpenSSLReal.createOpenSSL(OpenSSLReal.java:
81)
at JopensslService.basicLoad(JopensslService.java:38)
at
org
.jruby
.runtime.load.ClassExtensionLibrary.load(ClassExtensionLibrary.java:50)
at org.jruby.runtime.load.LoadService.smartLoad(LoadService.java:319)
at org.jruby.runtime.load.LoadService.require(LoadService.java:345)
at org.jruby.RubyKernel.require(RubyKernel.java:671)
at org.jruby.RubyKernelInvoker$require_s_method_1_0.call(Unknown
Source)
at org.jruby.internal.runtime.methods.JavaMethod
$JavaMethodOneBlock.call(JavaMethod.java:139)
at
org.jruby.internal.runtime.methods.AliasMethod.call(AliasMethod.java:60)
at
org
.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:
78)
at org.jruby.runtime.CallSite
$InlineCachingCallSite.call(CallSite.java:304)
at
ruby
.jit
.ruby
.Users
.aj
.jruby
.apache_minus_tomcat_minus_6_dot_0_dot_18
.bin
.Users
.aj
.jruby
.apache_minus_tomcat_minus_6_dot_0_dot_18
.webapps.meeho.WEB_minus_INF.lib.jruby_minus_complete_minus_1_dot_1
at
ruby
.jit
.ruby
.Users
.aj
.jruby
.apache_minus_tomcat_minus_6_dot_0_dot_18
.bin
.Users
.aj
.jruby
.apache_minus_tomcat_minus_6_dot_0_dot_18
.webapps.meeho.WEB_minus_INF.lib.jruby_minus_complete_minus_1_dot_1
at
org
.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:
144)
at org.jruby.RubyClass.invoke(RubyClass.java:236)
at
org.jruby.javasupport.util.RuntimeHelpers.invokeAs(RuntimeHelpers.java:
322)

(in catalina.out…)

Anyone?

/Anders

On Sep 11, 2008, at 10:25 AM, Dick D. wrote:

Then rebuild the war and redeploy

Mvh. / Best Regards

Anders Østergaard Jensen, B.Sc.
Partner, Meeho! ApS

Østerbrogade 132 2.tv.
DK-2100 København Ø
Denmark

Phone: +45 21 28 68 69
E-mail: [email protected]
Web: http://www.meeho.dk/

Anders Østergaard Jensen wrote:

I did that. The error still pops up in the warbler output when running
the ‘war’ target, but the Tomcat deployment yields a different error:

Sep 11, 2008 10:48:41 AM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive meeho.war
java.lang.VerifyError: (class: org/jruby/ext/openssl/ASN1$ASN1Data,
method: toASN1 signature: ()Lorg/bouncycastle/asn1/ASN1Encodable;) Wrong
return type in function
at org.jruby.ext.openssl.ASN1.createASN1(ASN1.java:269)

Ok, this looks like either a bad BC jar is getting picked up somewhere,
or the OpenSSL release compiled against the wrong jar somehow. Either
are possible.

I’m working with Anders on IRC now to get a verbose dump of all classes
being loaded during startup and deployment; hopefully it will be
something obvious.

  • Charlie

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Anders Østergaard Jensen wrote:

How can I change that, so that javascript_include_tag and other helper
methods do not automatically include the web app deployment path when
generating the URLs for the application? If not, I’m unable to run the
proxy in front of Tomcat (and the proxy is necessary for me).

If you only have the one app, I believe the trick with Tomcat is to name
your WAR file “ROOT.war” and remove the ROOT app that comes with Tomcat.
Your app will then be deployed at /.

I think there’s also a way to tweak warbler to tell Rails to use a
different base URI, but I don’t remember the setting. Something in
config/warble.rb probably?

  • Charlie

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

It looks like I got the application working – when I deploy it in /
<some_webapp_name.

I have a problem with the new context path, though, since I would like
to wrap the Tomcat installation in a nginx proxy that handles load
balancing, certificates, etc. The scenario is the following:

localhost:80 (nginx) -----> localhost:8080/meeho

My problem is that all the generated URLs in the rails application
point to localhost/meeho/:

... but since I use the proxy, the javascript references should just point to /javascripts/prototype.js etc -- and not with the prepended / meeho/ for all urls. How can I change that, so that javascript_include_tag and other helper methods do not automatically include the web app deployment path when generating the URLs for the application? If not, I'm unable to run the proxy in front of Tomcat (and the proxy is necessary for me). Thanks in advance, Anders On Sep 11, 2008, at 12:04 PM, Charles Oliver N. wrote: > > Ok, this looks like either a bad BC jar is getting picked up > somewhere, or the OpenSSL release compiled against the wrong jar > somehow. Either are possible. > > I'm working with Anders on IRC now to get a verbose dump of all > classes being loaded during startup and deployment; hopefully it > will be something obvious. > > - Charlie -- Mvh. / Best Regards Anders Østergaard Jensen, B.Sc. Partner, Meeho! ApS Østerbrogade 132 2.tv. DK-2100 København Ø Denmark Phone: +45 21 28 68 69 E-mail: [email protected] Web: http://www.meeho.dk/

There doesn’t seem to be an easy way to do it, but as you probably
will want to do it for stylesheets, js and other “static assets” you
should start by looking at the “compute_public_path” method at the
AssetTagHelper. If you find it’s too ugly to override a private method
(and it is ugly :stuck_out_tongue: ) you can just override the javascript_path
,stylesheet_path and image_path methods.

On Thu, Sep 11, 2008 at 1:33 PM, Anders Østergaard Jensen
[email protected] wrote:

On Sep 11, 2008, at 12:04 PM, Charles Oliver N. wrote:


Maurício Linhares
http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/
(en)
João Pessoa, PB, +55 83 8867-7208


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Sep 11, 2008, at 8:27 PM, Nick S. wrote:

Leading context paths should be handled transparently, though you may
need to use Rails asset helpers to ensure the proper paths to assets
are used (or hard-code the leading path).

I’m not sure if I get your agenda correctly:

As Charles Nutter states, an obvious solution is to deploy the
resulting war file as ROOT.war (a solution which in my opinion is a
bit of a hack). On the other hand, your recommendation is to hard-code
and hence overriding the default behaviour of the Rails asset helpers.
Is that correctly understood?

I’m not sure proxying from the root of a vhost to the context path in
Tomcat will work with the way JRuby-Rack sets the relative path
automatically – you might have to monkey patch around that code.
Relevant code is here:

http://github.com/nicksieger/jruby-rack/tree/master/src/main/ruby/jruby/rack/rails.rb#L137-146

I don’t know JRuby-Rack, and honestly I can’t see how this solution
fits in. Could you please explain it a bit more?

Thanks in advance – and cheers!

/Anders

On Thu, Sep 11, 2008 at 1:39 PM, Anders Østergaard Jensen
[email protected] wrote:

file as ROOT.war (a solution which in my opinion is a bit of a hack). On the
other hand, your recommendation is to hard-code and hence overriding the
default behaviour of the Rails asset helpers. Is that correctly understood?

Not quite. I’m saying that you shouldn’t have to hard-code any paths
if you use the Rails asset helpers. But, if you proxy from root (/)
on a frontend to a sub-path (/subpath) in Tomcat, you’re going to be
going against the grain, because JRuby-Rack is going to detect
/subpath and set the relative_url_root parameter such that Rails asset
helpers will be prepending it. In that case, you will need to undo the
effects of that, either by monkey patching the code I showed in the
link below, or by putting something in a before_filter of your
application.

/Nick

Could you please explain it a bit more?
Thanks in advance – and cheers!
/Anders


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Thu, Sep 11, 2008 at 11:49 AM, Charles Oliver N.
[email protected] wrote:

I think there’s also a way to tweak warbler to tell Rails to use a different
base URI, but I don’t remember the setting. Something in config/warble.rb
probably?

Leading context paths should be handled transparently, though you may
need to use Rails asset helpers to ensure the proper paths to assets
are used (or hard-code the leading path).

I’m not sure proxying from the root of a vhost to the context path in
Tomcat will work with the way JRuby-Rack sets the relative path
automatically – you might have to monkey patch around that code.
Relevant code is here:

Cheers,
/Nick


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Sep 11, 2008, at 9:10 PM, Nick S. wrote:

Not quite. I’m saying that you shouldn’t have to hard-code any paths
if you use the Rails asset helpers. But, if you proxy from root (/)
on a frontend to a sub-path (/subpath) in Tomcat, you’re going to be
going against the grain, because JRuby-Rack is going to detect
/subpath and set the relative_url_root parameter such that Rails asset
helpers will be prepending it. In that case, you will need to undo the
effects of that, either by monkey patching the code I showed in the
link below, or by putting something in a before_filter of your
application.

Got it. Now I understand.

I can see on the code that it’s hidden somewhere in JRuby::Rack which
is not quite accessible.

Do you want me to override that method from environment.rb?

Cheers,

/Anders


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email