Search code examples
osgiportapache-karafspring-restcontrollerapache-servicemix

servicemix: on which port is my osgi bundle listening?


As a newby to servicemix/karaf, I'm trying to create a very simple program that accepts and returns a REST-request. The class I have is:

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);
    }

}

I've got something similar working in Tomcat. In Tomcat, you would specify the port where it will listen to incoming requests by doubleclicking on the server in eclipse and setting a value in the "Ports" section. How do I set the port in Servicemix, or even figure out which port it's currently listening to? I have the bundle succesfully starting from the command line in Servicemix. My application doesn't seem to be listening on 80 (Apache), 8080 (None), or 8181 (Servicemix console)


Solution

  • First of all make sure you have the web-container deployed. For this make sure the war feature is installed.

    feature:list | grep war
    

    if it's not installed, install it by issueing:

    feature:install war
    

    Now, make sure your jar/war contains the Web-ContextPath Manifest entry telling the web-container which context path to look for. If you have all other required bundles installed and running, including all dependencies are set you should be able to navigate to your rest service on:

     localhost:8181/myContextPath/rest/document