卷曲球衣GET不会得到服务器

问题描述:

我有这样的服务器代码:卷曲球衣GET不会得到服务器

@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"; 
    } 

主办的嵌入式码头:

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

我尝试curl命令并没有看到任何断点停在服务器上。我错过了什么?

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

当我通过浏览器中调用我得到:

HTTP ERROR: 503 

Problem accessing /Sdk/test. Reason: 

    Service Unavailable 
Powered by Jetty:// 9.3.15.v20161220 
+0

你能够通过浏览器来接取它,写一些登录测试,然后检查 – gladiator

+0

不要使用需要设置WebAppContext的战争位置? –

+0

@gladiator我得到:HTTP错误:503 问题访问/ Sdk /测试。原因: 服务不可用 Powered by Jetty:// 9.3.15.v20161220 –

至于你添加@Produces(MediaType.TEXT_PLAIN)你应该添加-H "Content-Type:text/xml"卷曲命令

curl -H "Content-Type:text/xml" http://localhost:8083/Sdk/test 
+0

但即使当我通过浏览器调用时,我得到:HTTP错误:503 访问/ SDK /测试。原因: 服务不可用 Powered by Jetty:// 9.3.15.v20161220 –