Java URL Resolve resolveGoogleRedirect(String url)

Here you can find the source of resolveGoogleRedirect(String url)

Description

Exctract redirect target from google's redirect url

License

Apache License

Declaration

public static String resolveGoogleRedirect(String url) throws URISyntaxException, UnsupportedEncodingException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLDecoder;

public class Main {
    /** Exctract redirect target from google's redirect url */
    public static String resolveGoogleRedirect(String url) throws URISyntaxException, UnsupportedEncodingException {
        String query = new URI(url).getRawQuery();
        for (String param : query.split("&"))
            if (param.contains("=")) {
                String[] parts = param.split("=");
                if (parts.length == 2 && parts[0].equals("url")) {
                    return URLDecoder.decode(parts[1], "UTF-8");
                }//from w w  w  . j  a  va 2 s .  c o  m
            }
        throw new IllegalArgumentException("google redirect not found for url: " + url);
    }
}

Related

  1. resolve(final URL url)
  2. resolve(URL base, String relUrl)
  3. resolve(URL base, String uri)
  4. resolveHref(String baseUrl, String href)
  5. resolveManifestResources(final URL manifestUrl, final List resources)
  6. resolvePlatformUrl(String urlspec)
  7. resolveRelativeURL(final URL primaryUrl, final String relativeLoc)