Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jaxrs-dev] HeaderDelegate

Niklas,

 Most if not all of these classes have been around since 1.0. I see your point about the added difficulty of testing. However, if I understand correctly, what you’re proposing is a breaking change. This could be evaluated for 3.0 but it seems very hard to make a case for 2.2. 

 Perhaps you should file an issue so that others can comment on this. 

— Santiago

On Mar 22, 2018, at 1:35 PM, Niklas Mehner <niklas.mehner@xxxxxxxxx> wrote:



Hi,

I have a question regarding the header classes (CacheControl, EntityTag, ...) in JAX-RS. They all implement the pattern of having a static reference:

private static final HeaderDelegate<EntityTag> HEADER_DELEGATE =
RuntimeDelegate.getInstance().createHeaderDelegate(EntityTag.class);
and implementing valueOf/toString methods:

public static EntityTag valueOf(final String value) {
return HEADER_DELEGATE.fromString(value);
}
public String toString() {
return HEADER_DELEGATE.toString(this);
}
What is this actually for?

RestEasy implements adding a header in org.jboss.resteasy.plugins.server.servlet.HttpServletResponseHeaders:
protected void addResponseHeader(String key, Object value)
{
if (value == null)
{
return;
}
RuntimeDelegate.HeaderDelegate delegate = factory.getHeaderDelegate(value.getClass());
if (delegate != null)
{
//System.out.println("addResponseHeader: " + key + " " + delegate.toString(value));
response.addHeader(key, delegate.toString(value));
}
else
{
//System.out.println("addResponseHeader: " + key + " " + value.toString());
response.addHeader(key, value.toString());
}
}
Ans Jersey in org.glassfish.jersey.message.internal.HeaderUtils:
public static String asString(final Object headerValue, RuntimeDelegate rd) {
if (headerValue == null) {
return null;
}
if (headerValue instanceof String) {
return (String) headerValue;
}
if (rd == null) {
rd = RuntimeDelegate.getInstance();
}

final HeaderDelegate hp = rd.createHeaderDelegate(headerValue.getClass());
return (hp != null) ? hp.toString(headerValue) : headerValue.toString();
}
In both cases the toString() method of the header classes will not be used since createHeaderDelegate() is required to return a value for them.
And I don't see any use case for them as a user of the JAX-RS Api.
Could we just deprecate/remove them?
The static variable makes testing a lot harder and only causes problems e.g. when more than one implementation is on the classpath and is not a very nice design.
If rendering/parsing a header is required the HeaderDelegate could be used directly.

Is there any use case I am not seeing?

Best regards,
  Niklas
_______________________________________________
jaxrs-dev mailing list
jaxrs-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jaxrs-dev


Back to the top