簡體   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