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

Implementation of EntityPart API #4859

Merged
merged 2 commits into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Review comments reflected
Signed-off-by: jansupol <[email protected]>
  • Loading branch information
jansupol committed Sep 21, 2021
commit d561f965cd1a683c8d8b582d5fe24a150b6809e1
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@
import jakarta.ws.rs.core.NewCookie;
import jakarta.ws.rs.core.Response.ResponseBuilder;
import jakarta.ws.rs.core.UriBuilder;
import jakarta.ws.rs.ext.ParamConverter;
import jakarta.ws.rs.ext.RuntimeDelegate;

import org.glassfish.jersey.innate.spi.EntityPartBuilderProvider;
import org.glassfish.jersey.internal.util.collection.LazyValue;
import org.glassfish.jersey.internal.util.collection.Value;
import org.glassfish.jersey.internal.util.collection.Values;
import org.glassfish.jersey.message.internal.JerseyLink;
import org.glassfish.jersey.message.internal.OutboundJaxrsResponse;
import org.glassfish.jersey.message.internal.OutboundMessageContext;
Expand All @@ -52,8 +56,8 @@ public abstract class AbstractRuntimeDelegate extends RuntimeDelegate {

private final Set<HeaderDelegateProvider> hps;
private final Map<Class<?>, HeaderDelegate<?>> map;
private static final Object EPB_LOCK = new Object();
private static volatile EntityPartBuilderProvider cachedEntityPartBuilderProvider;
private LazyValue<EntityPartBuilderProvider> entityPartBuilderProvider = Values.lazy(
(Value<EntityPartBuilderProvider>) () -> findEntityPartBuilderProvider());

/**
* Initialization constructor. The injection manager will be shut down.
Expand Down Expand Up @@ -124,26 +128,9 @@ private <T> HeaderDelegate<T> _createHeaderDelegate(final Class<T> type) {

@Override
public EntityPart.Builder createEntityPartBuilder(String partName) throws IllegalArgumentException {
return getEntityPartBuilderProvider().withName(partName);
return entityPartBuilderProvider.get().withName(partName);
}

private static EntityPartBuilderProvider getEntityPartBuilderProvider() {
// Double-check idiom for lazy initialization of fields.
// Local variable is used to limit the number of more expensive accesses to a volatile field.
EntityPartBuilderProvider result = cachedEntityPartBuilderProvider;
if (result == null) { // First check (no locking)
synchronized (EPB_LOCK) {
result = cachedEntityPartBuilderProvider;
if (result == null) { // Second check (with locking)
result = findEntityPartBuilderProvider();
cachedEntityPartBuilderProvider = result;
}
}
}
return result;
}


/**
* Obtain a {@code RuntimeDelegate} instance using the method described in {@link #getInstance}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,10 @@ public Object apply(ContainerRequest request) {
Form otherForm = getCachedForm(request, !decode);
if (otherForm != null) {
form = switchUrlEncoding(request, otherForm);
cacheForm(request, form);
} else {
form = getForm(request);
cacheForm(request, form);
}
cacheForm(request, form);
}

try {
Expand Down