Skip to content

Instantly share code, notes, and snippets.

@jcalvert
Created October 15, 2011 08:10
Show Gist options
  • Select an option

  • Save jcalvert/1289254 to your computer and use it in GitHub Desktop.

Select an option

Save jcalvert/1289254 to your computer and use it in GitHub Desktop.
JRuby + CXF
package com.vetstreet;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* If we pull this JAR in via JRuby, we don't get the sexy OSGI Blueprint magic, so let's
* boot the context and provide accessors. Make it a singleton so we don't go blasting out contexts.
* @author jcalvert
*
*/
public class Context {
private static Context context;
private BeanFactory factory;
private Context()
{
ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(new String[] {"META-INF/spring/beans.xml"});
this.factory = (BeanFactory) appContext;
}
public static Context getInstance()
{
if(context == null)
{
context = new Context();
}
return context;
}
//Hide the fact that it's spring...
public Object getBean(String beanName)
{
return factory.getBean(beanName);
}
}
require 'java'
require './lib/my-deps.jar'
require './lib/my.jar'
context = com.vetstreet.Context.instance #Takes a moment as it loads up everything
=> Java::ComVetstreet::Context
registration_dao = context.get_bean "registrationDao"
=> #<Java::ComVetstreetDao::RegistrationDao:0x16315e08>
reg_hash = {'first_name' => "Foo", 'last_name' => "bar" ... }
registration_dao.register_user_with_map reg_hash
=> "my external system key"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment