我有这个服务器代码:
@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";
}
由嵌入式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();
}
}
}
我尝试使用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 :(得分:0)
如果您添加@Produces(MediaType.TEXT_PLAIN)
,则应将-H "Content-Type:text/xml"
添加到curl命令
curl -H "Content-Type:text/xml" http://localhost:8083/Sdk/test