2017-05-31 93 views
0

我有這樣的服務器代碼:捲曲球衣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 –

回答

0

至於你添加@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 –