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:io.joynr.messaging.bounceproxy.IsCreateChannelHttpRequest.java

@Override
public boolean matches(Object argument) {

    HttpRequest request = (HttpRequest) argument;

    // check if tracking ID is sent in header
    Header trackingIdHeader = request.getFirstHeader("X-Atmosphere-tracking-id");
    if (trackingIdHeader == null) {
        // no tracking ID header set at all
        return false;
    } else {/*from  ww w .j a v a  2  s  .  co  m*/
        if (!trackingIdHeader.getValue().equals(trackingId)) {
            // wrong tracking ID header set
            return false;
        }
    }

    // check if channel ID is sent as query parameter ccid
    List<NameValuePair> queryParameters = URLEncodedUtils.parse(URI.create(request.getRequestLine().getUri()),
            "UTF-8");
    for (NameValuePair queryParameter : queryParameters) {
        if (queryParameter.getName().equals("ccid") && queryParameter.getValue().equals(ccid)) {
            // right channel ID sent
            return true;
        } else {
            // wrong channel ID sent
            return false;
        }
    }
    // no query parameter with ccid sent at all
    return false;
}

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

public HttpRequestDescriptor(final URI uri, final String method, final List<NameValuePair> parameters)
        throws UnsupportedEncodingException, URISyntaxException {
    super();//from w ww.j a va  2s.c  o  m
    this.uri = URIUtils.createURI(uri.getScheme(), uri.getHost(), uri.getPort(), uri.getPath(), null, null);
    this.method = method;
    final String query = uri.getQuery();
    if (query != null) {
        parameters.addAll(URLEncodedUtils.parse(uri, "UTF-8"));
    }
    this.parameters = parameters;
}

From source file:jobhunter.cb.Client.java

public Job execute() throws IOException, URISyntaxException {
    l.debug("Connecting to {}", url);

    update("Connecting", 1L);
    final Document doc = Jsoup.connect(url).get();

    update("Parsing HTML", 2L);
    final Job job = Job.of();
    job.setPortal(CareerBuilderPlugin.portal);
    job.setLink(url);//  ww w .  j a  v a 2s.  co  m

    URLEncodedUtils.parse(new URI(url), "UTF-8").stream()
            .filter(nvp -> nvp.getName().equalsIgnoreCase("job_did")).findFirst()
            .ifPresent(param -> job.setExtId(param.getValue()));

    job.setPosition(doc.getElementById("job-title").text());
    job.setAddress(doc.getElementById("CBBody_Location").text());

    job.getCompany().setName(doc.getElementById("CBBody_CompanyName").text());

    StringBuilder description = new StringBuilder();

    description.append(StringEscapeUtils.unescapeHtml4(doc.getElementById("pnlJobDescription").html()));

    Element div = doc.getElementById("job-requirements");

    description.append(StringEscapeUtils.unescapeHtml4(div.getElementsByClass("section-body").html()));

    div = doc.getElementById("job-snapshot-section");

    description.append(StringEscapeUtils.unescapeHtml4(div.getElementsByClass("section-body").html()));

    job.setDescription(description.toString());
    update("Done", 3L);
    return job;
}

From source file:net.majorkernelpanic.streaming.rtsp.UriParser.java

/**
 * Configures a Session according to the given URI.
 * Here are some examples of URIs that can be used to configure a Session:
 * <ul><li>rtsp://xxx.xxx.xxx.xxx:8086?h264&flash=on</li>
 * <li>rtsp://xxx.xxx.xxx.xxx:8086?h263&camera=front&flash=on</li>
 * <li>rtsp://xxx.xxx.xxx.xxx:8086?h264=200-20-320-240</li>
 * <li>rtsp://xxx.xxx.xxx.xxx:8086?aac</li></ul>
 * @param uri The URI//  ww  w  .j  a v  a2s .  c om
 * @throws IllegalStateException
 * @throws IOException
 * @return A Session configured according to the URI
 */
