public void writeTo(T obj, Class<?> type, Type genType, Annotation[] anns, MediaType mt, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException { String encoding = HttpUtils.getSetEncoding(mt, headers, StandardCharsets.UTF_8.name()); byte[] bytes = obj.toString().getBytes(encoding); os.write(bytes); }
public String readFrom(Class<String> type, Type genType, Annotation[] anns, MediaType mt, MultivaluedMap<String, String> headers, InputStream is) throws IOException { return IOUtils.toString(is, HttpUtils.getEncoding(mt, StandardCharsets.UTF_8.name())); }
@Override public String fromString(String s) { return HttpUtils.urlDecode(s); }
public static String decodeValue(String value, boolean decode, ParameterType param) { if (!decode) { return value; } if (param == ParameterType.PATH || param == ParameterType.MATRIX) { return HttpUtils.pathDecode(value); } return HttpUtils.urlDecode(value); }
private String doGetPath(boolean decode, boolean addSlash) { String path = HttpUtils.getPathToMatch(message, addSlash); return decode ? HttpUtils.pathDecode(path) : path; }
public URI getBaseUri() { URI u = URI.create(HttpUtils.getEndpointAddress(message)); return HttpUtils.toAbsoluteUri(u, message); }
public static Date getHttpDate(String value) { if (value == null) { return null; } try { return HttpUtils.getHttpDateFormat().parse(value); } catch (ParseException ex) { return null; } }
public static String urlEncode(String value) { return urlEncode(value, "UTF-8"); }
private static String getPath(Message message) { String address = HttpUtils.getEndpointAddress(message); if (MessageUtils.isRequestor(message)) { return address; } String path = HttpUtils.getPathToMatch(message, false); return address + path; }
public static String getBaseAddress(Message m) { String endpointAddress = getEndpointAddress(m); try { URI uri = new URI(endpointAddress); String path = uri.getRawPath(); String scheme = uri.getScheme(); if (scheme != null && !scheme.startsWith(HttpUtils.HTTP_SCHEME) && HttpUtils.isHttpRequest(m)) { path = HttpUtils.toAbsoluteUri(path, m).getRawPath(); } return (path == null || path.length() == 0) ? "/" : path; } catch (URISyntaxException ex) { return endpointAddress == null ? "/" : endpointAddress; } }
public static String getPathToMatch(Message m, boolean addSlash) { String var = addSlash ? REQUEST_PATH_TO_MATCH_SLASH : REQUEST_PATH_TO_MATCH; String pathToMatch = (String)m.get(var); if (pathToMatch != null) { return pathToMatch; } String requestAddress = getProtocolHeader(m, Message.REQUEST_URI, "/"); if (m.get(Message.QUERY_STRING) == null) { int index = requestAddress.lastIndexOf('?'); if (index > 0 && index < requestAddress.length()) { m.put(Message.QUERY_STRING, requestAddress.substring(index + 1)); requestAddress = requestAddress.substring(0, index); } } String baseAddress = getBaseAddress(m); pathToMatch = getPathToMatch(requestAddress, baseAddress, addSlash); m.put(var, pathToMatch); return pathToMatch; }
public boolean isSecure() { String value = HttpUtils.getEndpointAddress(m); return value.startsWith("https://"); }
private List<String> getListValues(String headerName) { List<String> values = headers.get(headerName); if (values == null || values.isEmpty() || values.get(0) == null) { return Collections.emptyList(); } if (HttpUtils.isDateRelatedHeader(headerName)) { return values; } List<String> actualValues = new LinkedList<>(); for (String v : values) { actualValues.addAll(getHeaderValues(headerName, v)); } return actualValues; }
public String getHeaderString(String headerName) { return HttpUtils.getHeaderString(headers.get(headerName)); }
String httpMethod = HttpUtils.getProtocolHeader(message, Message.HTTP_REQUEST_METHOD, HttpMethod.POST, true); String rawPath = HttpUtils.getPathToMatch(message, true); acceptTypes = HttpUtils.getProtocolHeader(message, Message.ACCEPT_CONTENT_TYPE, null); if (acceptTypes == null) { acceptTypes = "*/*";
private Method getResourceMethod(Message m, String httpMethod) { String requestUri = HttpUtils.getPathToMatch(m, true); List<ClassResourceInfo> resources = JAXRSUtils.getRootResources(m); Map<ClassResourceInfo, MultivaluedMap<String, String>> matchedResources = JAXRSUtils.selectResourceClass(resources, requestUri, m); if (matchedResources == null) { return null; } MultivaluedMap<String, String> values = new MetadataMap<>(); OperationResourceInfo ori = findPreflightMethod(matchedResources, requestUri, httpMethod, values, m); return ori == null ? null : ori.getAnnotatedMethod(); }
segment = uList.get(i).getPath(); } else { segment = HttpUtils.fromPathSegment(uList.get(i));
private String toHttpDate(Date date) { SimpleDateFormat format = HttpUtils.getHttpDateFormat(); return format.format(date); }
public static String urlEncode(String value) { return urlEncode(value, StandardCharsets.UTF_8.name()); }
public static String decodeValue(String value, boolean decode, ParameterType param) { if (!decode) { return value; } if (param == ParameterType.PATH || param == ParameterType.MATRIX) { return HttpUtils.pathDecode(value); } else { return HttpUtils.urlDecode(value); } }