use of javax.ws.rs.ext.RuntimeDelegate in project jersey by jersey.
the class OutboundMessageContext method getAcceptableMediaTypes.
/**
* Get a list of media types that are acceptable for the message.
*
* @return a read-only list of requested message media types sorted according
* to their q-value, with highest preference first.
*/
@SuppressWarnings("unchecked")
public List<MediaType> getAcceptableMediaTypes() {
final List<Object> values = headers.get(HttpHeaders.ACCEPT);
if (values == null || values.isEmpty()) {
return WILDCARD_ACCEPTABLE_TYPE_SINGLETON_LIST;
}
final List<MediaType> result = new ArrayList<>(values.size());
final RuntimeDelegate rd = RuntimeDelegate.getInstance();
boolean conversionApplied = false;
for (final Object value : values) {
try {
if (value instanceof MediaType) {
final AcceptableMediaType _value = AcceptableMediaType.valueOf((MediaType) value);
// true if value was not an instance of AcceptableMediaType already
conversionApplied = _value != value;
result.add(_value);
} else {
conversionApplied = true;
result.addAll(HttpHeaderReader.readAcceptMediaType(HeaderUtils.asString(value, rd)));
}
} catch (java.text.ParseException e) {
throw exception(HttpHeaders.ACCEPT, value, e);
}
}
if (conversionApplied) {
// cache converted
headers.put(HttpHeaders.ACCEPT, result.stream().map((Function<MediaType, Object>) mediaType -> mediaType).collect(Collectors.toList()));
}
return Collections.unmodifiableList(result);
}
use of javax.ws.rs.ext.RuntimeDelegate in project jersey by jersey.
the class OutboundMessageContext method getAcceptableLanguages.
/**
* Get a list of languages that are acceptable for the message.
*
* @return a read-only list of acceptable languages sorted according
* to their q-value, with highest preference first.
*/
public List<Locale> getAcceptableLanguages() {
final List<Object> values = headers.get(HttpHeaders.ACCEPT_LANGUAGE);
if (values == null || values.isEmpty()) {
return Collections.singletonList(new AcceptableLanguageTag("*", null).getAsLocale());
}
final List<Locale> result = new ArrayList<Locale>(values.size());
final RuntimeDelegate rd = RuntimeDelegate.getInstance();
boolean conversionApplied = false;
for (final Object value : values) {
if (value instanceof Locale) {
result.add((Locale) value);
} else {
conversionApplied = true;
try {
result.addAll(HttpHeaderReader.readAcceptLanguage(HeaderUtils.asString(value, rd)).stream().map(LanguageTag::getAsLocale).collect(Collectors.toList()));
} catch (java.text.ParseException e) {
throw exception(HttpHeaders.ACCEPT_LANGUAGE, value, e);
}
}
}
if (conversionApplied) {
// cache converted
headers.put(HttpHeaders.ACCEPT_LANGUAGE, result.stream().map((Function<Locale, Object>) locale -> locale).collect(Collectors.toList()));
}
return Collections.unmodifiableList(result);
}
use of javax.ws.rs.ext.RuntimeDelegate in project jersey by jersey.
the class HeaderUtils method checkHeaderChanges.
/**
* Compares two snapshots of headers from jersey {@code ClientRequest} and logs {@code WARNING} in case of difference.
*
* Current container implementations does not support header modification in {@link javax.ws.rs.ext.WriterInterceptor}
* and {@link javax.ws.rs.ext.MessageBodyWriter}. The method checks there are some newly added headers
* (probably by WI or MBW) and logs {@code WARNING} message about it.
*
* @param headersSnapshot first immutable snapshot of headers
* @param currentHeaders current instance of headers tobe compared to
* @param connectorName name of connector the method is invoked from, used just in logged message
* @see <a href="https://java.net/jira/browse/JERSEY-2341">JERSEY-2341</a>
*/
public static void checkHeaderChanges(final Map<String, String> headersSnapshot, final MultivaluedMap<String, Object> currentHeaders, final String connectorName) {
if (HeaderUtils.LOGGER.isLoggable(Level.WARNING)) {
final RuntimeDelegate rd = RuntimeDelegate.getInstance();
final Set<String> changedHeaderNames = new HashSet<String>();
for (final Map.Entry<? extends String, ? extends List<Object>> entry : currentHeaders.entrySet()) {
if (!headersSnapshot.containsKey(entry.getKey())) {
changedHeaderNames.add(entry.getKey());
} else {
final String prevValue = headersSnapshot.get(entry.getKey());
final String newValue = asHeaderString(currentHeaders.get(entry.getKey()), rd);
if (!prevValue.equals(newValue)) {
changedHeaderNames.add(entry.getKey());
}
}
}
if (!changedHeaderNames.isEmpty()) {
if (HeaderUtils.LOGGER.isLoggable(Level.WARNING)) {
HeaderUtils.LOGGER.warning(LocalizationMessages.SOME_HEADERS_NOT_SENT(connectorName, changedHeaderNames.toString()));
}
}
}
}
use of javax.ws.rs.ext.RuntimeDelegate in project tesb-rt-se by Talend.
the class ApplicationServer method startApplication.
private static Server startApplication(Application app) {
RuntimeDelegate delegate = RuntimeDelegate.getInstance();
JAXRSServerFactoryBean bean = delegate.createEndpoint(app, JAXRSServerFactoryBean.class);
bean.setAddress("http://localhost:8080" + bean.getAddress());
bean.setStart(false);
Server server = bean.create();
JettyHTTPDestination dest = (JettyHTTPDestination) server.getDestination();
JettyHTTPServerEngine engine = (JettyHTTPServerEngine) dest.getEngine();
engine.setSessionSupport(true);
server.start();
return server;
}
use of javax.ws.rs.ext.RuntimeDelegate in project jbpm by kiegroup.
the class RestWorkItemHandlerTest method initialize.
@SuppressWarnings({ "rawtypes" })
@BeforeClass
public static void initialize() throws Exception {
SimpleRESTApplication application = new SimpleRESTApplication();
RuntimeDelegate delegate = RuntimeDelegate.getInstance();
JAXRSServerFactoryBean bean = delegate.createEndpoint(application, JAXRSServerFactoryBean.class);
bean.setProvider(new JAXBElementProvider());
bean.setAddress("http://localhost:9998" + bean.getAddress());
server = bean.create();
server.start();
}
Aggregations