Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CXF-8233: Wrong response code in case of error #648

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1535,6 +1535,12 @@ public void onewayRequest() {
}
}

@POST
@Path("/oneway/propogateExceptionVar/{i}")
@Oneway
public void onewayRequestPropogateExceptionWithVar() {
}

@POST
@Path("/books/customstatus")
@Produces("application/xml")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ public void testGetBookSameUriAutoRedirect() throws Exception {
String theCookie = r.getStringHeaders().getFirst("TheCookie");
assertEquals("b", theCookie);
}

@Test
public void testGetBookDiffUriAutoRedirect() throws Exception {
String address = "http://localhost:" + PORT + "/bookstore/redirect?sameuri=false";
Expand All @@ -254,8 +253,6 @@ public void testGetBookDiffUriAutoRedirect() throws Exception {
assertTrue(cause.getMessage().contains("Different HTTP Scheme or Host Redirect detected on"));
}
}


@Test
public void testGetBookRelativeUriAutoRedirect() throws Exception {
String address = "http://localhost:" + PORT + "/bookstore/redirect/relative?loop=false";
Expand All @@ -270,7 +267,6 @@ public void testGetBookRelativeUriAutoRedirect() throws Exception {
String newAddress = "http://localhost:" + PORT + "/bookstore/redirect/relative?redirect=true";
assertEquals(newAddress, wc.getCurrentURI().toString());
}

@Test
public void testGetBookRelativeUriAutoRedirectLoop() throws Exception {
String address = "http://localhost:" + PORT + "/bookstore/redirect/relative?loop=true";
Expand All @@ -285,7 +281,6 @@ public void testGetBookRelativeUriAutoRedirectLoop() throws Exception {
assertTrue(cause.getMessage().contains("Redirect loop detected on"));
}
}

@Test
public void testGetBookRelativeUriAutoRedirectNotAllowed() throws Exception {
String address = "http://localhost:" + PORT + "/bookstore/redirect/relative?loop=true";
Expand Down Expand Up @@ -366,7 +361,6 @@ public void testGetCustomBookBufferedResponse() {
assertEquals("OK", r.getHeaderString("customresponse"));
}


@Test
public void testGetCustomBookText() {
String address = "http://localhost:" + PORT + "/bookstore/customtext";
Expand Down Expand Up @@ -436,7 +430,6 @@ private void doTestUseParamBeanWebClient(String address) {
assertEquals(123L, book.getId());
}


@Test
public void testGetIntroChapterFromSelectedBook() {
String address = "http://localhost:" + PORT + "/bookstore/books(id=le=123)/chapter";
Expand All @@ -454,7 +447,6 @@ public void testGetIntroChapterFromSelectedBook2() {
}

private void doTestGetChapterFromSelectedBook(String address) {

WebClient wc = WebClient.create(address);
wc.accept("application/xml");
Chapter chapter = wc.get(Chapter.class);
Expand Down Expand Up @@ -582,9 +574,7 @@ public void testGetBookWithCustomHeader() throws Exception {

@Test
public void testGetBookWithNameInQuery() throws Exception {

String endpointAddress =
"http://localhost:" + PORT + "/bookstore/name-in-query";
String endpointAddress = "http://localhost:" + PORT + "/bookstore/name-in-query";
WebClient wc = WebClient.create(endpointAddress);
String name = "Many spaces";
wc.query("name", name);
Expand All @@ -594,9 +584,7 @@ public void testGetBookWithNameInQuery() throws Exception {

@Test
public void testGetBookAsObject() throws Exception {

String endpointAddress =
"http://localhost:" + PORT + "/bookstore/object";
String endpointAddress = "http://localhost:" + PORT + "/bookstore/object";
WebClient wc = WebClient.create(endpointAddress);
Book b = wc.get(Book.class);
assertEquals("Book as Object", b.getName());
Expand All @@ -618,7 +606,6 @@ public void testProcessingInstruction() throws Exception {

@Test
public void testGetBookWithColonMarks() throws Exception {

// URLEncoder will turn ":" into "%3A" but ':' is actually
// not disallowed in the path components
String endpointAddressUrlEncoded =
Expand All @@ -628,18 +615,15 @@ public void testGetBookWithColonMarks() throws Exception {
Response r = WebClient.create(endpointAddressUrlEncoded).get();
assertEquals(404, r.getStatus());

String endpointAddress =
"http://localhost:" + PORT + "/bookstore/books/colon/1:2:3";
String endpointAddress = "http://localhost:" + PORT + "/bookstore/books/colon/1:2:3";
WebClient wc = WebClient.create(endpointAddress);
Book b = wc.get(Book.class);
assertEquals(123L, b.getId());
}

@Test
public void testPostAnd401WithText() throws Exception {

String endpointAddress =
"http://localhost:" + PORT + "/bookstore/post401";
String endpointAddress = "http://localhost:" + PORT + "/bookstore/post401";
WebClient wc = WebClient.create(endpointAddress);
WebClient.getConfig(wc).getHttpConduit().getClient().setAllowChunking(false);
assertFalse(WebClient.getConfig(wc).getHttpConduit().getClient().isAllowChunking());
Expand All @@ -651,29 +635,23 @@ public void testPostAnd401WithText() throws Exception {

@Test
public void testCapturedServerInFault() throws Exception {

String endpointAddress =
"http://localhost:" + PORT + "/bookstore/infault";
String endpointAddress = "http://localhost:" + PORT + "/bookstore/infault";
WebClient wc = WebClient.create(endpointAddress);
Response r = wc.get();
assertEquals(401, r.getStatus());
}

@Test
public void testCapturedServerOutFault() throws Exception {

String endpointAddress =
"http://localhost:" + PORT + "/bookstore/outfault";
String endpointAddress = "http://localhost:" + PORT + "/bookstore/outfault";
WebClient wc = WebClient.create(endpointAddress);
Response r = wc.get();
assertEquals(403, r.getStatus());
}

@Test
public void testGetCollectionOfBooks() throws Exception {

String endpointAddress =
"http://localhost:" + PORT + "/bookstore/collections";
String endpointAddress = "http://localhost:" + PORT + "/bookstore/collections";
WebClient wc = WebClient.create(endpointAddress);
wc.accept("application/xml");
Collection<? extends Book> collection = wc.getCollection(Book.class);
Expand All @@ -684,9 +662,7 @@ public void testGetCollectionOfBooks() throws Exception {

@Test
public void testPostCollectionGetBooksWebClient() throws Exception {

String endpointAddress =
"http://localhost:" + PORT + "/bookstore/collections3";
String endpointAddress = "http://localhost:" + PORT + "/bookstore/collections3";
WebClient wc = WebClient.create(endpointAddress);
wc.accept("application/xml").type("application/xml");
Book b1 = new Book("CXF in Action", 123L);
Expand All @@ -702,9 +678,7 @@ public void testPostCollectionGetBooksWebClient() throws Exception {

@Test
public void testPostCollectionGenericEntityWebClient() throws Exception {

String endpointAddress =
"http://localhost:" + PORT + "/bookstore/collections3";
String endpointAddress = "http://localhost:" + PORT + "/bookstore/collections3";
WebClient wc = WebClient.create(endpointAddress);
wc.accept("application/xml").type("application/xml");
Book b1 = new Book("CXF in Action", 123L);
Expand All @@ -724,7 +698,6 @@ public void testPostCollectionGenericEntityWebClient() throws Exception {

@Test
public void testPostGetCollectionGenericEntityAndType() throws Exception {

String endpointAddress =
"http://localhost:" + PORT + "/bookstore/collections";
WebClient wc = WebClient.create(endpointAddress);
Expand Down Expand Up @@ -757,7 +730,6 @@ public void testPostGetCollectionGenericEntityAndType() throws Exception {

@Test
public void testPostCollectionOfBooksWebClient() throws Exception {

String endpointAddress =
"http://localhost:" + PORT + "/bookstore/collections";
WebClient wc = WebClient.create(endpointAddress);
Expand All @@ -782,18 +754,15 @@ public void testPostCollectionOfBooksWebClient() throws Exception {

@Test
public void testPostNullGetEmptyCollectionProxy() throws Exception {

String endpointAddress = "http://localhost:" + PORT;
BookStore bs = JAXRSClientFactory.create(endpointAddress, BookStore.class);
List<Book> books = bs.postBookGetCollection(null);
assertNotNull(books);
assertEquals(0, books.size());

}

@Test
public void testPostObjectGetCollection() throws Exception {

String endpointAddress =
"http://localhost:" + PORT + "/bookstore/collectionBook";
WebClient wc = WebClient.create(endpointAddress);
Expand All @@ -809,7 +778,6 @@ public void testPostObjectGetCollection() throws Exception {

@Test
public void testCaching() throws Exception {

String endpointAddress =
"http://localhost:" + PORT + "/bookstore/books/response/123";

Expand Down Expand Up @@ -850,7 +818,6 @@ public void testCaching() throws Exception {

@Test
public void testCachingExpires() throws Exception {

String endpointAddress =
"http://localhost:" + PORT + "/bookstore/books/response2/123";

Expand Down Expand Up @@ -893,7 +860,6 @@ public void testCachingExpires() throws Exception {

@Test
public void testCachingExpiresUsingETag() throws Exception {

String endpointAddress =
"http://localhost:" + PORT + "/bookstore/books/response3/123";

Expand Down Expand Up @@ -934,7 +900,6 @@ public void testCachingExpiresUsingETag() throws Exception {
cacheControlFeature.close();
}


@Test
public void testOnewayWebClient() throws Exception {
WebClient client = WebClient.create("http://localhost:" + PORT + "/bookstore/oneway");
Expand Down Expand Up @@ -1113,14 +1078,21 @@ public void testSetManyCookiesWebClient() throws Exception {
assertTrue("Did not contain dummy2", hasDummy2);
}


@Test
public void testOnewayProxy() throws Exception {
BookStore proxy = JAXRSClientFactory.create("http://localhost:" + PORT, BookStore.class);
proxy.onewayRequest();
assertEquals(202, WebClient.client(proxy).getResponse().getStatus());
}

@Test
public void testOnewayPropogateExceptionVar() throws Exception {
final String endpointAddress = "http://localhost:" + PORT + "/bookstore/oneway/propogateExceptionVar/1";
WebClient wc = WebClient.create(endpointAddress);
Response r = wc.post(null);
assertEquals(500, r.getStatus());
}

@Test
public void testProxyWithCollectionMatrixParams() throws Exception {
BookStore proxy = JAXRSClientFactory.create("http://localhost:" + PORT, BookStore.class);
Expand Down Expand Up @@ -2676,7 +2648,6 @@ public void testGetPlainLong() throws Exception {
}
}


@Test
public void testMutipleAcceptHeader() throws Exception {
String endpointAddress =
Expand Down Expand Up @@ -2923,7 +2894,6 @@ public void testGetBookWithServerWebApplicationExceptionAndReaderInterceptor() t
}
}


private ReaderInterceptor getReaderInterceptor() {
return readerInterceptorContext -> {
InputStream is = new BufferedInputStream(readerInterceptorContext.getInputStream());
Expand All @@ -2932,7 +2902,6 @@ private ReaderInterceptor getReaderInterceptor() {
};
}


private void getAndCompareAsStrings(String address,
String resourcePath,
String acceptType,
Expand Down Expand Up @@ -2990,11 +2959,7 @@ private String stripXmlInstructionIfNeeded(String str) {
return str;
}



private String getStringFromInputStream(InputStream in) throws Exception {
return IOUtils.toString(in);
}


}