2013-02-21 38 views
0

我试图按照Eclipse wiki上的教程创建我的第一个Jetty嵌入式模式应用程序。我想在JRuby而不是Java中执行此操作。使用jruby的jetty嵌入式应用程序

这里的Java代码:

public class ManyConnectors 
{ 
public static void main(String[] args) throws Exception 
{ 
    Server server = new Server(); 

    SelectChannelConnector connector0 = new SelectChannelConnector(); 
    connector0.setPort(8080); 
    connector0.setMaxIdleTime(30000); 
    connector0.setRequestHeaderSize(8192); 

    SelectChannelConnector connector1 = new SelectChannelConnector(); 
    connector1.setHost("127.0.0.1"); 
    connector1.setPort(8888); 
    connector1.setThreadPool(new QueuedThreadPool(20)); 
    connector1.setName("admin"); 

    SslSelectChannelConnector ssl_connector = new SslSelectChannelConnector(); 
    String jetty_home = 
     System.getProperty("jetty.home","../jetty-distribution/target/distribution"); 
    System.setProperty("jetty.home",jetty_home); 
    ssl_connector.setPort(8443); 
    SslContextFactory cf = ssl_connector.getSslContextFactory(); 
    cf.setKeyStore(jetty_home + "/etc/keystore"); 
    cf.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4"); 
    cf.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g"); 

    server.setConnectors(new Connector[]{ connector0, connector1, ssl_connector }); 

    server.setHandler(new HelloHandler()); 

    server.start(); 
    server.join(); 
} 
} 

我在翻译这行成等价的JRuby的一个问题:

server.setConnectors(new Connector[]{ connector0, connector1, ssl_connector }); 

任何帮助,将不胜感激。

+0

你有什么问题?显示你的努力,你的试验,你的错误。 – gaborsch 2013-02-21 21:49:29

+0

你可以显示你的进口? – Rob 2013-02-22 06:11:47

回答

1

尝试使用普通的旧阵列:

server.set_connectors([connector0, connector1, ssl_connector ]) 

编辑 - 这里有一个工作示例:

require 'pp' 
require 'java' 
require 'jetty-6.1.3.jar' # in local dir 
require 'jetty-util-6.1.3.jar' # in local dir 
require 'servlet-api-2.5-6.1.3.jar' # in local dir 

class MyHandler 
    include org.mortbay.jetty.Handler 
    def destroy;end 
    def start;end 
    def getServer;end 
    def handle(target, request, response, dispatch) 
    pp target 
    pp request 
    end 
    def setServer(server);end 
end 
server = Java::OrgMortbayJetty::Server.new 


connector0 = org.mortbay.jetty.nio.SelectChannelConnector.new 
connector0.set_port(8080) 
connector0.set_max_idle_time(30000) 
# connector0.set_request_header_size(8192) # could not find this method 

server.set_connectors([connector0]) 
server.set_handlers([MyHandler.new]) 
server.start 
server.join 
+0

谢谢。那就是诀窍。你是个学者和绅士。 – user2095940 2013-02-23 22:25:00

相关问题