如何从CURL

时间:2017-11-02 02:26:37

标签: java rest curl spring-boot

我在solaris盒上部署了一个简单的嵌入式tomcat springboot Java应用程序。 它有一些宁静的终点。它们无法通过互联网访问,因为它主要是一个Java应用程序。 所以Curl被用来访问宁静的端点。我的问题是如何访问端点。如何使用GET?

@Controller
public class TopicStatsController {

    @Autowired
    private QueueDepths depths;

    @RequestMapping("/topicDepth")
    @ResponseBody
    public Long topicDepth() throws Exception {
        return depths.topicDepth();
    }

    @RequestMapping("/subscribersDepth")
    @ResponseBody
    public List<Long> subscribersDepth() throws Exception {
        return depths.subscribersDepth();
    }

    @RequestMapping("/errorDepth")
    @ResponseBody
    public Long errorDepth() throws Exception {
        return depths.errorDepth();
    }

}

我在日志文件中看到的一些信息

org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-11-02 01:42:13,459 INFO  [main] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/purgeErrorQueues],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity<java.lang.String> com.bp.pnc.publisher.app.controller.ErrorQueueController.purgeErrorQueues(long)
2017-11-02 01:42:13,465 INFO  [main] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/timer],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Double com.bp.pnc.publisher.app.controller.MetricsController.timer(java.lang.String) throws java.lang.Exception
2017-11-02 01:42:13,466 INFO  [main] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/gauge],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object com.bp.pnc.publisher.app.controller.MetricsController.gauge(java.lang.String) throws java.lang.Exception
2017-11-02 01:42:13,467 INFO  [main] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/counter],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Long com.bp.pnc.publisher.app.controller.MetricsController.counter(java.lang.String) throws java.lang.Exception
2017-11-02 01:42:13,468 INFO  [main] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/metricNames],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.util.Set<java.lang.String> com.bp.pnc.publisher.app.controller.MetricsController.metricNames() throws java.lang.Exception
2017-11-02 01:42:13,471 INFO  [main] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/status],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public com.bp.pnc.publisher.app.domain.StatusDetail com.bp.pnc.publisher.app.controller.StatusInfoController.getStatus()
2017-11-02 01:42:13,475 INFO  [main] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/subscribersDepth],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.util.List<java.lang.Long> com.bp.pnc.publisher.app.controller.TopicStatsController.subscribersDepth() throws java.lang.Exception
2017-11-02 01:42:13,476 INFO  [main] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/topicDepth],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Long com.bp.pnc.publisher.app.controller.TopicStatsController.topicDepth() throws java.lang.Exception
2017-11-02 01:42:13,477 INFO  [main] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/errorDepth],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Long com.bp.pnc.publisher.app.controller.TopicStatsController.errorDepth() throws java.lang.Exception
2017-11-02 01:42:13,528 INFO  [main] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/error],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2017-11-02 01:42:13,530 INFO  [main] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/error],methods=[],params=[],headers=[],consumes=[],produces=[text/html],custom=[]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest)
2017-11-02 01:42:13,906 INFO  [main] org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-11-02 01:42:13,906 INFO  [main] org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-11-02 01:42:24,888 INFO  [main] org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping - Mapped "{[/info],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-11-02 01:42:24,895 INFO  [main] org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping - Mapped "{[/metrics/{name:.*}],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.MetricsMvcEndpoint.value(java.lang.String)
2017-11-02 01:42:24,895 INFO  [main] org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping - Mapped "{[/metrics],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-11-02 01:42:24,897 INFO  [main] org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping - Mapped "{[/autoconfig],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-11-02 01:42:24,898 INFO  [main] org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping - Mapped "{[/beans],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-11-02 01:42:24,899 INFO  [main] org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping - Mapped "{[/mappings],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-11-02 01:42:24,900 INFO  [main] org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping - Mapped "{[/trace],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-11-02 01:42:24,901 INFO  [main] org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping - Mapped "{[/configprops],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-11-02 01:42:24,904 INFO  [main] org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping - Mapped "{[/env/{name:.*}],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EnvironmentMvcEndpoint.value(java.lang.String)
2017-11-02 01:42:24,905 INFO  [main] org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping - Mapped "{[/env],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-11-02 01:42:24,906 INFO  [main] org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping - Mapped "{[/dump],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-11-02 01:42:24,909 INFO  [main] org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping - Mapped "{[/he

1 个答案:

答案 0 :(得分:1)

为在本地计算机上运行的Web应用程序创建的URL通常采用以下格式:http://localhost:[PORT]/[CONTEXTPAHT]/[CONTROLLER_PATH]

如果应用程序在8080上运行且没有设置上下文路径,那么该网址将变为http://localhost:8080/topicDepth,依此类推