Skip to content

Commit 43a9594

Browse files
committed
Add a crude test to verify #170
1 parent 82087b8 commit 43a9594

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

json/src/test/java/com/fasterxml/jackson/jaxrs/json/dw/SimpleEndpointTestBase.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,15 @@ public Point maxPoint(MappingIterator<Point> points) throws IOException
222222
return max;
223223
}
224224

225+
@Path("/echo")
226+
@POST
227+
@Consumes(MediaType.APPLICATION_JSON)
228+
@Produces(MediaType.APPLICATION_JSON)
229+
public Point echoPoint(Point point) throws IOException
230+
{
231+
return point;
232+
}
233+
225234
private int _distance(Point p) {
226235
return (p.x * p.x) + (p.y * p.y);
227236
}
@@ -496,6 +505,53 @@ public void testMappingIterator() throws Exception
496505
assertEquals(4, p.y);
497506
}
498507

508+
// [jaxrs-providers#108]
509+
public void testPointNoTrailingContent() throws Exception
510+
{
511+
final ObjectMapper mapper = new ObjectMapper();
512+
Server server = startServer(TEST_PORT, SimpleResourceApp.class);
513+
Point p;
514+
515+
try {
516+
URL url = new URL("http://localhost:"+TEST_PORT+"/point/echo");
517+
518+
// First, content with no trailing stuff
519+
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
520+
conn.setRequestProperty("Accept", MediaType.APPLICATION_JSON);
521+
conn.setRequestProperty("Content-Type", MediaType.APPLICATION_JSON);
522+
conn.setDoOutput(true);
523+
conn.setRequestMethod("POST");
524+
OutputStream out = conn.getOutputStream();
525+
out.write(aposToQuotes("{'x':1,'y':1}").getBytes("UTF-8"));
526+
out.close();
527+
assertEquals(200, conn.getResponseCode());
528+
InputStream in = conn.getInputStream();
529+
p = mapper.readValue(in, Point.class);
530+
in.close();
531+
// ensure we got a valid Point
532+
assertNotNull(p);
533+
assertEquals(1, p.x);
534+
assertEquals(1, p.y);
535+
536+
// Then try with trailing token; not allowed
537+
conn = (HttpURLConnection) url.openConnection();
538+
conn.setRequestProperty("Accept", MediaType.APPLICATION_JSON);
539+
conn.setRequestProperty("Content-Type", MediaType.APPLICATION_JSON);
540+
conn.setDoOutput(true);
541+
conn.setRequestMethod("POST");
542+
out = conn.getOutputStream();
543+
out.write(aposToQuotes("{'x':1,'y':1} 123 ").getBytes("UTF-8"));
544+
out.close();
545+
546+
// Hmmh. Typically would be mapped to 400 but apparently JAX-RS default is 500
547+
assertEquals(500, conn.getResponseCode());
548+
in.close();
549+
550+
} finally {
551+
server.stop();
552+
}
553+
}
554+
499555
// [Issue#34] Verify that Untouchables act the way as they should
500556
@SuppressWarnings("resource")
501557
public void testUntouchables() throws Exception

0 commit comments

Comments
 (0)