繁体   English   中英

Dropwizard REST:由于某种原因,获取请求被重定向302

[英]Dropwizard REST: Get request is being redirected 302 for some reason

我按照此处的教程使用Dropwizard构建了REST服务器。 服务器应提供一项服务-显示Hello world消息。

这是我启动时的输出:

c:\\ Users \\ administrator \\ Eclipse工作区\\ Web \\ DropwizardExample> java -jar target \\ DropwizardExample-0.0.1-SNAPSHOT.jar服务器src \\ main \\ resources \\ hello-world.yml信息[2016-06-15 12:21 :45,341]

org.eclipse.jetty.util.log:记录初始化为@ 1464ms INFO [2016-06-15 12:21:45,449] io.dropwizard.server.ServerFactory:启动hello-world INFO [2016-06-15 12:21: 45,459] io.dropwizard.server.SimpleServerFactory:注册带有根路径前缀的球衣处理程序:/ hello-world INFO [2016-06-15 12:21:45,477] io.dropwizard.server.SimpleServerFactory:使用根路径前缀注册管理处理程序:/ admin INFO [2016-06-15 12:21:45,522] org.eclipse.jetty.setuid.SetUIDListener:已打开hello-world @ 17d2e85 {HTTP / 1.1} {0.0.0.0:8080} INFO [2016-06- 15 12:21:45,525] org.eclipse.jetty.server.Server:jetty-9.2.z-SNAPSHOT INFO [2016-06-15 12:21:46,207] io.dropwizard.jersey.DropwizardResourceConfig:找到了以下路径对于配置的资源:

 GET /hello-world (com.HelloWorldResource) 

信息[2016-06-15 12:21:46,208] org.eclipse.jetty.server.handler.ContextHandler:已启动idjMutableServletContextHandler @ 18f8a80 {/ hello-world,null,AVAILABLE}信息[2016-06-15 12:21: 46,214] io.dropwizard.setup.AdminEnvironment:任务=

 POST /tasks/log-level (io.dropwizard.servlets.tasks.LogConfigurationTask) POST /tasks/gc (io.dropwizard.servlets.tasks.GarbageCollectionTask) 

信息[2016-06-15 12:21:46,219] org.eclipse.jetty.server.handler.ContextHandler:已启动idjMutableServletContextHandler @ 1ab9dd6 {/ admin,null,AVAILA BLE}信息[2016-06-15 12:21:46,293 ] org.eclipse.jetty.server.ServerConnector:已启动hello-world @ 17d2e85 {HTTP / 1.1} {0.0.0.0:8080}信息[2016-06-15 12:21:46,293] org.eclipse.jetty.server。服务器:@ 2417ms启动

yml文件如下:

template: Hello, %s!
defaultName: Stranger

server:
  type: simple
  applicationContextPath: /hello-world
  adminContextPath: /admin
  connector:
    type: http
    port: 8080

当我尝试去

http:// localhost:8080 / hello-world

在IE或Chrome上,它在地址末尾添加另一个斜杠并产生:

127.0.0.1--[15 / Jun / 2016:12:26:48 +0000]“ GET / hello-world HTTP / 1.1” 302 -“-”“ Mozilla / 4.0(兼容; MSIE 8.0; Windows NT 6.1; WOW64 ; Trident / 4。0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E)” 3

127.0.0.1--[15 / Jun / 2016:12:26:48 +0000]“ GET / hello-world / HTTP / 1.1” 404 43“-”“ Mozilla / 4.0(兼容; MSIE 8.0; Windows NT 6.1; WOW64; Trident / 4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E)“” 3

在控制台上。

如果我在末尾手动添加斜杠,则直接得到404。

你能帮忙吗?

好吧,我理解了这个问题。 我将以下内容添加到yml文件中:

server:
  type: simple
  applicationContextPath: /hello-world
  adminContextPath: /admin
  connector:
    type: http
    port: 7777

好吧,我不确定我为什么会理解completley,但是看来这里不需要一台简单的服务器,而是默认的服务器。 因此,删除此段后,我收到200 OK。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM