@@ -222,6 +222,15 @@ public Point maxPoint(MappingIterator<Point> points) throws IOException
222
222
return max ;
223
223
}
224
224
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
+
225
234
private int _distance (Point p ) {
226
235
return (p .x * p .x ) + (p .y * p .y );
227
236
}
@@ -496,6 +505,53 @@ public void testMappingIterator() throws Exception
496
505
assertEquals (4 , p .y );
497
506
}
498
507
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
+
499
555
// [Issue#34] Verify that Untouchables act the way as they should
500
556
@ SuppressWarnings ("resource" )
501
557
public void testUntouchables () throws Exception
0 commit comments