0

I have this server code:

@Path("/Sdk")
public class SdkOperation {


    private final CofmanService cofmanService;

    public SdkOperation() throws Exception {
        this(new CofmanServiceNet());
    }

    @VisibleForTesting
    public SdkOperation(CofmanService cofmanServiceNet) throws Exception {
        this.cofmanService = cofmanServiceNet;
//        SdkServiceConfig.s.initLog();
//        logger.info("SdkServiceConfig.s.LOG4J_PATH= " + SdkServiceConfig.s.LOG4J_PATH);

    }

    @Context
    ServletContext context;

    @Context
    HttpHeaders httpHeaders;

    @Path("/test")
    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String test() {
        return "in SDK Operation test";
    }

hosted by embedded Jetty:

public class ServerRunner {

    private final static org.apache.log4j.Logger logger = LoggingUtils.getLogger();

    public static void main(String[] args) throws Exception {
        SdkServiceConfig.s.initLog();


        final int port = 8083;

        final Server jettyServer = new Server(port);
        final HandlerCollection handlers = new HandlerCollection();

        // Creating the first web application context
        final WebAppContext webappContext = new WebAppContext();


        webappContext.setExtractWAR(false);
        handlers.addHandler(webappContext);

        // Adding the handlers to the server.
        jettyServer.setHandler(handlers);

        try {
            jettyServer.start();
            jettyServer.join();
        } catch (Exception ex) {
            logger.error("failed to init jetty server", ex);
        } finally {
            jettyServer.destroy();
        }
    }       
}

I try curl command and don't see any breakpoint stop on the server. What am I missing?

curl http://localhost:8083/Sdk/test

When i call via browser i get:

HTTP ERROR: 503

Problem accessing /Sdk/test. Reason:

    Service Unavailable
Powered by Jetty:// 9.3.15.v20161220
Elad Benda2
  • 13,852
  • 29
  • 82
  • 157

1 Answers1

0

As far as you add @Produces(MediaType.TEXT_PLAIN) you should add -H "Content-Type:text/xml" to curl command

curl -H "Content-Type:text/xml" http://localhost:8083/Sdk/test
Mike Adamenko
  • 2,944
  • 1
  • 15
  • 28
  • but even when i call via browser i get: HTTP ERROR: 503 Problem accessing /Sdk/test. Reason: Service Unavailable Powered by Jetty:// 9.3.15.v20161220 – Elad Benda2 May 31 '17 at 19:19