Example usage for org.apache.http.client.utils URLEncodedUtils parse

List of usage examples for org.apache.http.client.utils URLEncodedUtils parse

Introduction

In this page you can find the example usage for org.apache.http.client.utils URLEncodedUtils parse.

Prototype

public static List<NameValuePair> parse(final String s, final Charset charset) 

Source Link

Document

Returns a list of NameValuePair NameValuePairs as parsed from the given string using the given character encoding.

Usage

From source file:org.activiti.app.rest.editor.DecisionTablesResource.java

@RequestMapping(method = RequestMethod.GET, produces = "application/json")
public ResultListDataRepresentation getDecisionTables(HttpServletRequest request) {
    // need to parse the filterText parameter ourselves, due to encoding issues with the default parsing.
    String filter = null;//from   w w  w .j a v a 2  s  .  com
    List<NameValuePair> params = URLEncodedUtils.parse(request.getQueryString(), Charset.forName("UTF-8"));
    if (params != null) {
        for (NameValuePair nameValuePair : params) {
            if ("filter".equalsIgnoreCase(nameValuePair.getName())) {
                filter = nameValuePair.getValue();
            }
        }
    }
    return decisionTableService.getDecisionTables(filter);
}

From source file:com.bt.download.android.gui.httpserver.BrowseHandler.java

@Override
public void handle(HttpExchange exchange) throws IOException {
    assertUPnPActive();/*from  w w w . jav  a2  s . co m*/

    GZIPOutputStream os = null;

    byte type = -1;

    try {

        List<NameValuePair> query = URLEncodedUtils.parse(exchange.getRequestURI(), "UTF-8");

        for (NameValuePair item : query) {
            if (item.getName().equals("type")) {
                type = Byte.parseByte(item.getValue());
            }
        }

        if (type == -1) {
            exchange.sendResponseHeaders(Code.HTTP_BAD_REQUEST, 0);
            return;
        }

        String response = getResponse(exchange, type);

        exchange.getResponseHeaders().set("Content-Encoding", "gzip");
        exchange.getResponseHeaders().set("Content-Type", "text/json; charset=UTF-8");
        exchange.sendResponseHeaders(Code.HTTP_OK, 0);

        os = new GZIPOutputStream(exchange.getResponseBody());

        os.write(response.getBytes("UTF-8"));
        os.finish();

    } catch (IOException e) {
        LOG.warning("Error browsing files type=" + type);
        throw e;
    } finally {
        if (os != null) {
            os.close();
        }
        exchange.close();
    }
}

From source file:org.xwiki.velocity.tools.URLTool.java

