【问题标题】:servicemix: on which port is my osgi bundle listening?servicemix:我的 osgi bundle 在哪个端口上监听?
【发布时间】:2016-08-12 22:56:55
【问题描述】:

作为 servicemix/karaf 的新手,我正在尝试创建一个非常简单的程序来接受并返回 REST 请求。我的课程是:

package (....)

import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import (...).model.RSDocument;
import (...).model.RSDocumentResponse;

@RestController
public class DocumentService {

    @RequestMapping(value = "/rest/document", method = RequestMethod.POST,
            produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody ResponseEntity<RSDocumentResponse> printDocument(
            @RequestBody RSDocument documentRequest)
    {
        System.out.println(documentRequest.getContent());
        RSDocumentResponse response = new RSDocumentResponse();
        response.setSuccess(true);
        return new ResponseEntity<>(response, HttpStatus.OK);
    }

}

我在 Tomcat 中也有类似的工作。在 Tomcat 中,您可以通过在 eclipse 中双击服务器并在“端口”部分中设置一个值来指定它将侦听传入请求的端口。如何在 Servicemix 中设置端口,甚至找出它当前正在侦听的端口?我从 Servicemix 中的命令行成功地启动了捆绑包。我的应用程序似乎没有在 80(Apache)、8080(无)或 8181(Servicemix 控制台)上监听

【问题讨论】:

  • 如何打包和部署应用程序。我猜你有不止这一门课

标签: osgi port apache-karaf spring-restcontroller apache-servicemix


【解决方案1】:

首先确保您已部署网络容器。为此,请确保安装了战争功能。

feature:list | grep war

如果未安装,请通过以下命令安装:

feature:install war

现在,确保您的 jar/war 包含 Web-ContextPath 清单条目,告诉 Web 容器要查找哪个上下文路径。如果您安装并运行了所有其他必需的捆绑包,包括所有依赖项都已设置,您应该能够导航到您的休息服务:

 localhost:8181/myContextPath/rest/document

【讨论】:

  • 也许值得指出的是,Karaf 依赖 Jetty 作为 Web 容器,并且配置(如连接器的端口)可以通过 $KARAF_HOME/etc 中的 jetty.xml 进行更改。
  • @Ralf,这实际上只对了一半......因为它是一个 OSGi Http 服务,配置它的首选方法是使用 osgi 服务属性:org.osgi.service.http.port
  • 我没有清单文件,我们在另一个(工作)项目中也没有清单文件。我可以在其他地方包含 Web-ContextPath 吗?也许是 blueprint.xml 或 pom.xml?
  • 没关系,我已经让它工作了,没有上下文路径
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-07-12
  • 1970-01-01
  • 1970-01-01
  • 2014-11-01
  • 2014-11-04
  • 1970-01-01
  • 2013-12-03
相关资源
最近更新 更多