Skip to content
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 @@ -36,7 +36,6 @@

import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.cxf.Bus;
Expand Down Expand Up @@ -120,7 +119,6 @@ public abstract class AbstractHTTPDestination
protected boolean fixedParameterOrder;
protected boolean multiplexWithAddress;
protected CertConstraints certConstraints;
protected boolean isServlet3;
protected boolean decodeBasicAuthWithIso8859;
protected ContinuationProviderFactory cproviderFactory;
protected boolean enableWebSocket;
Expand All @@ -147,12 +145,6 @@ public AbstractHTTPDestination(Bus b,
this.bus = b;
this.registry = registry;
this.path = path;
try {
ServletRequest.class.getMethod("isAsyncSupported");
isServlet3 = true;
} catch (Throwable t) {
//servlet 2.5 or earlier, no async support
}
decodeBasicAuthWithIso8859 = PropertyUtils.isTrue(bus.getProperty(DECODE_BASIC_AUTH_WITH_ISO8859));

initConfig();
Expand Down Expand Up @@ -513,39 +505,20 @@ private String setEncoding(final Message inMessage,
return contentType;
}
protected Message retrieveFromContinuation(HttpServletRequest req) {
if (!isServlet3) {
if (cproviderFactory != null) {
return cproviderFactory.retrieveFromContinuation(req);
}
return null;
}
return retrieveFromServlet3Async(req);
}

protected Message retrieveFromServlet3Async(HttpServletRequest req) {
try {
return (Message)req.getAttribute(CXF_CONTINUATION_MESSAGE);
} catch (Throwable ex) {
// the request may not implement the Servlet3 API
}
return null;
return (Message)req.getAttribute(CXF_CONTINUATION_MESSAGE);
}

protected void setupContinuation(Message inMessage,
final HttpServletRequest req,
final HttpServletResponse resp) {
try {
if (isServlet3 && req.isAsyncSupported()) {
inMessage.put(ContinuationProvider.class.getName(),
new Servlet3ContinuationProvider(req, resp, inMessage));
} else if (cproviderFactory != null) {
ContinuationProvider p = cproviderFactory.createContinuationProvider(inMessage, req, resp);
if (p != null) {
inMessage.put(ContinuationProvider.class.getName(), p);
}
if (req.isAsyncSupported()) {
inMessage.put(ContinuationProvider.class.getName(),
new Servlet3ContinuationProvider(req, resp, inMessage));
} else if (cproviderFactory != null) {
ContinuationProvider p = cproviderFactory.createContinuationProvider(inMessage, req, resp);
if (p != null) {
inMessage.put(ContinuationProvider.class.getName(), p);
}
} catch (Throwable ex) {
// the request may not implement the Servlet3 API
}
}
protected String getBasePath(String contextPath) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import jakarta.servlet.WriteListener;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.cxf.common.classloader.ClassLoaderUtils;
import org.apache.cxf.common.util.PropertyUtils;
import org.apache.cxf.continuations.Continuation;
import org.apache.cxf.continuations.ContinuationCallback;
Expand All @@ -40,22 +39,10 @@
*
*/
public class Servlet3ContinuationProvider implements ContinuationProvider {
static final boolean IS_31;
static {
boolean is31;
try {
ClassLoaderUtils.loadClass("jakarta.servlet.WriteListener", HttpServletRequest.class);
is31 = true;
} catch (Throwable t) {
is31 = false;
}
IS_31 = is31;
}

HttpServletRequest req;
HttpServletResponse resp;
Message inMessage;
Servlet3Continuation continuation;
Servlet31Continuation continuation;

public Servlet3ContinuationProvider(HttpServletRequest req,
HttpServletResponse resp,
Expand All @@ -80,14 +67,14 @@ public Continuation getContinuation() {
}

if (continuation == null) {
continuation = IS_31 ? new Servlet31Continuation() : new Servlet3Continuation();
continuation = new Servlet31Continuation();
} else {
continuation.startAsyncAgain();
}
return continuation;
}

public class Servlet3Continuation implements Continuation, AsyncListener {
public class Servlet31Continuation implements Continuation, AsyncListener {
private static final String BLOCK_RESTART = "org.apache.cxf.continuation.block.restart";
AsyncContext context;
volatile boolean isNew = true;
Expand All @@ -99,7 +86,7 @@ public class Servlet3Continuation implements Continuation, AsyncListener {
private ContinuationCallback callback;
private boolean blockRestart;

public Servlet3Continuation() {
public Servlet31Continuation() {
req.setAttribute(AbstractHTTPDestination.CXF_CONTINUATION_MESSAGE,
inMessage.getExchange().getInMessage());
callback = inMessage.getExchange().get(ContinuationCallback.class);
Expand Down Expand Up @@ -138,7 +125,13 @@ public boolean suspend(long timeout) {
return true;
}
protected void updateMessageForSuspend() {
inMessage.getExchange().getInMessage().getInterceptorChain().suspend();
Message currentMessage = PhaseInterceptorChain.getCurrentMessage();
if (currentMessage.get(WriteListener.class) != null) {
getOutputStream().setWriteListener(currentMessage.get(WriteListener.class));
currentMessage.getInterceptorChain().suspend();
} else {
inMessage.getExchange().getInMessage().getInterceptorChain().suspend();
}
}
public void redispatch() {
if (!isComplete) {
Expand Down Expand Up @@ -239,7 +232,7 @@ private boolean isClientDisconnected(Throwable ex) {

@Override
public boolean isReadyForWrite() {
return true;
return getOutputStream().isReady();
}

protected ServletOutputStream getOutputStream() {
Expand All @@ -255,26 +248,4 @@ public boolean isTimeout() {
return isTimeout;
}
}
public class Servlet31Continuation extends Servlet3Continuation {
public Servlet31Continuation() {
}

@Override
protected void updateMessageForSuspend() {
Message currentMessage = PhaseInterceptorChain.getCurrentMessage();
if (currentMessage.get(WriteListener.class) != null) {
// CXF Continuation WriteListener will likely need to be introduced
// for NIO supported with non-Servlet specific mechanisms
getOutputStream().setWriteListener(currentMessage.get(WriteListener.class));
currentMessage.getInterceptorChain().suspend();
} else {
inMessage.getExchange().getInMessage().getInterceptorChain().suspend();
}
}

@Override
public boolean isReadyForWrite() {
return getOutputStream().isReady();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public void testThatProvidedSpanIsNotClosedWhenActive() throws MalformedURLExcep
}

// Await till flush happens, usually a second is enough
await().atMost(Duration.ofSeconds(5L)).until(()-> TestSpanHandler.getAllSpans().size() == 4);
await().atMost(Duration.ofSeconds(10L)).until(()-> TestSpanHandler.getAllSpans().size() == 4);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gnodet seems like another non-related changes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but they belong to a different PR. I merged the PRs into this one to work around the flaky tests in CI and make PR green. The idea would be to merge the other PRs first, then rebase this one.


assertThat(TestSpanHandler.getAllSpans().size(), equalTo(4));
assertThat(TestSpanHandler.getAllSpans().get(3).name(), equalTo("test span"));
Expand All @@ -292,7 +292,7 @@ public void testThatProvidedSpanIsNotDetachedWhenActiveUsingAsyncClient() throws
}

// Await till flush happens, usually a second is enough
await().atMost(Duration.ofSeconds(5L)).until(()-> TestSpanHandler.getAllSpans().size() == 4);
await().atMost(Duration.ofSeconds(10L)).until(()-> TestSpanHandler.getAllSpans().size() == 4);

assertThat(TestSpanHandler.getAllSpans().size(), equalTo(4));
assertThat(TestSpanHandler.getAllSpans().get(3).name(), equalTo("test span"));
Expand Down Expand Up @@ -340,7 +340,7 @@ public void testThatNewSpanIsCreatedOnClientTimeout() {
try {
client.get();
} finally {
await().atMost(Duration.ofSeconds(5L)).until(()-> TestSpanHandler.getAllSpans().size() == 2);
await().atMost(Duration.ofSeconds(10L)).until(()-> TestSpanHandler.getAllSpans().size() == 2);
assertThat(TestSpanHandler.getAllSpans().size(), equalTo(2));
assertThat(TestSpanHandler.getAllSpans().get(0).name(), equalTo("GET " + client.getCurrentURI()));
assertThat(TestSpanHandler.getAllSpans().get(0).tags(), hasKey("error"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public void testThatNewInnerSpanIsCreatedOneway() throws Exception {
service.orderBooks();

// Await till flush happens, usually every second
await().atMost(Duration.ofSeconds(5L)).until(() -> TestSpanHandler.getAllSpans().size() == 2);
await().atMost(Duration.ofSeconds(10L)).until(() -> TestSpanHandler.getAllSpans().size() == 2);

assertThat(TestSpanHandler.getAllSpans().get(0).name(), equalTo("POST /BookStore"));
assertThat(TestSpanHandler.getAllSpans().get(1).name(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public void testThatNewInnerSpanIsCreatedUsingAsyncInvocation() throws Interrupt
final Response r = withTrace(createWebClient("/bookstore/books/async")).get();
assertEquals(Status.OK.getStatusCode(), r.getStatus());

await().atMost(Duration.ofSeconds(5L)).until(() -> otelRule.getSpans().size() == 2);
await().atMost(Duration.ofSeconds(10L)).until(() -> otelRule.getSpans().size() == 2);

final List<SpanData> spans = getSpansSorted();
assertThat(spans.size(), equalTo(2));
Expand Down Expand Up @@ -287,7 +287,7 @@ public void testThatNewSpanIsCreatedUsingAsyncInvocation() throws InterruptedExc
final Response r = createWebClient("/bookstore/books/async").get();
assertEquals(Status.OK.getStatusCode(), r.getStatus());

await().atMost(Duration.ofSeconds(5L)).until(() -> otelRule.getSpans().size() == 2);
await().atMost(Duration.ofSeconds(10L)).until(() -> otelRule.getSpans().size() == 2);

final List<SpanData> spans = getSpansSorted();
assertThat(spans.size(), equalTo(2));
Expand All @@ -303,7 +303,7 @@ public void testThatNewSpanIsCreatedWhenNotProvidedUsingAsyncClient() throws Exc
final Response r = client.async().get().get(1L, TimeUnit.SECONDS);
assertEquals(Status.OK.getStatusCode(), r.getStatus());

await().atMost(Duration.ofSeconds(5L)).until(() -> otelRule.getSpans().size() == 3);
await().atMost(Duration.ofSeconds(10L)).until(() -> otelRule.getSpans().size() == 3);

assertThat(otelRule.getSpans().size(), equalTo(3));
assertThat(otelRule.getSpans().get(0).getName(), equalTo("Get Books"));
Expand Down Expand Up @@ -373,7 +373,7 @@ public void testThatProvidedSpanIsNotClosedWhenActive() throws MalformedURLExcep
}

// Await till flush happens, usually every second
await().atMost(Duration.ofSeconds(5L)).until(() -> otelRule.getSpans().size() == 4);
await().atMost(Duration.ofSeconds(10L)).until(() -> otelRule.getSpans().size() == 4);

assertThat(otelRule.getSpans().size(), equalTo(4));
assertThat(otelRule.getSpans().get(3).getName(), equalTo("test span"));
Expand All @@ -392,7 +392,7 @@ public void testThatProvidedSpanIsNotDetachedWhenActiveUsingAsyncClient() throws
assertThat(Span.current().getSpanContext().getSpanId(),
equalTo(span.getSpanContext().getSpanId()));

await().atMost(Duration.ofSeconds(5L)).until(() -> otelRule.getSpans().size() == 3);
await().atMost(Duration.ofSeconds(10L)).until(() -> otelRule.getSpans().size() == 3);

assertThat(otelRule.getSpans().size(), equalTo(3));
assertThat(otelRule.getSpans().get(0).getName(), equalTo("Get Books"));
Expand All @@ -406,7 +406,7 @@ public void testThatProvidedSpanIsNotDetachedWhenActiveUsingAsyncClient() throws
}

// Await till flush happens, usually every second
await().atMost(Duration.ofSeconds(5L)).until(() -> otelRule.getSpans().size() == 4);
await().atMost(Duration.ofSeconds(10L)).until(() -> otelRule.getSpans().size() == 4);

assertThat(otelRule.getSpans().size(), equalTo(4));
assertThat(otelRule.getSpans().get(3).getName(), equalTo("test span"));
Expand Down Expand Up @@ -443,7 +443,7 @@ public void testThatNewSpanIsCreatedOnClientTimeout() {
try {
client.get();
} finally {
await().atMost(Duration.ofSeconds(5L)).until(() -> otelRule.getSpans().size() == 2);
await().atMost(Duration.ofSeconds(10L)).until(() -> otelRule.getSpans().size() == 2);
assertThat(otelRule.getSpans().toString(), otelRule.getSpans().size(), equalTo(2));
assertThat(otelRule.getSpans().get(0).getName(), equalTo("GET " + client.getCurrentURI()));
assertThat(otelRule.getSpans().get(0).getStatus().getStatusCode(), equalTo(StatusCode.ERROR));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public void testThatNewInnerSpanIsCreatedUsingAsyncInvocation() throws Interrupt
final Response r = withTrace(createWebClient("/bookstore/books/async"), spanId).get();
assertEquals(Status.OK.getStatusCode(), r.getStatus());

await().atMost(Duration.ofSeconds(5L)).until(()-> REPORTER.getSpans().size() == 2);
await().atMost(Duration.ofSeconds(10L)).until(()-> REPORTER.getSpans().size() == 2);

final List<JaegerSpan> spans = getSpansSorted();
assertThat(spans.size(), equalTo(2));
Expand All @@ -226,7 +226,7 @@ public void testThatNewSpanIsCreatedUsingAsyncInvocation() throws InterruptedExc
final Response r = createWebClient("/bookstore/books/async").get();
assertEquals(Status.OK.getStatusCode(), r.getStatus());

await().atMost(Duration.ofSeconds(5L)).until(()-> REPORTER.getSpans().size() == 2);
await().atMost(Duration.ofSeconds(10L)).until(()-> REPORTER.getSpans().size() == 2);

final List<JaegerSpan> spans = getSpansSorted();
assertThat(spans.size(), equalTo(2));
Expand All @@ -241,7 +241,7 @@ public void testThatNewSpanIsCreatedWhenNotProvidedUsingAsyncClient() throws Exc
final Response r = client.async().get().get(1L, TimeUnit.SECONDS);
assertEquals(Status.OK.getStatusCode(), r.getStatus());

await().atMost(Duration.ofSeconds(5L)).until(()-> REPORTER.getSpans().size() == 3);
await().atMost(Duration.ofSeconds(10L)).until(()-> REPORTER.getSpans().size() == 3);

assertThat(REPORTER.getSpans().size(), equalTo(3));
assertThat(REPORTER.getSpans().get(0).getOperationName(), equalTo("Get Books"));
Expand Down Expand Up @@ -325,7 +325,7 @@ public void testThatProvidedSpanIsNotClosedWhenActive() throws MalformedURLExcep
}

// Await till flush happens, usually every second
await().atMost(Duration.ofSeconds(5L)).until(()-> REPORTER.getSpans().size() == 4);
await().atMost(Duration.ofSeconds(10L)).until(()-> REPORTER.getSpans().size() == 4);

assertThat(REPORTER.getSpans().size(), equalTo(4));
assertThat(REPORTER.getSpans().get(3).getOperationName(), equalTo("test span"));
Expand All @@ -342,7 +342,7 @@ public void testThatProvidedSpanIsNotDetachedWhenActiveUsingAsyncClient() throws
assertEquals(Status.OK.getStatusCode(), r.getStatus());
assertThat(tracer.activeSpan().context(), equalTo(span.context()));

await().atMost(Duration.ofSeconds(5L)).until(()-> REPORTER.getSpans().size() == 3);
await().atMost(Duration.ofSeconds(10L)).until(()-> REPORTER.getSpans().size() == 3);

assertThat(REPORTER.getSpans().size(), equalTo(3));
assertThat(REPORTER.getSpans().get(0).getOperationName(), equalTo("Get Books"));
Expand All @@ -356,7 +356,7 @@ public void testThatProvidedSpanIsNotDetachedWhenActiveUsingAsyncClient() throws
}

// Await till flush happens, usually every second
await().atMost(Duration.ofSeconds(5L)).until(()-> REPORTER.getSpans().size() == 4);
await().atMost(Duration.ofSeconds(10L)).until(()-> REPORTER.getSpans().size() == 4);

assertThat(REPORTER.getSpans().size(), equalTo(4));
assertThat(REPORTER.getSpans().get(3).getOperationName(), equalTo("test span"));
Expand Down Expand Up @@ -391,7 +391,7 @@ public void testThatNewSpanIsCreatedOnClientTimeout() {
try {
client.get();
} finally {
await().atMost(Duration.ofSeconds(5L)).until(()-> REPORTER.getSpans().size() == 2);
await().atMost(Duration.ofSeconds(10L)).until(()-> REPORTER.getSpans().size() == 2);
assertThat(REPORTER.getSpans().toString(), REPORTER.getSpans().size(), equalTo(2));
assertThat(REPORTER.getSpans().get(0).getOperationName(), equalTo("GET " + client.getCurrentURI()));
assertThat(REPORTER.getSpans().get(0).getTags(), hasItem(Tags.ERROR.getKey(), Boolean.TRUE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public void testThatProvidedSpanIsNotClosedWhenActive() throws Exception {
}

// Await till flush happens, usually every second
await().atMost(Duration.ofSeconds(5L)).until(() -> otelRule.getSpans().size() == 4);
await().atMost(Duration.ofSeconds(10L)).until(() -> otelRule.getSpans().size() == 4);

assertThat(otelRule.getSpans().size(), equalTo(4));
assertThat(otelRule.getSpans().get(3).getName(), equalTo("test span"));
Expand Down Expand Up @@ -331,7 +331,7 @@ public void testThatNewInnerSpanIsCreatedOneway() throws Exception {
service.orderBooks();

// Await till flush happens, usually every second
await().atMost(Duration.ofSeconds(5L)).until(() -> otelRule.getSpans().size() == 2);
await().atMost(Duration.ofSeconds(10L)).until(() -> otelRule.getSpans().size() == 2);

assertThat(otelRule.getSpans().get(0).getName(), equalTo("POST /BookStore"));
assertThat(otelRule.getSpans().get(1).getName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public void testThatProvidedSpanIsNotClosedWhenActive() throws Exception {
}

// Await till flush happens, usually every second
await().atMost(Duration.ofSeconds(5L)).until(()-> REPORTER.getSpans().size() == 4);
await().atMost(Duration.ofSeconds(10L)).until(()-> REPORTER.getSpans().size() == 4);

assertThat(REPORTER.getSpans().size(), equalTo(4));
assertThat(REPORTER.getSpans().get(3).getOperationName(), equalTo("test span"));
Expand Down Expand Up @@ -234,7 +234,7 @@ public void testThatNewInnerSpanIsCreatedOneway() throws Exception {
service.orderBooks();

// Await till flush happens, usually every second
await().atMost(Duration.ofSeconds(5L)).until(() -> REPORTER.getSpans().size() == 2);
await().atMost(Duration.ofSeconds(10L)).until(() -> REPORTER.getSpans().size() == 2);

assertThat(REPORTER.getSpans().get(0).getOperationName(), equalTo("POST /BookStore"));
assertThat(REPORTER.getSpans().get(1).getOperationName(),
Expand Down
Loading