List of usage examples for org.apache.http.client.utils URIUtils createURI
@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
From source file:de.huxhorn.whistler.services.RealurlUrlUnshortener.java
public String unshorten(String url) { XMLStreamReader2 xmlStreamReader = null; try {/* w w w. ja va2 s. c o m*/ List<NameValuePair> qparams = new ArrayList<NameValuePair>(); // http://realurl.org/api/v1/getrealurl.php?url= qparams.add(new BasicNameValuePair("url", url)); BasicHttpParams params = new BasicHttpParams(); DefaultHttpClient httpclient = new DefaultHttpClient(params); URI uri = URIUtils.createURI("http", "realurl.org", -1, "/api/v1/getrealurl.php", URLEncodedUtils.format(qparams, "UTF-8"), 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(); xmlStreamReader = (XMLStreamReader2) WstxInputFactory.newInstance().createXMLStreamReader(instream); /* <root> <status>1</status> <url> <short>http://bit.ly/10QRTY</short> <real> http://uk.techcrunch.com/2009/04/09/tweetmeme-re-launches-to-gun-for-top-of-the-twitter-link-tree/ </real> </url> </root> */ while (xmlStreamReader.hasNext()) { int type = xmlStreamReader.next(); if (type == XMLStreamConstants.START_ELEMENT) { if ("real".equals(xmlStreamReader.getName().getLocalPart())) { return xmlStreamReader.getElementText(); } } } /* 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.jzboy.couchdb.http.URITemplates.java
/** * URI used to start a replication process between two databases *///from www .j a v a2s . com public static URI replicate(String host, int port) throws URISyntaxException { return URIUtils.createURI("http", host, port, "_replicate", null, null); }
From source file:com.controlj.addon.weather.util.HTTPHelper.java
public Document readDocument(String scheme, String host, int port, String path, Map<String, Object> params) throws IOException, URISyntaxException { URI uri = URIUtils.createURI(scheme, host, port, path, encodeParams(params), null); return httpclient.execute(new HttpGet(uri), new ResponseHandler<Document>() { //@Override public Document handleResponse(HttpResponse response) throws IOException { if (response.getStatusLine().getStatusCode() != 200) throw new IOException(response.getStatusLine().getReasonPhrase()); HttpEntity entity = response.getEntity(); if (entity != null) { String responseString = EntityUtils.toString(entity); try { SAXReader reader = new SAXReader(); return reader.read(new StringReader(responseString)); } catch (DocumentException e) { throw (IOException) new IOException("Service returned \"" + responseString + '"') .initCause(e); }// www . ja va 2 s . c om } throw new IOException("No response"); } }); }
From source file:org.mobicents.servlet.sip.restcomm.interpreter.http.HttpRequestDescriptor.java
public HttpUriRequest getHttpRequest() throws IllegalArgumentException, URISyntaxException, UnsupportedEncodingException { if ("GET".equalsIgnoreCase(method)) { final String query = URLEncodedUtils.format(parameters, "UTF-8"); final URI uri = URIUtils.createURI(this.uri.getScheme(), this.uri.getHost(), this.uri.getPort(), this.uri.getPath(), query, null); return new HttpGet(uri); } else if ("POST".equalsIgnoreCase(method)) { final HttpPost post = new HttpPost(uri); post.setEntity(new UrlEncodedFormEntity(parameters)); return post; } else {//from w ww .j av a 2 s . c o m throw new IllegalArgumentException(method + " is not a supported HTTP method."); } }
From source file:com.woonoz.proxy.servlet.UrlRewriterImpl.java
public URI rewriteUri(URI url) throws URISyntaxException, MalformedURLException { if (requestedUrlPointsToServlet(url)) { final String targetPath = rewritePathIfNeeded(url.getPath()); return URIUtils.createURI(targetServer.getProtocol(), targetServer.getHost(), targetServer.getPort(), targetPath, servletRequest.getQueryString(), null); } else {//from w w w . j a v a 2s . co m return url; } }
From source file:tjs.tuneramblr.util.TuneramblrUrlHelper.java
/** * builds the stem of the add song URL. this includes the protocol, port, * base, and location. note: this URL does NOT contain a query string. * /*from w w w . j ava 2 s .c om*/ * @return returns a string representing tuneramblr add song URL */ public URI getAddSongHttpPostUrl() { URI builtUrl = null; try { builtUrl = URIUtils.createURI(PROTOCOL_HTTP, TUNERAMBLR_BASE_URL, NO_PORT, TUNERAMBLR_ADD_SONG_URL, null, null); } catch (URISyntaxException e) { builtUrl = null; } return builtUrl; }
From source file:org.onsteroids.eve.api.provider.img.DefaultCharacterPortraitApi.java
@Override public CharacterPortrait getCharacterPortrait(long characterId, PortraitSize size) throws ApiException { HttpClient httpClient = httpClientProvider.get(); List<NameValuePair> qparams = Lists.newArrayList(); qparams.add(new BasicNameValuePair("c", Long.toString(characterId))); qparams.add(new BasicNameValuePair("s", Integer.toString(size.getSize()))); final URI requestURI; try {/*from w w w .j a va 2s.c om*/ requestURI = URIUtils.createURI(serverUri.getScheme(), serverUri.getHost(), serverUri.getPort(), serverUri.getPath(), URLEncodedUtils.format(qparams, "UTF-8"), null); } catch (URISyntaxException e) { throw new InternalApiException(e); } LOG.trace("Resulting URI: {}", requestURI); final HttpPost postRequest = new HttpPost(requestURI); // make the real call LOG.trace("Fetching result from {}...", serverUri); final HttpResponse response; try { response = httpClient.execute(postRequest); } catch (IOException e) { throw new InternalApiException(e); } if (!FORMAT.equals(response.getEntity().getContentType().getValue())) { throw new InternalApiException( "Failed to fetch portrait [" + response.getEntity().getContentType().getValue() + "]."); } try { return new DefaultCharacterPortrait(response); } catch (IOException e) { throw new InternalApiException(e); } }
From source file:com.jzboy.couchdb.http.URITemplates.java
/** * URI used to identify a database/* ww w . j a v a 2 s.co m*/ */ public static URI database(String host, int port, String dbName) throws URISyntaxException { return URIUtils.createURI("http", host, port, dbName, null, null); }
From source file:m2.android.archetype.api.BaseProtocol.java
/** * RTCS ? ./*from ww w.j av a 2 s . c om*/ * @param scheme * @param host * @param port * @param path * @param query * @param fragment * @return * @throws URISyntaxException */ public static URI createURI(String scheme, String host, int port, String path, String query, String fragment) throws URISyntaxException { logger.d("createURI HOST=%s", host); return URIUtils.createURI(scheme, host, port, path, query, fragment); }
From source file:com.eviware.soapui.impl.support.HttpUtils.java
public static java.net.URI createUri(String scheme, String userinfo, String host, int port, String escapedPath, String escapedQuery, String escapedFragment) throws URISyntaxException { return URIUtils.createURI(scheme, (userinfo == null ? "" : (userinfo + "@")) + host, port, escapedPath, escapedQuery, escapedFragment); }