-
-
Save rjungemann/421805 to your computer and use it in GitHub Desktop.
Sinatra-like example in JRuby with Jersey
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'java' | |
java_import 'javax.ws.rs.Path' | |
java_import 'javax.ws.rs.GET' | |
java_import 'javax.ws.rs.Produces' | |
java_package 'com.headius.demo.jersey' | |
java_annotation 'Path("/helloworld")' | |
class HelloWorld | |
java_annotation 'GET' | |
java_annotation 'Produces("text/plain")' | |
def cliched_message | |
"Hello World" | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'java' | |
java_import com.sun.jersey.api.container.grizzly.GrizzlyWebContainerFactory | |
base_uri = "http://localhost:9998/" | |
init_params = { | |
"com.sun.jersey.config.property.packages" => "com.headius.demo.jersey" | |
} | |
puts "Starting grizzly" | |
thread_selector = GrizzlyWebContainerFactory.create( | |
base_uri, init_params.to_java) | |
puts <<EOS | |
Jersey app started with WADL available at #{base_uri}application.wadl | |
Try out #{base_uri}helloworld | |
Hit enter to stop it... | |
EOS | |
gets | |
thread_selector.stop_endpoint | |
exit(0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~/projects/jruby ➔ jrubyc -c ../jersey-archive-1.2/lib/jsr311-api-1.1.1.jar --javac restful_service.rb | |
Generating Java class HelloWorld to /Users/headius/projects/jruby/com/headius/demo/jersey/HelloWorld.java | |
javac -d /Users/headius/projects/jruby -cp /Users/headius/projects/jruby/lib/jruby.jar:../jersey-archive-1.2/lib/jsr311-api-1.1.1.jar /Users/headius/projects/jruby/com/headius/demo/jersey/HelloWorld.java |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~/projects/jruby ➔ CLASSPATH=../jersey-archive-1.2/lib/jersey-core-1.2.jar:../jersey-archive-1.2/lib/jersey-server-1.2.jar:~/Downloads/grizzly-servlet-webserver-1.9.9.jar:../jersey-archive-1.2/lib/jsr311-api-1.1.1.jar:../jersey-archive-1.2/lib/asm-3.1.jar jruby main.rb | |
Starting grizzly | |
Jersey app started with WADL available at http://localhost:9998/application.wadl | |
Try out http://localhost:9998/helloworld | |
Hit enter to stop it... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~ ➔ curl http://localhost:9998/helloworld | |
Hello World | |
~ ➔ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment