Example usage for org.apache.http.client.utils URIUtils createURI

List of usage examples for org.apache.http.client.utils URIUtils createURI

Introduction

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

Prototype

@Deprecated
public static URI createURI(final String scheme, final String host, final int port, final String path,
        final String query, final String fragment) throws URISyntaxException 

Source Link

Document

Constructs a URI using all the parameters.

Usage

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   ww  w. j  a v  a2 s .c  om
    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:edu.illinois.my.wiki.portlet.http.services.UriUtilsWrapper.java

@Override
public URI createUri(String urlPath, Parameters wikiParameters) {
    String serverAddress = server.asString();
    ImmutableList<NameValuePair> parameters = wikiParameters.asNameValuePairs();
    String path = URLEncodedUtils.format(parameters, ENCODING);
    try {/*from w ww . j a v a 2 s  . c  o m*/
        return URIUtils.createURI(SECURE_HTTP, serverAddress, defaultPort, urlPath, path, fragment);
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.switchfly.inputvalidation.sanitizer.UrlStripHtmlSanitizer.java

@Override
public String execute(String content) {
    if (StringUtils.isBlank(content)) {
        return content;
    }/*from   ww w . ja v a 2 s  .  c  om*/

    URI uri;
    try {
        uri = new URI(content);
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }

    List<NameValuePair> cleanedPairs = parse(uri);

    String queryString = cleanedPairs.isEmpty() ? null : URLEncodedUtils.format(cleanedPairs, ENCODING);

    try {
        return URIUtils.createURI(uri.getScheme(), uri.getHost(), uri.getPort(), uri.getPath(), queryString,
                uri.getFragment()).toString();
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.jzboy.couchdb.http.URITemplates.java

/**
 * URI used to see active tasks running on a server
 *//*from ww  w  . j  a v  a2s  . c om*/
public static URI activeTasks(String host, int port) throws URISyntaxException {
    return URIUtils.createURI("http", host, port, "_active_tasks", null, null);
}

From source file:de.huxhorn.whistler.services.TagdefTagDefinitionService.java

public TagDefinition define(String tag) {
    if (tag.startsWith("#")) {
        tag = tag.substring(1);//from   w  ww .  j  a v  a2s  .  co m
    }
    XMLStreamReader2 xmlStreamReader = null;
    try {
        BasicHttpParams params = new BasicHttpParams();
        DefaultHttpClient httpclient = new DefaultHttpClient(params);

        URI uri = URIUtils.createURI("http", "api.tagdef.com", -1, "/one." + tag, null, null);
        HttpGet httpget = new HttpGet(uri);
        if (logger.isDebugEnabled())
            logger.debug("HttpGet.uri={}", httpget.getURI());
        HttpResponse response = httpclient.execute(httpget);

        HttpEntity entity = response.getEntity();
        if (entity != null) {
            InputStream instream = entity.getContent();

            /*
            <?xml version="1.0" encoding="UTF-8"?>
            <defs>
               <def>
                  <text>#ff is the same as (short for) #followfriday.</text>
                  <time>2009-05-08 00:00:00</time>
                  <upvotes>38</upvotes>
                  <downvotes>7</downvotes>
                  <uri>http://tagdef.com/ff</uri>
               </def>
            </defs>
                    
            <?xml version="1.0" encoding="UTF-8"?>
            <defs>
               <uri>http://tagdef.com/nonexisting</uri>
            </defs>
             */

            xmlStreamReader = (XMLStreamReader2) WstxInputFactory.newInstance().createXMLStreamReader(instream);
            while (xmlStreamReader.hasNext()) {
                int type = xmlStreamReader.next();
                if (type == XMLStreamConstants.START_ELEMENT) {
                    String tagName = xmlStreamReader.getName().getLocalPart();
                    if ("def".equals(tagName)) {
                        TagDefinition result = new TagDefinition();
                        result.setTag("#" + tag);
                        while (xmlStreamReader.hasNext()) {
                            type = xmlStreamReader.next();
                            if (type == XMLStreamConstants.START_ELEMENT) {
                                tagName = xmlStreamReader.getName().getLocalPart();
                                if ("text".equals(tagName)) {
                                    result.setDefinition(xmlStreamReader.getElementText());
                                } else if ("uri".equals(tagName)) {
                                    result.setUrl(xmlStreamReader.getElementText());
                                }
                            } else if (type == XMLStreamConstants.END_ELEMENT) {
                                tagName = xmlStreamReader.getName().getLocalPart();
                                if ("def".equals(tagName)) {
                                    break;
                                }
                            }
                        }

                        return result;
                    }
                }
            }
            /*
            BufferedReader reader = new BufferedReader(new InputStreamReader(instream, "UTF-8"));
            StringBuilder builder=new StringBuilder();
            for(;;)
            {
               String line = reader.readLine();
               if(line == null)
               {
                  break;
               }
               if(builder.length() != 0)
               {
                  builder.append("\n");
               }
               builder.append(line);
            }
            if(logger.isInfoEnabled()) logger.info("Result: {}", builder);
            */
        }
    } catch (IOException ex) {
        if (logger.isWarnEnabled())
            logger.warn("Exception!", ex);
    } catch (URISyntaxException ex) {
        if (logger.isWarnEnabled())
            logger.warn("Exception!", ex);
    } catch (XMLStreamException ex) {
        if (logger.isWarnEnabled())
            logger.warn("Exception!", ex);
    } finally {
        if (xmlStreamReader != null) {
            try {
                xmlStreamReader.closeCompletely();
            } catch (XMLStreamException e) {
                // ignore
            }
        }
    }
    return null;
}

From source file:com.chuck.core.filter.FilterQuery.java

/**
 * Builds a http get for the transitService specified
 *
 * @return returns the  HTTP get// w ww  .j a v a2s  .co m
 */
@Override
public URI buildQuery() throws URISyntaxException {
    addParameter("api-key", TransitService.getApiKey());
    return URIUtils.createURI("http", BASE_REQUEST_URL, 0, transitService.getServiceName(),
            URLEncodedUtils.format(parameters, "UTF-8"), null);
}

From source file:uk.ac.jorum.integration.RestApiBaseTest.java

protected int getResponseCode(String endpoint, String queryString) throws Exception {
    URI uri = URIUtils.createURI(apiProtocol, apiHost, jettyPort(), jettyPath() + endpoint, queryString, null);
    HttpGet httpget = new HttpGet(uri);
    httpget.addHeader("Accept", "application/json");
    HttpResponse response = client.execute(httpget);
    return response.getStatusLine().getStatusCode();
}

From source file:com.nadmm.airports.tfr.TfrService.java

private void getTfrList(Intent intent) {
    boolean force = intent.getBooleanExtra(FORCE_REFRESH, false);

    File tfrFile = getFile(TFR_CACHE_NAME);
    if (!tfrFile.exists() || force) {
        URI uri;//ww w .j a v a2  s .  c o m
        try {
            uri = URIUtils.createURI("http", TFR_HOST, 80, TFR_PATH, TFR_QUERY, null);
            fetch(uri, tfrFile);
        } catch (URISyntaxException e) {
            UiUtils.showToast(this, "TFR: " + e.getMessage());
        }
    }

    TfrList tfrList = new TfrList();
    mParser.parse(tfrFile, tfrList);
    Collections.sort(tfrList.entries);

    Intent result = makeResultIntent(intent.getAction());
    result.putExtra(TFR_LIST, tfrList);
    sendResultIntent(result);
}

From source file:org.mahasen.thread.ReplicateRequestStarter.java

public void run() {
    for (String partName : resource.getPartNames()) {
        try {//from   w  w w  . ja va  2  s  .c  om

            URI uri = null;
            ArrayList<NameValuePair> qparams = new ArrayList<NameValuePair>();
            qparams.add(new BasicNameValuePair("parentFileName",
                    String.valueOf(resource.getProperty(MahasenConstants.FILE_NAME))));
            qparams.add(new BasicNameValuePair("partName", partName));
            uri = URIUtils.createURI("https",
                    resource.getSplittedPartsIpTable().get(partName).get(0) + ":"
                            + MahasenConstants.SERVER_PORT,
                    -1, "/mahasen/replicate_request_ajaxprocessor.jsp",
                    URLEncodedUtils.format(qparams, "UTF-8"), null);

            System.out.println("Target Address for Replicate Request : " + uri);

            HttpClient replicateHttpClient = new DefaultHttpClient();
            replicateHttpClient = SSLWrapper.wrapClient(replicateHttpClient);
            HttpPost httppost = new HttpPost(uri);

            HttpResponse response = replicateHttpClient.execute(httppost);
            System.out.println(
                    "--------- response to ReplicateRequestStarter----------" + response.getStatusLine());
        } catch (IOException e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        } catch (URISyntaxException e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        }

    }

}

From source file:com.nadmm.airports.tfr.TfrImageService.java

private void getTfrImage(Intent intent) {
    Tfr tfr = (Tfr) intent.getSerializableExtra(TFR_ENTRY);
    String notamId = tfr.notamId;
    int start = notamId.indexOf(' ');
    if (start > 0) {
        notamId = notamId.substring(start + 1);
    }/*  w w  w  .  j a  v  a 2s . c o  m*/
    notamId = notamId.replace("/", "_");

    String name = "sect_" + notamId + ".gif";
    File imageFile = getFile(name);

    if (!imageFile.exists()) {
        URI uri;
        try {
            uri = URIUtils.createURI("http", TFR_HOST, 80, TFR_PATH + "/" + name, null, null);
            fetch(uri, imageFile);
        } catch (URISyntaxException e) {
            UiUtils.showToast(this, "TFR: " + e.getMessage());
        }
    }

    Intent result = makeResultIntent(intent.getAction());
    if (imageFile.exists()) {
        result.putExtra(TFR_IMAGE_PATH, imageFile.getAbsolutePath());
    }
    sendResultIntent(result);
}