【问题标题】:Using external server restlet framework使用外部服务器 restlet 框架
【发布时间】:2013-08-21 10:58:00
【问题描述】:

我正在使用 Restlet 框架,但现在我想更改为合适的服务器而不是使用 localhost。 我已经将我的 php 文件(它们使用 rest_server URL 访问 java 文件)添加到服务器的文件夹和我的 java 文件中,但我不确定如何更改代码,以便它识别文件的新位置在哪里.

这是来自 IdentiscopeServer 的代码(构造函数为空):

public static void main(String[] args) throws Exception {

    //setsup our security manager
    if (System.getSecurityManager() == null){
        System.setSecurityManager(new SecurityManager());
    }

    identiscopeServerApp = new IdentiscopeServerApplication();

    IdentiscopeServer server = new IdentiscopeServer();
    server.getServers().add(Protocol.HTTP,8888);
    server.getDefaultHost().attach("", identiscopeServerApp);
    server.start();

}

我猜想更改的正确行是带有“Protocol.HTTP, 8888”的行。如果我的新服务器地址是http://devweb2013.co.uk/research/Identiscope,我该如何设置呢?除了将文件移动到服务器中的文件夹之外,还有其他必要的工作吗?

IdensicopeServerApplication 如下:

public class IdentiscopeServerApplication extends Application {

public IdentiscopeServerApplication() {
}

public Restlet createInboundRoot() {
    Router router = new Router(getContext());

    //attaches the /tweet path to the TweetRest class
    router.attach("/collectionPublic", CollectionPublicREST.class);
    router.attach("/collectionPrivate", CollectionPrivateREST.class);
    router.attach("/analysis", AnalysisREST.class);
    return router;
}
}

提前谢谢你,这是我第一次使用这个框架。

【问题讨论】:

  • 如果不了解 IdentiscopeServerApplication 和 IdentiscopeServer 类,很难提供帮助
  • 很抱歉。更新了帖子,见上文。
  • 我想查看这些类的代码,因为我相信所有其余的服务连接逻辑都在那里。您在问题中提供的代码来自一个非常抽象的层。
  • 有什么想法吗?只需忽略 IdentiscopeServerApplication 类上的注释“//将 /tweet 路径附加到 TweetRest 类”
  • restlet 代码通常会根据请求 URL 的上下文检测它部署的服务器。您希望如何部署应用程序?在 Servlet 容器中?使用其中一个 Restlet 引擎?

标签: java php rest web-hosting restlet


【解决方案1】:

如果我理解正确,您只想将 main() 方法作为服务器运行,对吗?在这种情况下,main() 的代码需要位于运行时可以在http://devweb2013.co.uk/research/Identiscope 提供服务的位置。由于您还没有说明要放置代码的服务器类型,因此我无法说出放置代码的最佳位置。我假设您在部署服务器上具有超级用户权限,因为您提供的 URL 意味着端口 80 将为您的 Identiscope Web 服务提供服务(端口 80 是大多数操作系统上的特权端口)。因此,作为答案,我只能提供一般信息。

在您的部署服务器上,端口 80 必须是空闲的(即,该机器上的端口 80 上不应有其他任何东西充当 Web 服务器)并且 IdentiscopeApplication 必须在端口 80 上运行。为此,您只需更改行:

server.getServers().add(Protocol.HTTP,8888);

到:

server.getServers().add(Protocol.HTTP, 80);

然后以允许在端口 80 上启动服务器的用户身份运行应用程序(最好不是超级用户)。如果您还没有,您需要在部署服务器上运行 Java,并确保所有 Restlet 库都在您计划运行应用程序的类路径中。

如果我理解你想要做什么,那么这应该可以解决问题。

【讨论】:

  • Snapman,非常感谢您的回复。我最近在服务器上遇到了一些问题,但是一旦我测试了你提出的建议,我会在这里发布它是否成功。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-07
  • 1970-01-01
  • 1970-01-01
  • 2020-02-12
  • 2021-10-07
相关资源
最近更新 更多