private static <T> RestfulClientInvoker createClientInvoker(Class<T> clazz, Method method, ResteasyWebTarget base, ProxyConfig config) { Set<String> httpMethods = IsHttpMethod.getHttpMethods(method); if (httpMethods == null || httpMethods.size() != 1) { throw new RuntimeException( "You must use at least one, but no more than one http method annotation on: " + method.toString()); } RestfulClientInvoker invoker = new RestfulClientInvoker(base, clazz, method, config); invoker.setHttpMethod(httpMethods.iterator().next()); return invoker; }
public static Response serializeError(Exception ex) { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(ex); oos.flush(); String info = new String(Base64.encodeBytesToBytes(baos.toByteArray()), MotanConstants.DEFAULT_CHARACTER); return Response.status(Status.EXPECTATION_FAILED).header(EXCEPTION_HEADER, ex.getClass()).entity(info) .build(); } catch (IOException e) { LoggerUtil.error("serialize " + ex.getClass() + " error", e); return Response.status(Status.INTERNAL_SERVER_ERROR).entity("serialization " + ex.getClass() + " error") .build(); } }
public static Exception getCause(BuiltResponse resp) { if (resp == null || resp.getStatus() != Status.EXPECTATION_FAILED.getStatusCode()) return null; String exceptionClass = resp.getHeaderString(EXCEPTION_HEADER); if (!StringUtils.isBlank(exceptionClass)) { String body = resp.readEntity(String.class); resp.close(); try { ByteArrayInputStream bais = new ByteArrayInputStream( Base64.decode(body.getBytes(MotanConstants.DEFAULT_CHARACTER))); ObjectInputStream ois = new ObjectInputStream(bais); return (Exception) ois.readObject(); } catch (Exception e) { LoggerUtil.error("deserialize " + exceptionClass + " error", e); } } return null; }
public static boolean isRootResource(Class clazz) { return getRootResourceClass(clazz) != null; } }
/** * Look up the configured port number, first checking an environment variable (RESTEASY_PORT), * then a system property (org.jboss.resteasy.port), and finally the default port (8081). * * @return the port number specified in either the environment or system properties */ public static int getPort() { return PortProvider.getPort(); }
public static InputStream noContentCheck( MultivaluedMap httpHeaders, InputStream is) throws NoContentException { contentLengthCheck(httpHeaders); NoContentInputStreamDelegate delegate = new NoContentInputStreamDelegate(is); return delegate; }
/** * * @param username user name * @param password password */ public BasicAuthentication(final String username, final String password) { authHeader = BasicAuthHelper.createHeader(username, password); }
/** * Keep any valid encodings from string i.e. keep "%2D" but don't keep "%p" * * @param segment value to encode * @return encoded value */ public static String encodePathSaveEncodings(String segment) { String result = encodeFromArray(segment, pathEncoding, false); result = encodeNonCodes(result); return result; }
@Override public MultivaluedMap<String, String> getDecodedFormParameters() { return new PrefixedMultivaluedMap<String>(prefix, super.getDecodedFormParameters()); }
/** * Keep encoded values "%...", matrix parameters and template parameters intact. * @param value path segment * @return encoded path segment */ public static String encodePathSegment(String value) { return encodeValue(value, pathSegmentEncoding); }
@Override public UriBuilder replacePath(String path) { if (path == null) { this.path = null; return this; } this.path = Encode.encodePath(path); return this; }
/** * Formats the given date according to the RFC 1123 pattern. * * @param date The date to format. * @return An RFC 1123 formatted date string. * @see #PATTERN_RFC1123 */ public static String formatDate(Date date) { return formatDate(date, PATTERN_RFC1123); }
/** * Look up the configured hostname, first checking an environment variable (RESTEASY_HOST), * then a system property (org.jboss.resteasy.host), and finally the default hostname (localhost). * * @return the host specified in either the environment or system properties */ public static String getHost() { return PortProvider.getHost(); } }
final Class resourceDef = GetRestful.getRootResourceClass(implClass) != null ? implClass : type;
/** * Keep any valid encodings from string i.e. keep "%2D" but don't keep "%p" * * @param segment value to encode * @return encoded value */ public static String encodePathSegmentSaveEncodings(String segment) { String result = encodeFromArray(segment, pathSegmentEncoding, false); result = encodeNonCodes(result); return result; }
/** * Keep encoded values "%..." and template parameters intact. * @param value query string * @return encoded query string */ public static String encodeQueryString(String value) { return encodeValue(value, queryStringEncoding); }
final Class resourceDef = GetRestful.getRootResourceClass(implClass) != null ? implClass : type;
/** * Keep encoded values "%..." and template parameters intact. * @param value uri fragment * @return encoded uri fragment */ public static String encodeFragment(String value) { return encodeValue(value, queryStringEncoding); }