Skip to content

Instantly share code, notes, and snippets.

Created July 15, 2015 16:29
Show Gist options
  • Save anonymous/cc367a624d6864cbd104 to your computer and use it in GitHub Desktop.
Save anonymous/cc367a624d6864cbd104 to your computer and use it in GitHub Desktop.
# Servlet
class EventProcessorServlet < WEBrick::HTTPServlet::AbstractServlet
def initialize(server, agent)
super server
@agent = agent
end
def do_POST(req, resp)
begin
@agent.process(req.body)
rescue Exception => msg
resp.status = 500
resp['content-type'] = 'text/plain'
resp.body = "#{msg}\n#{req.body}"
end
resp.status = 200
end
end
# in @agent
def process(event_json)
raise "No records processed" unless do_something(event_json)
end
# response.body
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<HTML>
<HEAD><TITLE>Internal Server Error</TITLE></HEAD>
<BODY>
<H1>Internal Server Error</H1>
No records processed
<HR>
<ADDRESS>
WEBrick/1.3.1 (Ruby/2.2.2/2015-04-13) at
127.0.0.1:59255
</ADDRESS>
</BODY>
</HTML>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment