/** * Form encode a string */ @Functions.Expose(prefix = "os", names = {"urlEncode"}) public static String formEncode(String text) { if (text == null) { return null; } return Utf8UrlCoder.encode(text); }
/** * Form encode a string */ @Functions.Expose(prefix = "osx", names = {"urlEncode"}) public static String formEncode(String text) { if (text == null) { return null; } return Utf8UrlCoder.encode(text); }
/** * Form encode a string */ @Functions.Expose(prefix = "os", names = {"urlEncode"}) public static String formEncode(String text) { if (text == null) { return null; } return Utf8UrlCoder.encode(text); }
/** * Form encode a string */ @Functions.Expose(prefix = "osx", names = {"urlEncode"}) public static String formEncode(String text) { if (text == null) { return null; } return Utf8UrlCoder.encode(text); }
/** * Form encode a string */ @Functions.Expose(prefix = "os", names = {"urlEncode"}) public static String formEncode(String text) { if (text == null) { return null; } return Utf8UrlCoder.encode(text); }
/** * Encode the input for transfer. We use something a lot like HTML form * encodings. * @param in map of parameters to encode */ private byte[] serialize(Map<String, String> in) { StringBuilder sb = new StringBuilder(); for (Map.Entry<String, String> val : in.entrySet()) { sb.append(Utf8UrlCoder.encode(val.getKey())); sb.append('='); sb.append(Utf8UrlCoder.encode(val.getValue())); sb.append('&'); } if (sb.length() > 0) { sb.deleteCharAt(sb.length() - 1); // Remove the last & } return CharsetUtil.getUtf8Bytes(sb.toString()); }
/** * Encodes a token using the a plaintext dummy format. * @param token token to encode * @return token with values separated by colons */ public String encodeToken(SecurityToken token) { return Joiner.on(":").join( Utf8UrlCoder.encode(token.getOwnerId()), Utf8UrlCoder.encode(token.getViewerId()), Utf8UrlCoder.encode(token.getAppId()), Utf8UrlCoder.encode(token.getDomain()), Utf8UrlCoder.encode(token.getAppUrl()), Long.toString(token.getModuleId()), Utf8UrlCoder.encode(token.getContainer())); }
/** * Encodes a token using the a plaintext dummy format. * @param token token to encode * @return token with values separated by colons */ public String encodeToken(SecurityToken token) { return Joiner.on(":").join( Utf8UrlCoder.encode(token.getOwnerId()), Utf8UrlCoder.encode(token.getViewerId()), Utf8UrlCoder.encode(token.getAppId()), Utf8UrlCoder.encode(token.getDomain()), Utf8UrlCoder.encode(token.getAppUrl()), Long.toString(token.getModuleId()), Utf8UrlCoder.encode(token.getContainer())); }
@Test public void encodeComplex() { assertEquals(ENCODED_COMPLEX, Utf8UrlCoder.encode(RAW_COMPLEX)); }
@Test public void encodeSimple() { assertEquals(ENCODED_SIMPLE, Utf8UrlCoder.encode(RAW_SIMPLE)); }
@Test public void encodeSimple() { assertEquals(ENCODED_SIMPLE, Utf8UrlCoder.encode(RAW_SIMPLE)); }
@Test public void encodeComplex() { assertEquals(ENCODED_COMPLEX, Utf8UrlCoder.encode(RAW_COMPLEX)); }
@Test public void encodeSimple() { assertEquals(ENCODED_SIMPLE, Utf8UrlCoder.encode(RAW_SIMPLE)); }
@Test public void encodeComplex() { assertEquals(ENCODED_COMPLEX, Utf8UrlCoder.encode(RAW_COMPLEX)); }
@Test public void encodeComplex() { assertEquals(ENCODED_COMPLEX, Utf8UrlCoder.encode(RAW_COMPLEX)); }
@Test public void encodeSimple() { assertEquals(ENCODED_SIMPLE, Utf8UrlCoder.encode(RAW_SIMPLE)); }
@Test public void encodeSimple() { assertEquals(ENCODED_SIMPLE, Utf8UrlCoder.encode(RAW_SIMPLE)); }
@Test public void encodeComplex() { assertEquals(ENCODED_COMPLEX, Utf8UrlCoder.encode(RAW_COMPLEX)); }
protected void normalizeProtocol(HttpRequest request) throws GadgetException { // Normalize the protocol part of the URI if (request.getUri().getScheme()== null) { throw new GadgetException(GadgetException.Code.INVALID_PARAMETER, "Url " + request.getUri().toString() + " does not include scheme", HttpResponse.SC_BAD_REQUEST); } else if (!"http".equals(request.getUri().getScheme()) && !"https".equals(request.getUri().getScheme())) { throw new GadgetException(GadgetException.Code.INVALID_PARAMETER, "Invalid request url scheme in url: " + Utf8UrlCoder.encode(request.getUri().toString()) + "; only \"http\" and \"https\" supported.", HttpResponse.SC_BAD_REQUEST); } } }
protected void normalizeProtocol(HttpRequest request) throws GadgetException { // Normalize the protocol part of the URI if (request.getUri().getScheme()== null) { throw new GadgetException(GadgetException.Code.INVALID_PARAMETER, "Url " + request.getUri().toString() + " does not include scheme", HttpResponse.SC_BAD_REQUEST); } else if (!"http".equals(request.getUri().getScheme()) && !"https".equals(request.getUri().getScheme())) { throw new GadgetException(GadgetException.Code.INVALID_PARAMETER, "Invalid request url scheme in url: " + Utf8UrlCoder.encode(request.getUri().toString()) + "; only \"http\" and \"https\" supported.", HttpResponse.SC_BAD_REQUEST); } } }