-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add suspendables for request and response filters
Add some tests to ensure the filters are called as desired.
- Loading branch information
1 parent
87e471a
commit 241b2d4
Showing
5 changed files
with
105 additions
and
9 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
comsat-jersey-server/src/main/resources/META-INF/suspendable-supers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
javax.ws.rs.container.ContainerRequestFilter.filter | ||
javax.ws.rs.container.ContainerResponseFilter.filter | ||
org.glassfish.jersey.process.internal.Stage.apply |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...-jersey-server/src/test/java/co/paralleluniverse/fibers/jersey/AddTestFiltersFeature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package co.paralleluniverse.fibers.jersey; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.ws.rs.container.ContainerRequestContext; | ||
import javax.ws.rs.container.ContainerRequestFilter; | ||
import javax.ws.rs.container.ContainerResponseContext; | ||
import javax.ws.rs.container.ContainerResponseFilter; | ||
import javax.ws.rs.core.Feature; | ||
import javax.ws.rs.core.FeatureContext; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
import co.paralleluniverse.fibers.Fiber; | ||
import co.paralleluniverse.fibers.SuspendExecution; | ||
import co.paralleluniverse.fibers.Suspendable; | ||
|
||
@Provider | ||
public class AddTestFiltersFeature implements Feature { | ||
|
||
@Override | ||
public boolean configure(FeatureContext context) { | ||
context.register(TestRequestFilter.class); | ||
context.register(TestResponseFilter.class); | ||
return true; | ||
} | ||
|
||
} | ||
|
||
class TestRequestFilter implements ContainerRequestFilter { | ||
|
||
@Override | ||
@Suspendable | ||
public void filter(ContainerRequestContext requestContext) throws IOException { | ||
try { | ||
Fiber.sleep(5); | ||
requestContext.getHeaders().add(FiberServletContainerTest.REQUEST_FILTER_HEADER, | ||
FiberServletContainerTest.REQUEST_FILTER_HEADER_VALUE); | ||
} catch (InterruptedException | SuspendExecution e) { | ||
throw new Error(e); | ||
} | ||
} | ||
} | ||
|
||
class TestResponseFilter implements ContainerResponseFilter { | ||
|
||
@Override | ||
@Suspendable | ||
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) | ||
throws IOException { | ||
try { | ||
Fiber.sleep(5); | ||
responseContext.getHeaders().add(FiberServletContainerTest.RESPONSE_FILTER_HEADER, | ||
FiberServletContainerTest.RESPONSE_FILTER_HEADER_VALUE); | ||
} catch (InterruptedException | SuspendExecution e) { | ||
throw new Error(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters