2222import jakarta .ws .rs .client .Entity ;
2323import jakarta .ws .rs .client .WebTarget ;
2424import jakarta .ws .rs .core .Application ;
25+ import jakarta .ws .rs .core .Feature ;
2526import jakarta .ws .rs .core .Response ;
2627import org .glassfish .jersey .client .ClientConfig ;
2728import org .glassfish .jersey .logging .LoggingFeature ;
2829import org .glassfish .jersey .server .ResourceConfig ;
2930import org .glassfish .jersey .test .JerseyTest ;
3031import org .junit .Test ;
3132
33+ import java .util .ArrayList ;
34+ import java .util .List ;
35+ import java .util .concurrent .ExecutionException ;
36+ import java .util .concurrent .Future ;
3237import java .util .logging .Logger ;
3338
3439import static org .junit .Assert .assertEquals ;
@@ -67,13 +72,11 @@ public Response postWithEntity(String entity) {
6772
6873 @ Test
6974 public void testPostError () {
70- WebTarget r = target ("test" );
75+ final WebTarget target = target ("test" );
7176
7277 for (int i = 0 ; i < 100 ; i ++) {
73- try {
74- r .request ().post (Entity .text ("POST" ));
75- } catch (ClientErrorException ex ) {
76- }
78+ final Response resp = target .request ().post (Entity .text ("POST" ));
79+ assertEquals (500 , resp .getStatus ());
7780 }
7881 }
7982
@@ -92,13 +95,18 @@ public void testPostErrorWithEntity() {
9295 }
9396
9497 @ Test
95- public void testPostErrorAsync () {
96- WebTarget r = target ("test" );
98+ public void testPostErrorAsync () throws ExecutionException , InterruptedException {
99+ final WebTarget target = target ("test" );
100+
101+ final List <Future <Response >> responses = new ArrayList <>(100 );
97102
98103 for (int i = 0 ; i < 100 ; i ++) {
99- try {
100- r .request ().async ().post (Entity .text ("POST" ));
101- } catch (ClientErrorException ex ) {
104+ responses .add (target .request ().async ().post (Entity .text ("POST" )));
105+ }
106+ for (int i = responses .size () - 1 ; i >= 0 ;) {
107+ if (responses .get (i ).isDone ()) {
108+ assertEquals (500 , responses .remove (i ).get ().getStatus ());
109+ i --;
102110 }
103111 }
104112 }
0 commit comments