/**
 * Parse a query string into a map of key-value pairs.
 * /* ww w  . j a va  2s  . c o  m*/
 * @param query query string to be parsed
 * @return a mapping of parameter names to values suitable e.g. to pass into {@link EscapeTool#url(Map)}
 */
public Map<String, List<String>> parseQuery(String query) {
    Map<String, List<String>> queryParams = new LinkedHashMap<>();
    if (query != null) {
        for (NameValuePair params : URLEncodedUtils.parse(query, StandardCharsets.UTF_8)) {
            String name = params.getName();
            List<String> values = queryParams.get(name);
            if (values == null) {
                values = new ArrayList<>();
                queryParams.put(name, values);
            }
            values.add(params.getValue());
        }
    }
    return queryParams;
}

From source file:net.facework.core.streaming.misc.UriParser.java

public static void parse(String uri, Session session) throws IllegalStateException, IOException {
    boolean flash = false;
    int camera = CameraInfo.CAMERA_FACING_FRONT;
    Log.i("UriParser", "RTSP server received:" + uri);
    String[] uriItem = uri.split("/");
    filename = uriItem[uriItem.length - 1];

    List<NameValuePair> params = URLEncodedUtils.parse(URI.create(uri), "UTF-8");
    if (params.size() > 0) {

        // Those parameters must be parsed first or else they won't necessarily be taken into account
        for (Iterator<NameValuePair> it = params.iterator(); it.hasNext();) {
            NameValuePair param = it.next();
            // play file
            if (param.getName().equals("file")) {
                Log.i("UriParser", "file name:" + param.getValue());
                session.setFile(param.getValue());
                session.addFileVideoTrack(Session.FILE_VIDEO_H264);
                Log.i("UriParser", "RTSP work in FILE_VIDEO_H264 Mode. FILE:" + param.getValue());
                session.addFileAudioTrack(Session.FILE_AUDIO_AAC);
                Log.i("UriParser", "RTSP work in FILE_AUDIO_AAC Mode. FILE:" + param.getValue());
                session.setFileMode();//from  w  ww .  j  a  va  2 s .co m

                break;
            }
            // FLASH ON/OFF
            if (param.getName().equals("flash")) {
                if (param.getValue().equals("on"))
                    flash = true;
                else
                    flash = false;
            }

            // CAMERA -> the client can choose between the front facing camera and the back facing camera
            else if (param.getName().equals("camera")) {
                if (param.getValue().equals("back"))
                    camera = CameraInfo.CAMERA_FACING_BACK;
                else if (param.getValue().equals("front"))
                    camera = CameraInfo.CAMERA_FACING_FRONT;
            }

            // MULTICAST -> the stream will be sent to a multicast group
            // The default mutlicast address is 228.5.6.7, but the client can specify one 
            else if (param.getName().equals("multicast")) {
                session.setRoutingScheme(Session.MULTICAST);
                if (param.getValue() != null) {
                    try {
                        InetAddress addr = InetAddress.getByName(param.getValue());
                        if (!addr.isMulticastAddress()) {
                            throw new IllegalStateException("Invalid multicast address !");
                        }
                        session.setDestination(addr);
                    } catch (UnknownHostException e) {
                        throw new IllegalStateException("Invalid multicast address !");
                    }
                } else {
                    // Default multicast address
                    session.setDestination(InetAddress.getByName("228.5.6.7"));
                }
            }

            // UNICAST -> the client can use this so specify where he wants the stream to be sent
            else if (param.getName().equals("unicast")) {
                if (param.getValue() != null) {
                    try {
                        InetAddress addr = InetAddress.getByName(param.getValue());
                        session.setDestination(addr);
                    } catch (UnknownHostException e) {
                        throw new IllegalStateException("Invalid destination address !");
                    }
                }
            }

            // TTL -> the client can modify the time to live of packets
            // By default ttl=64
            else if (param.getName().equals("ttl")) {
                if (param.getValue() != null) {
                    try {
                        int ttl = Integer.parseInt(param.getValue());
                        if (ttl < 0)
                            throw new IllegalStateException("The TTL must be a positive integer !");
                        session.setTimeToLive(ttl);
                    } catch (Exception e) {
                        throw new IllegalStateException("The TTL must be a positive integer !");
                    }
                }
            }

            // No tracks will be added to the session
            else if (param.getName().equals("stop")) {
                return;
            }

        }

        for (Iterator<NameValuePair> it = params.iterator(); it.hasNext();) {
            NameValuePair param = it.next();

            // H264
            if (param.getName().equals("h264")) {
                VideoQuality quality = VideoQuality.parseQuality(param.getValue());
                session.addVideoTrack(Session.VIDEO_H264, camera, quality, flash);
            }

            // H263
            else if (param.getName().equals("h263")) {
                VideoQuality quality = VideoQuality.parseQuality(param.getValue());
                session.addVideoTrack(Session.VIDEO_H263, camera, quality, flash);
            }

            // AMRNB
            else if (param.getName().equals("amrnb") || param.getName().equals("amr")) {
                session.addAudioTrack(Session.AUDIO_AMRNB);
            }

            // AAC
            else if (param.getName().equals("aac")) {
                session.addAudioTrack(Session.AUDIO_AAC);
            }

            // Generic Audio Stream -> make use of api level 12
            // TODO: Doesn't work :/
            else if (param.getName().equals("testnewapi")) {
                session.addAudioTrack(Session.AUDIO_ANDROID_AMR);
            }

        }

        // The default behavior is to only add one video track
        if (session.getTrackCount() == 0) {
            session.addVideoTrack();
            session.addAudioTrack();
        }

    } else if (!filename.contains(":")) {
        if (filename.equals("h264.sdp")) {
            VideoQuality quality = VideoQuality.defaultVideoQualiy.clone();
            session.addVideoTrack(Session.VIDEO_H264, camera, quality, flash);
        } else {
            Log.i("UriParser", "file name:" + filename + ";");
            session.setFile(filename);
            session.addFileVideoTrack(Session.FILE_VIDEO_H264);
            Log.i("UriParser", "RTSP work in FILE_VIDEO_H264 Mode. FILE:" + filename);
            /*session.addFileAudioTrack(Session.FILE_AUDIO_AAC);
            Log.i("UriParser","RTSP work in FILE_AUDIO_AAC Mode. FILE:"+filename);*/
            session.setFileMode();
        }

    }
    // Uri has no parameters: the default behavior is to only add one video track
    else {
        session.addVideoTrack();
        session.addAudioTrack();
    }
}

From source file:com.github.mike10004.pac4j.oauth.googleappsdomainclient.GoogleAppsDomainApi20Test.java

@Test
public void testGetAuthorizationUrl() throws Exception {
    System.out.println("test getAuthorizationUrl");

    String clientId = "someRandomChars.apps.googleusercontent.com";
    String clientSecret = "someMoreRandomness";
    String callbackUri = "https://app.example.com/oauth/callback";
    String scope = PROFILE_SCOPE + ' ' + EMAIL_SCOPE;
    OutputStream stream = null;//  www  . j a  v  a 2 s.  c om
    String domain = "example.com";
    OAuthConfig config = new GoogleAppsDomainOAuthConfig(clientId, clientSecret, callbackUri,
            SignatureType.Header, scope, stream, domain);

    GoogleAppsDomainApi20 api = new GoogleAppsDomainApi20();
    String authorizationUrl = api.getAuthorizationUrl(config);

    URI uri = URI.create(authorizationUrl);
    System.out.println("authorization URL = " + authorizationUrl);
    List<NameValuePair> queryParts = URLEncodedUtils.parse(uri, Charsets.UTF_8.name());
    assertParameterValue(queryParts, "hd", domain);
    assertParameterValue(queryParts, "scope", scope);
    assertParameterValue(queryParts, "redirect_uri", callbackUri);
    assertParameterValue(queryParts, "client_id", clientId);
}

From source file:org.wikimedia.analytics.kraken.pig.CanonicalizeArticleTitleTest.java

@Test
public void testSemiColonInUri() throws URISyntaxException, MalformedURLException {
    // A bug in Apache HttpComponents 4.0.x means
    // that it is not properly handling semicolons to separate key/values
    // in a query String. The solution is to replace the semicolon with an
    // ampersand.

    String urlString = "http://m.heise.de/newsticker/meldung/TomTom-baut-um-1643641.html?mrw_channel=ho;mrw_channel=ho;from-classic=1";
    URL url = new URL(urlString.replace(";", "&"));
    URLEncodedUtils.parse(url.toURI(), "utf-8");
}

From source file:com.nebel_tv.content.api.ContentWrapper.java

@Override
public WrapperResponse getMediaData(String url) {

    try {/*from   ww  w .j av  a2 s .co m*/
        String name = getUrlLastSegment(url);
        IWrapperMethod method = WrapperMethodFactory.getMethodByName(name);

        if (method != null) {
            List<NameValuePair> pairs = URLEncodedUtils.parse(new URI(url), "UTF-8");

            Map<String, String> params = new HashMap<String, String>();
            for (NameValuePair param : pairs) {
                params.put(param.getName(), param.getValue());
            }
            return method.execute(params);
        }
    } catch (URISyntaxException ex) {
        Logger.getLogger(ContentWrapper.class.getName()).log(Level.WARNING, null, ex);
    } catch (InvalidParameterException ex) {
        Logger.getLogger(ContentWrapper.class.getName()).log(Level.SEVERE, null, ex);

        return new WrapperResponse(ResponseResult.InvalidParams, ResponseType.Content, "");
    }
    return new WrapperResponse(ResponseResult.InvalidUrl, ResponseType.Content, "");
}

From source file:org.apache.marmotta.ldclient.provider.phpbb.mapping.PHPBBForumHrefMapper.java

@Override
public List<Value> map(String resourceUri, Element selectedValue, ValueFactory factory) {
    String baseUriSite = resourceUri.substring(0, resourceUri.lastIndexOf('/'));
    String baseUriTopic = baseUriSite + "/viewforum.php?";

    try {/*from   w w  w  .j av  a2  s  . co  m*/
        URI uri = new URI(selectedValue.absUrl("href"));
        Map<String, String> params = new HashMap<String, String>();
        for (NameValuePair p : URLEncodedUtils.parse(uri, "UTF-8")) {
            params.put(p.getName(), p.getValue());
        }

        return Collections.singletonList((Value) factory.createURI(baseUriTopic + "f=" + params.get("f")));
    } catch (URISyntaxException ex) {
        throw new RuntimeException("invalid syntax for URI", ex);
    }
}

From source file:org.bml.util.RequestDataContainer.java

/**
 * Accepts a URI and parses out the parameters if there are any.
 * @param theUri A vaild URI//from ww w .  j av a 2s  .  c om
 * @return a map of key - distinct values representing the parameters in the URI if any 
 *
 * @pre theUri!=null
 */
public static Map<String, Set<String>> parseURIParams(final URI theUri) {
    if (CHECKED) {
        Preconditions.checkNotNull(theUri, "Can not parse parameters from a null URI");
    }
    List<NameValuePair> paramList = URLEncodedUtils.parse(theUri, CharEncoding.UTF_8);
    Map<String, Set<String>> paramMap = new HashMap<String, Set<String>>();
    Set<String> tmpValues = null;
    for (NameValuePair pair : paramList) {
        tmpValues = paramMap.get(pair.getName());
        if (tmpValues == null) {
            tmpValues = new HashSet<String>();
            paramMap.put(pair.getName(), tmpValues);
        }
        tmpValues.add(pair.getValue());
    }
    return paramMap;
}

From source file:org.mobicents.servlet.restcomm.http.client.HttpRequestDescriptor.java

public HttpRequestDescriptor(final URI uri, final String method, final List<NameValuePair> parameters) {
    super();//from   ww  w . j a v  a2  s . c o  m
    this.uri = base(uri);
    this.method = method;
    if (parameters != null) {
        this.parameters = parameters;
    } else {
        this.parameters = new ArrayList<NameValuePair>();
    }
    final String query = uri.getQuery();
    if (query != null) {
        final List<NameValuePair> other = URLEncodedUtils.parse(uri, "UTF-8");
        parameters.addAll(other);
    }
}