-
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
415 unsupported media type when using mount to add routes
- Loading branch information
Showing
7 changed files
with
184 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Jooby https://jooby.io | ||
* Apache License Version 2.0 https://jooby.io/LICENSE.txt | ||
* Copyright 2014 Edgar Espina | ||
*/ | ||
package io.jooby.i3400; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import io.jooby.Jooby; | ||
import io.jooby.jackson.JacksonModule; | ||
import io.jooby.junit.ServerTest; | ||
import io.jooby.junit.ServerTestRunner; | ||
import okhttp3.MediaType; | ||
import okhttp3.RequestBody; | ||
|
||
public class Issue3400 { | ||
|
||
static class AppA extends Jooby { | ||
{ | ||
post("/pets", ctx -> ctx.body(Pet3400.class)); | ||
} | ||
} | ||
|
||
@ServerTest | ||
public void shouldShareDecodersOnMountedResources(ServerTestRunner runner) { | ||
runner | ||
.define( | ||
app -> { | ||
app.install(new JacksonModule()); | ||
app.mount(new AppA()); | ||
}) | ||
.ready( | ||
http -> { | ||
http.post( | ||
"/pets", | ||
RequestBody.create( | ||
"{\"id\": 1, \"name\": \"Cheddar\"}", MediaType.parse("application/json")), | ||
rsp -> { | ||
assertEquals("{\"id\":1,\"name\":\"Cheddar\"}", rsp.body().string()); | ||
assertEquals("application/json;charset=UTF-8", rsp.header("Content-Type")); | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Jooby https://jooby.io | ||
* Apache License Version 2.0 https://jooby.io/LICENSE.txt | ||
* Copyright 2014 Edgar Espina | ||
*/ | ||
package io.jooby.i3400; | ||
|
||
public class Pet3400 { | ||
private int id; | ||
private String name; | ||
|
||
public Pet3400(int id, String name) { | ||
this.id = id; | ||
this.name = name; | ||
} | ||
|
||
public int getId() { | ||
return id; | ||
} | ||
|
||
public void setId(int id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Jooby https://jooby.io | ||
* Apache License Version 2.0 https://jooby.io/LICENSE.txt | ||
* Copyright 2014 Edgar Espina | ||
*/ | ||
package io.jooby.i3500; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import io.jooby.junit.ServerTest; | ||
import io.jooby.junit.ServerTestRunner; | ||
import okhttp3.MediaType; | ||
import okhttp3.RequestBody; | ||
|
||
public class Issue3500 { | ||
|
||
@ServerTest | ||
public void shouldShareDecodersOnMountedResources(ServerTestRunner runner) { | ||
runner | ||
.use(WidgetService::new) | ||
.ready( | ||
http -> { | ||
http.post( | ||
"/api/widgets1", | ||
RequestBody.create("{\"id\": 1}", MediaType.get("application/json")), | ||
rsp -> { | ||
assertEquals(201, rsp.code()); | ||
}); | ||
http.post( | ||
"/api/widgets2", | ||
RequestBody.create("{\"id\": 1}", MediaType.get("application/json")), | ||
rsp -> { | ||
assertEquals(201, rsp.code()); | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Jooby https://jooby.io | ||
* Apache License Version 2.0 https://jooby.io/LICENSE.txt | ||
* Copyright 2014 Edgar Espina | ||
*/ | ||
package io.jooby.i3500; | ||
|
||
public class Widget { | ||
private int id; | ||
|
||
public int getId() { | ||
return id; | ||
} | ||
|
||
public void setId(int id) { | ||
this.id = id; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Jooby https://jooby.io | ||
* Apache License Version 2.0 https://jooby.io/LICENSE.txt | ||
* Copyright 2014 Edgar Espina | ||
*/ | ||
package io.jooby.i3500; | ||
|
||
import io.jooby.Jooby; | ||
import io.jooby.StatusCode; | ||
import io.jooby.gson.GsonModule; | ||
|
||
public class WidgetService extends Jooby { | ||
|
||
public WidgetService() { | ||
install(new GsonModule()); | ||
|
||
post( | ||
"/api/widgets1", | ||
ctx -> { | ||
Widget widget = ctx.body().to(Widget.class); | ||
System.out.println("Created " + widget); | ||
return ctx.send(StatusCode.CREATED); | ||
}); | ||
|
||
mount(new WidgetRouter()); | ||
} | ||
|
||
public static void main(String[] args) { | ||
new WidgetService().start(); | ||
} | ||
} | ||
|
||
class WidgetRouter extends Jooby { | ||
|
||
public WidgetRouter() { | ||
|
||
post( | ||
"/api/widgets2", | ||
ctx -> { | ||
Widget widget = ctx.body().to(Widget.class); | ||
return ctx.send(StatusCode.CREATED); | ||
}); | ||
} | ||
} |