@@ -205,6 +205,15 @@ public Point maxPoint(MappingIterator<Point> points) throws IOException
205
205
return max ;
206
206
}
207
207
208
+ @ Path ("/echo" )
209
+ @ POST
210
+ @ Consumes (MediaType .APPLICATION_JSON )
211
+ @ Produces (MediaType .APPLICATION_JSON )
212
+ public Point echoPoint (Point point ) throws IOException
213
+ {
214
+ return point ;
215
+ }
216
+
208
217
private int _distance (Point p ) {
209
218
return (p .x * p .x ) + (p .y * p .y );
210
219
}
@@ -478,7 +487,54 @@ public void testMappingIterator() throws Exception
478
487
assertEquals (4 , p .y );
479
488
}
480
489
481
- // [Issue#34] Verify that Untouchables act the way as they should
490
+ // [jakarta-rs-providers#16]
491
+ public void testPointNoTrailingContent () throws Exception
492
+ {
493
+ final ObjectMapper mapper = new ObjectMapper ();
494
+ Server server = startServer (TEST_PORT , SimpleResourceApp .class );
495
+ Point p ;
496
+
497
+ try {
498
+ URL url = new URL ("http://localhost:" +TEST_PORT +"/point/echo" );
499
+
500
+ // First, content with no trailing stuff
501
+ HttpURLConnection conn = (HttpURLConnection ) url .openConnection ();
502
+ conn .setRequestProperty ("Accept" , MediaType .APPLICATION_JSON );
503
+ conn .setRequestProperty ("Content-Type" , MediaType .APPLICATION_JSON );
504
+ conn .setDoOutput (true );
505
+ conn .setRequestMethod ("POST" );
506
+ OutputStream out = conn .getOutputStream ();
507
+ out .write (a2q ("{'x':1,'y':1}" ).getBytes ("UTF-8" ));
508
+ out .close ();
509
+ assertEquals (200 , conn .getResponseCode ());
510
+ InputStream in = conn .getInputStream ();
511
+ p = mapper .readValue (in , Point .class );
512
+ in .close ();
513
+ // ensure we got a valid Point
514
+ assertNotNull (p );
515
+ assertEquals (1 , p .x );
516
+ assertEquals (1 , p .y );
517
+
518
+ // Then try with trailing token; not allowed
519
+ 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
+ out = conn .getOutputStream ();
525
+ out .write (a2q ("{'x':1,'y':1} 123 " ).getBytes ("UTF-8" ));
526
+ out .close ();
527
+
528
+ // Hmmh. Typically would be mapped to 400 but apparently JAX-RS default is 500
529
+ assertEquals (500 , conn .getResponseCode ());
530
+ in .close ();
531
+
532
+ } finally {
533
+ server .stop ();
534
+ }
535
+ }
536
+
537
+ // Verify that Untouchables act the way as they should
482
538
@ SuppressWarnings ("resource" )
483
539
public void testUntouchables () throws Exception
484
540
{
0 commit comments