/** * Get a message header as a single string value. * <p> * Each single header value is converted to String using a * {@link javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate} if one is available * via {@link javax.ws.rs.ext.RuntimeDelegate#createHeaderDelegate(java.lang.Class)} * for the header value class or using its {@code toString} method if a header * delegate is not available. * * @param name the message header. * @return the message header value. If the message header is not present then * {@code null} is returned. If the message header is present but has no * value then the empty string is returned. If the message header is present * more than once then the values of joined together and separated by a ',' * character. */ public String getHeaderString(String name) { return HeaderUtils.asHeaderString(headers.get(name), RuntimeDelegate.getInstance()); }
rd = RuntimeDelegate.getInstance(); final HeaderDelegate hp = rd.createHeaderDelegate(headerValue.getClass()); return (hp != null) ? hp.toString(headerValue) : headerValue.toString();
/** * Starts the lightweight HTTP server serving the JAX-RS application. * * @return new instance of the lightweight HTTP server * @throws IOException */ static HttpServer startServer() throws IOException { // create a new server listening at port 8080 final HttpServer server = HttpServer.create(new InetSocketAddress(getBaseURI().getPort()), 0); Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { server.stop(0); } })); // create a handler wrapping the JAX-RS application HttpHandler handler = RuntimeDelegate.getInstance().createEndpoint(new JaxRsApplication(), HttpHandler.class); // map JAX-RS handler to the server root server.createContext(getBaseURI().getPath(), handler); // start the server server.start(); return server; }
@Override public Locale getLanguage() { if (contentLanguage == null && httpHeaders.getFirst(CONTENT_LANGUAGE) != null) { contentLanguage = RuntimeDelegate.getInstance().createHeaderDelegate(Locale.class).fromString(httpHeaders.getFirst(CONTENT_LANGUAGE)); } return contentLanguage; }
@SuppressWarnings(value = "unchecked") protected void flushHeaders() throws IOException { if (headersFlushed) return; headersFlushed = true; RuntimeDelegate delegate = RuntimeDelegate.getInstance(); for (String key : headers.keySet()) { List<Object> objs = headers.get(key); for (Object obj : objs) { String value; RuntimeDelegate.HeaderDelegate headerDelegate = delegate .createHeaderDelegate(obj.getClass()); if (headerDelegate != null) { value = headerDelegate.toString(obj); } else { value = obj.toString(); } stream.write(key.getBytes()); stream.write(": ".getBytes()); stream.write(value.getBytes()); stream.write("\r\n".getBytes()); } } stream.write("\r\n".getBytes()); }
/** * Add a new header value. * * @param name header name. * @param value header value. * @return updated context. */ public InboundMessageContext header(String name, Object value) { getHeaders().add(name, HeaderUtils.asString(value, RuntimeDelegate.getInstance())); return this; }
/** * Transforms multi value map of headers to single {@code String} value map. * * Returned map is immutable. Map values are formatted using method {@link #asHeaderString}. * * @param headers headers to be formatted * @return immutable single {@code String} value map or * {@code null} if {@code headers} input parameter is {@code null}. */ public static Map<String, String> asStringHeadersSingleValue(final MultivaluedMap<String, Object> headers) { if (headers == null) { return null; } final RuntimeDelegate rd = RuntimeDelegate.getInstance(); return Collections.unmodifiableMap(headers.entrySet().stream() .collect(Collectors.toMap( Map.Entry::getKey, entry -> asHeaderString(entry.getValue(), rd)))); }
/** * You may put path parameters anywhere within the uriTemplate except port. * * @param uriTemplate uri template * @return uri builder */ public static ResteasyUriBuilder fromTemplate(String uriTemplate) { ResteasyUriBuilder impl = (ResteasyUriBuilder)RuntimeDelegate.getInstance().createUriBuilder(); impl.uriTemplate(uriTemplate); return impl; }
/** * Create a new builder instance. * * @return a new response builder. */ protected static ResponseBuilder newInstance() { return RuntimeDelegate.getInstance().createResponseBuilder(); }
/** * Create a new builder instance initialized from an existing URI. * * @param uri a URI that will be used to initialize the builder. * @return a new builder. * @throws IllegalArgumentException if uri is {@code null}. */ public static Builder fromUri(URI uri) { Builder b = RuntimeDelegate.getInstance().createLinkBuilder(); b.uri(uri); return b; }
/** * Create a new builder instance. * * @return a new builder instance. */ public static VariantListBuilder newInstance() { return RuntimeDelegate.getInstance().createVariantListBuilder(); }
/** * Add new header values. * * @param name header name. * @param values header values. * @return updated context. */ public InboundMessageContext headers(String name, Object... values) { this.getHeaders().addAll(name, HeaderUtils.asStringList(Arrays.asList(values), RuntimeDelegate.getInstance())); return this; }
private static List<String> iterableToList(final Iterable<?> values) { final LinkedList<String> linkedList = new LinkedList<String>(); final RuntimeDelegate rd = RuntimeDelegate.getInstance(); for (Object element : values) { linkedList.add(HeaderUtils.asString(element, rd)); } return linkedList; }
@Initializer(before = InitMilestone.PLUGINS_STARTED) public static void setRuntimeDelegate() { RuntimeDelegate.setInstance(new ResteasyProviderFactory()); }
public static RuntimeDelegate getInstance() { RuntimeDelegate result = cachedDelegate; if (result == null) { synchronized (LOCK) { result = cachedDelegate; if (result == null) { cachedDelegate = result = findDelegate(); } } } return result; }
/** * Convert a header value, represented as a general object, to the * string value. * <p> * This method defers to {@link RuntimeDelegate#createHeaderDelegate} to * obtain a {@link HeaderDelegate} to convert the value to a string. If * a {@link HeaderDelegate} is not found then the <code>toString</code> * is utilized. * <p> * Containers may use this method to convert the header values obtained * from the {@link #getHttpHeaders} * * @param headerValue the header value as an object * @return the string value */ public static String getHeaderValue(Object headerValue) { HeaderDelegate hp = rd.createHeaderDelegate(headerValue.getClass()); return (hp != null) ? hp.toString(headerValue) : headerValue.toString(); }
public UriBuilder get() { return runtimeDelegate.createUriBuilder(); } }
public Response.ResponseBuilder get() { return runtimeDelegate.createResponseBuilder(); } }
public Variant.VariantListBuilder get() { return runtimeDelegate.createVariantListBuilder(); } }
@Override public Locale getLanguage() { Object value = getMetadata().getFirst(CONTENT_LANGUAGE); if (value == null) { return null; } if (value instanceof Locale) { return (Locale)value; } return RuntimeDelegate.getInstance().createHeaderDelegate(Locale.class) .fromString(value instanceof String ? (String)value : getHeaderAsString(value)); }