简体   繁体   English

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

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

I built a REST server using Dropwizard following their tutorial here . 我按照此处的教程使用Dropwizard构建了REST服务器。 The server should serve a single service - display Hello world message. 服务器应提供一项服务-显示Hello world消息。

This is the output when I launched it: 这是我启动时的输出:

c:\\Users\\administrator\\Eclipse workspaces\\Web\\DropwizardExample>java -jar target\\DropwizardExample-0.0.1-SNAPSHOT.jar server src\\main\\resources\\hello-world.yml INFO [2016-06-15 12:21:45,341] 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: Logging initialized @1464ms INFO [2016-06-15 12:21:45,449] io.dropwizard.server.ServerFactory: Starting hello-world INFO [2016-06-15 12:21:45,459] io.dropwizard.server.SimpleServerFactory: Registering jersey handler with root path prefix: /hello-world INFO [2016-06-15 12:21:45,477] io.dropwizard.server.SimpleServerFactory: Registering admin handler with root path prefix: /admin INFO [2016-06-15 12:21:45,522] org.eclipse.jetty.setuid.SetUIDListener: Opened 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: The following paths were found for the configured resources: 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) 

INFO [2016-06-15 12:21:46,208] org.eclipse.jetty.server.handler.ContextHandler: Started idjMutableServletContextHandler@18f8a80{/hello-world,null, AVAILABLE} INFO [2016-06-15 12:21:46,214] io.dropwizard.setup.AdminEnvironment: tasks = 信息[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) 

INFO [2016-06-15 12:21:46,219] org.eclipse.jetty.server.handler.ContextHandler: Started idjMutableServletContextHandler@1ab9dd6{/admin,null,AVAILA BLE} INFO [2016-06-15 12:21:46,293] org.eclipse.jetty.server.ServerConnector: Started hello-world@17d2e85{HTTP/1.1}{0.0.0.0:8080} INFO [2016-06-15 12:21:46,293] org.eclipse.jetty.server.Server: Started @2417ms 信息[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启动

The yml file is as follows: yml文件如下:

template: Hello, %s!
defaultName: Stranger

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

When I try to go to 当我尝试去

http://localhost:8080/hello-world http:// localhost:8080 / hello-world

On IE or Chrome, it adds another slash at the end of the address and yields: 在IE或Chrome上,它在地址末尾添加另一个斜杠并产生:

127.0.0.1 - - [15/Jun/2016:12:26:48 +0000] "GET /hello-world HTTP/1.1" 302 - "-" "Mozilla/4.0 (compatible; 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” 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 (compatible; 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

at the console. 在控制台上。

If I manually add the slash at the end, it directly gives me 404. 如果我在末尾手动添加斜杠,则直接得到404。

Can you assist please? 你能帮忙吗?

Well, I understood the problem. 好吧,我理解了这个问题。 I added the following to the yml file: 我将以下内容添加到yml文件中:

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

Well, I am not sure I understood completley why, but it appears to be that a simple server is not required here, but the default one. 好吧,我不确定我为什么会理解completley,但是看来这里不需要一台简单的服务器,而是默认的服务器。 So after removing this segment, I recieved 200 OK. 因此,删除此段后,我收到200 OK。

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

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