public static Session parse(String uri) throws IllegalStateException, IOException {
    SessionBuilder builder = SessionBuilder.getInstance().clone();

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

        builder.setAudioEncoder(AUDIO_NONE).setVideoEncoder(VIDEO_NONE);

        // 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();

            // FLASH ON/OFF
            if (param.getName().equalsIgnoreCase("flash")) {
                if (param.getValue().equalsIgnoreCase("on"))
                    builder.setFlashEnabled(true);
                else
                    builder.setFlashEnabled(false);
            }

            // CAMERA -> the client can choose between the front facing camera and the back facing camera
            else if (param.getName().equalsIgnoreCase("camera")) {
                if (param.getValue().equalsIgnoreCase("back"))
                    builder.setCamera(CameraInfo.CAMERA_FACING_BACK);
                else if (param.getValue().equalsIgnoreCase("front"))
                    builder.setCamera(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 another
            else if (param.getName().equalsIgnoreCase("multicast")) {
                if (param.getValue() != null) {
                    try {
                        InetAddress addr = InetAddress.getByName(param.getValue());
                        if (!addr.isMulticastAddress()) {
                            throw new IllegalStateException("Invalid multicast address !");
                        }
                        builder.setDestination(addr);
                    } catch (UnknownHostException e) {
                        throw new IllegalStateException("Invalid multicast address !");
                    }
                } else {
                    // Default multicast address
                    builder.setDestination(InetAddress.getByName("228.5.6.7"));
                }
            }

            // UNICAST -> the client can use this to specify where he wants the stream to be sent
            else if (param.getName().equalsIgnoreCase("unicast")) {
                if (param.getValue() != null) {
                    try {
                        InetAddress addr = InetAddress.getByName(param.getValue());
                        builder.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().equalsIgnoreCase("ttl")) {
                if (param.getValue() != null) {
                    try {
                        int ttl = Integer.parseInt(param.getValue());
                        if (ttl < 0)
                            throw new IllegalStateException();
                        builder.setTimeToLive(ttl);
                    } catch (Exception e) {
                        throw new IllegalStateException("The TTL must be a positive integer !");
                    }
                }
            }

            // H.264
            else if (param.getName().equalsIgnoreCase("h264")) {
                VideoQuality quality = VideoQuality.parseQuality(param.getValue());
                builder.setVideoQuality(quality).setVideoEncoder(VIDEO_H264);
            }

            // H.263
            else if (param.getName().equalsIgnoreCase("h263")) {
                VideoQuality quality = VideoQuality.parseQuality(param.getValue());
                builder.setVideoQuality(quality).setVideoEncoder(VIDEO_H263);
            }

            // AMR
            else if (param.getName().equalsIgnoreCase("amrnb") || param.getName().equalsIgnoreCase("amr")) {
                AudioQuality quality = AudioQuality.parseQuality(param.getValue());
                builder.setAudioQuality(quality).setAudioEncoder(AUDIO_AMRNB);
            }

            // AAC
            else if (param.getName().equalsIgnoreCase("aac")) {
                AudioQuality quality = AudioQuality.parseQuality(param.getValue());
                builder.setAudioQuality(quality).setAudioEncoder(AUDIO_AAC);
            }

        }

    }

    if (builder.getVideoEncoder() == VIDEO_NONE && builder.getAudioEncoder() == AUDIO_NONE) {
        SessionBuilder b = SessionBuilder.getInstance();
        builder.setVideoEncoder(b.getVideoEncoder());
        builder.setAudioEncoder(b.getAudioEncoder());
    }

    return builder.build();

}

From source file:com.google.android.vending.licensing.ResponseData.java

private static Map<String, String> decodeExtras(String extras) {
    Map<String, String> results = new HashMap<>();
    URI rawExtras;//from  ww w .  ja v  a 2  s .  co  m
    try {
        rawExtras = new URI("?" + extras);
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException("Invalid syntax error while decoding extras data from " + "server.");
    }

    List<NameValuePair> extraList = URLEncodedUtils.parse(rawExtras, "UTF-8");
    for (NameValuePair item : extraList) {
        String name = item.getName();
        int i = 0;
        while (results.containsKey(name)) {
            name = item.getName() + ++i;
        }
        results.put(name, item.getValue());
    }
    return results;
}

From source file:com.cognifide.qa.bb.proxy.analyzer.predicate.RequestPredicateImpl.java

@Override
public boolean accepts(HttpRequest request) {
    boolean result = false;
    URI uri = URI.create(request.getUri());
    String path = uri.getPath();/*  w  w w. ja va 2s .c  o  m*/
    if (path != null && path.startsWith(urlPrefix)) {
        String query = uri.getQuery();
        if (expectedParams.isEmpty() && StringUtils.isEmpty(query)) {
            result = true;
        } else if (StringUtils.isNotEmpty(query)) {
            List<NameValuePair> params = URLEncodedUtils.parse(query, Charsets.UTF_8);
            result = hasAllExpectedParams(expectedParams, params);
        }
    }
    return result;
}

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

@Test
public void test() throws URISyntaxException, MalformedURLException {
    //URL url = new URL("http://en.wikipedia.org/w/index.php?search=symptoms+of+vitamin+d+deficiency&title=Special%3ASearch");
    URL url = new URL("http://en.wikipedia.org/w/index.php?");
    URLEncodedUtils.parse(url.toURI(), "utf-8");
}

From source file:cn.ysu.edu.realtimeshare.librtsp.rtsp.UriParser.java

/**
 * Configures a Session according to the given URI.
 * Here are some examples of URIs that can be used to configure a Session:
 * <ul><li>rtsp://xxx.xxx.xxx.xxx:8086?h264&flash=on</li>
 * <li>rtsp://xxx.xxx.xxx.xxx:8086?h263&camera=front&flash=on</li>
 * <li>rtsp://xxx.xxx.xxx.xxx:8086?h264=200-20-320-240</li>
 * <li>rtsp://xxx.xxx.xxx.xxx:8086?aac</li></ul>
 * @param uri The URI/*  ww w . j  av a2  s.c o  m*/
 * @throws IllegalStateException
 * @throws IOException
 * @return A Session configured according to the URI
 */
public static Session parse(String uri) throws IllegalStateException, IOException {
    SessionBuilder builder = SessionBuilder.getInstance().clone();
    byte audioApi = 0, videoApi = 0;

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

        builder.setAudioEncoder(AUDIO_NONE).setVideoEncoder(VIDEO_NONE);

        // 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();

            // FLASH ON/OFF
            if (param.getName().equalsIgnoreCase("flash")) {
                if (param.getValue().equalsIgnoreCase("on"))
                    builder.setFlashEnabled(true);
                else
                    builder.setFlashEnabled(false);
            }

            // CAMERA -> the client can choose between the front facing camera and the back facing camera
            else if (param.getName().equalsIgnoreCase("camera")) {
                if (param.getValue().equalsIgnoreCase("back"))
                    builder.setCamera(CameraInfo.CAMERA_FACING_BACK);
                else if (param.getValue().equalsIgnoreCase("front"))
                    builder.setCamera(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 another
            else if (param.getName().equalsIgnoreCase("multicast")) {
                if (param.getValue() != null) {
                    try {
                        InetAddress addr = InetAddress.getByName(param.getValue());
                        if (!addr.isMulticastAddress()) {
                            throw new IllegalStateException("Invalid multicast address !");
                        }
                        builder.setDestination(param.getValue());
                    } catch (UnknownHostException e) {
                        throw new IllegalStateException("Invalid multicast address !");
                    }
                } else {
                    // Default multicast address
                    builder.setDestination("228.5.6.7");
                }
            }

            // UNICAST -> the client can use this to specify where he wants the stream to be sent
            else if (param.getName().equalsIgnoreCase("unicast")) {
                if (param.getValue() != null) {
                    builder.setDestination(param.getValue());
                }
            }

            // VIDEOAPI -> can be used to specify what api will be used to encode video (the MediaRecorder API or the MediaCodec API)
            else if (param.getName().equalsIgnoreCase("videoapi")) {
                if (param.getValue() != null) {
                    if (param.getValue().equalsIgnoreCase("mr")) {
                        videoApi = MediaStream.MODE_MEDIARECORDER_API;
                    } else if (param.getValue().equalsIgnoreCase("mc")) {
                        videoApi = MediaStream.MODE_MEDIACODEC_API;
                    }
                }
            }

            // AUDIOAPI -> can be used to specify what api will be used to encode audio (the MediaRecorder API or the MediaCodec API)
            else if (param.getName().equalsIgnoreCase("audioapi")) {
                if (param.getValue() != null) {
                    if (param.getValue().equalsIgnoreCase("mr")) {
                        audioApi = MediaStream.MODE_MEDIARECORDER_API;
                    } else if (param.getValue().equalsIgnoreCase("mc")) {
                        audioApi = MediaStream.MODE_MEDIACODEC_API;
                    }
                }
            }

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

            // H.264
            else if (param.getName().equalsIgnoreCase("h264")) {
                VideoQuality quality = VideoQuality.parseQuality(param.getValue());
                builder.setVideoQuality(quality).setVideoEncoder(VIDEO_H264);
            }

            // H.263
            else if (param.getName().equalsIgnoreCase("h263")) {
                VideoQuality quality = VideoQuality.parseQuality(param.getValue());
                builder.setVideoQuality(quality).setVideoEncoder(VIDEO_H263);
            }

            // AMR
            else if (param.getName().equalsIgnoreCase("amrnb") || param.getName().equalsIgnoreCase("amr")) {
                AudioQuality quality = AudioQuality.parseQuality(param.getValue());
                builder.setAudioQuality(quality).setAudioEncoder(AUDIO_AMRNB);
            }

            // AAC
            else if (param.getName().equalsIgnoreCase("aac")) {
                AudioQuality quality = AudioQuality.parseQuality(param.getValue());
                builder.setAudioQuality(quality).setAudioEncoder(AUDIO_AAC);
            }

        }

    }

    if (builder.getVideoEncoder() == VIDEO_NONE && builder.getAudioEncoder() == AUDIO_NONE) {
        SessionBuilder b = SessionBuilder.getInstance();
        builder.setVideoEncoder(b.getVideoEncoder());
        builder.setAudioEncoder(b.getAudioEncoder());
    }

    Session session = builder.build();

    if (videoApi > 0 && session.getVideoTrack() != null) {
        session.getVideoTrack().setStreamingMethod(videoApi);
    }

    if (audioApi > 0 && session.getAudioTrack() != null) {
        session.getAudioTrack().setStreamingMethod(audioApi);
    }

    return session;

}

From source file:com.soft160.app.blobstore.HttpMessageHandler.java

private void Get(HttpExchange he) throws IOException, RocksDBException, ClassNotFoundException {
    List<NameValuePair> pairs = URLEncodedUtils.parse(he.getRequestURI().getQuery(), StandardCharsets.UTF_8);
    UUID bucket = null, file = null;
    for (NameValuePair pair : pairs) {
        if (pair.getName().equalsIgnoreCase("bucket")) {
            bucket = parseUUID(pair.getValue());
        } else if (pair.getName().equalsIgnoreCase("blob")) {
            file = parseUUID(pair.getValue());
        }//www.  j  av a  2  s . com
    }
    if (bucket == null || file == null) {
        SendResponse(he, HttpStatus.SC_BAD_REQUEST, "Unknown bucket/file");
    }

    BlobInfo info = localStore.GetBlob(bucket, file);
    if (info == null) {
        SendResponse(he, HttpStatus.SC_NOT_FOUND, "bucket/file not found");
    } else {
        he.getResponseHeaders().add("Content-Type", "application/octet-stream");
        he.getResponseHeaders().add("Content-Length", Integer.toString(info.size));
        try (FileInputStream inFile = new FileInputStream(info.path)) {
            he.sendResponseHeaders(HttpStatus.SC_OK, inFile.getChannel().size());
            IOUtils.copy(inFile, he.getResponseBody());
        }
    }
}

From source file:org.carewebframework.ui.FrameworkWebSupport.java

/**
 * Converts the queryString to a map.//from ww  w  .  j ava 2  s  . c  o m
 * 
 * @param queryString The query string (leading "?" is optional)
 * @param valueDelimiter String to use to delimit multiple values for a parameter. May be null.
 * @return A map containing the arguments from the query string. This may return null if the
 *         queryString is empty.
 */
public static Map<String, String> queryStringToMap(final String queryString, String valueDelimiter) {
    if (queryString == null || queryString.isEmpty()) {
        return null;
    }

    try {
        valueDelimiter = valueDelimiter == null ? "" : valueDelimiter;
        URI uri = new URI(queryString.startsWith("?") ? queryString : ("?" + queryString));
        List<NameValuePair> params = URLEncodedUtils.parse(uri, StrUtil.CHARSET);

        final Map<String, String> result = new HashMap<String, String>();

        for (NameValuePair nvp : params) {
            String value = result.get(nvp.getName());
            result.put(nvp.getName(), (value == null ? "" : value + valueDelimiter) + nvp.getValue());
        }

        return result;
    } catch (URISyntaxException e) {
        return null;
    }
}