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:org.craftercms.social.util.UGCHttpClient.java
public HttpResponse getModerationStatusTarget(String ticket, String moderationStatus, String target) throws URISyntaxException, ClientProtocolException, IOException { List<NameValuePair> qparams = new ArrayList<NameValuePair>(); qparams.add(new BasicNameValuePair("ticket", ticket)); qparams.add(new BasicNameValuePair("target", target)); URI uri = URIUtils.createURI(scheme, host, port, appPath + "/api/2/ugc/moderation/" + moderationStatus + "/target.json", URLEncodedUtils.format(qparams, HTTP.UTF_8), null); HttpGet httpget = new HttpGet(uri); HttpClient httpclient = new DefaultHttpClient(); return httpclient.execute(httpget); }
From source file:com.jzboy.couchdb.http.URITemplates.java
/** * URI used to see a design document// www . j av a2 s .c o m */ public static URI designDoc(String host, int port, String dbName, String designDocName) throws URISyntaxException { String path = String.format("%s/_design/%s", dbName, designDocName); return URIUtils.createURI("http", host, port, path, null, null); }
From source file:com.github.feribg.audiogetter.helpers.Utils.java
/** * Prepare Vimeo search URL//ww w .jav a 2 s.co m * @param query * @param page * @return * @throws URISyntaxException */ public static URI getVimeoSearchURI(String query, Integer page) throws URISyntaxException { List<NameValuePair> qparams = new ArrayList<NameValuePair>(); qparams.add(new BasicNameValuePair("query", query)); qparams.add(new BasicNameValuePair("page", String.valueOf(page))); qparams.add(new BasicNameValuePair("per_page", String.valueOf(Constants.Vimeo.PER_PAGE))); return URIUtils.createURI(Constants.Vimeo.API_SCHEME, Constants.Vimeo.API_HOST, -1, Constants.Vimeo.API_SEARCH, URLEncodedUtils.format(qparams, "UTF-8"), null); }
From source file:iristk.speech.nuancecloud.JSpeexNuanceCloudRecognizerListener.java
private void initRequest() { try {/*from w ww . ja v a 2s .c om*/ byteQueue.reset(); encodedQueue.reset(); JSpeexEnc encoder = new JSpeexEnc(16000); encoder.startEncoding(byteQueue, encodedQueue); List<NameValuePair> qparams = new ArrayList<NameValuePair>(); qparams.add(new BasicNameValuePair("appId", APP_ID)); qparams.add(new BasicNameValuePair("appKey", APP_KEY)); qparams.add(new BasicNameValuePair("id", DEVICE_ID)); URI uri = URIUtils.createURI("https", HOSTNAME, 443, SERVLET, URLEncodedUtils.format(qparams, "UTF-8"), null); final HttpPost httppost = new HttpPost(uri); httppost.addHeader("Content-Type", CODEC); httppost.addHeader("Content-Language", LANGUAGE); httppost.addHeader("Accept-Language", LANGUAGE); httppost.addHeader("Accept", RESULTS_FORMAT); httppost.addHeader("Accept-Topic", LM); if (nuanceAudioSource != null) { httppost.addHeader("X-Dictation-AudioSource", nuanceAudioSource.name()); } if (cookie != null) httppost.addHeader("Cookie", cookie); InputStreamEntity reqEntity = new InputStreamEntity(encodedQueue.getInputStream(), -1); reqEntity.setContentType(CODEC); httppost.setEntity(reqEntity); postThread = new PostThread(httppost); } catch (URISyntaxException e) { e.printStackTrace(); } }
From source file:org.craftercms.social.util.UGCHttpClient.java
public HttpResponse getThread(String ticket, String ugcId) throws Exception { List<NameValuePair> qparams = new ArrayList<NameValuePair>(); qparams.add(new BasicNameValuePair("ticket", ticket)); URI uri = URIUtils.createURI(scheme, host, port, appPath + "/api/2/ugc/thread/" + ugcId + ".json", URLEncodedUtils.format(qparams, HTTP.UTF_8), null); HttpGet httpget = new HttpGet(uri); HttpClient httpclient = new DefaultHttpClient(); return httpclient.execute(httpget); }
From source file:com.jzboy.couchdb.http.URITemplates.java
/** * URI used to get information about a design document *//*from ww w . j a v a 2 s. c om*/ public static URI designDocInfo(String host, int port, String dbName, String designDocName) throws URISyntaxException { String path = String.format("%s/_design/%s/_info", dbName, designDocName); return URIUtils.createURI("http", host, port, path, null, null); }
From source file:com.cloudapp.rest.CloudApi.java
/** * //from w ww . j av a 2 s .c o m * {@inheritDoc} * * @see com.cloudapp.rest.CloudApi#getItems() */ public JSONArray getItems(int page, int itemsPerPage, String type, boolean showDeleted) throws CloudApiException { HttpGet request = null; try { // Sanitize the parameters if (page < 1) { page = 1; } if (itemsPerPage < 1) { itemsPerPage = 1; } // Prepare the list of parameters. List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("page", "" + page)); nvps.add(new BasicNameValuePair("per_page", "" + itemsPerPage)); if (type != null) { nvps.add(new BasicNameValuePair("type", type)); } nvps.add(new BasicNameValuePair("deleted", (showDeleted) ? "true" : "false")); // Prepare the URI (the host and querystring.) URI uri = URIUtils.createURI("http", "my.cl.ly", -1, "/items", URLEncodedUtils.format(nvps, "UTF-8"), null); // Prepare the request. request = new HttpGet(uri); request.addHeader("Accept", "application/json"); // Perform the request. HttpResponse response = client.execute(request); response.addHeader("Accept", "application/json"); int status = response.getStatusLine().getStatusCode(); String body = EntityUtils.toString(response.getEntity(), "UTF-8"); // We always need 200 for items retrieval. if (status == 200) { return new JSONArray(body); } // Anything else is a failure. throw new CloudApiException(status, body, null); } catch (IOException e) { LOGGER.error("Error when trying to retrieve the items.", e); throw new CloudApiException(500, e.getMessage(), e); } catch (JSONException e) { LOGGER.error("Error when trying to parse the response as JSON.", e); throw new CloudApiException(500, e.getMessage(), e); } catch (URISyntaxException e) { LOGGER.error("Error when trying to retrieve the items.", e); throw new CloudApiException(500, e.getMessage(), e); } finally { if (request != null) { request.abort(); } } }
From source file:com.eviware.soapui.impl.wsdl.submit.filters.HttpRequestFilter.java
@SuppressWarnings("deprecation") @Override// ww w. j av a2s. c o m public void filterHttpRequest(SubmitContext context, HttpRequestInterface<?> request) { HttpRequestBase httpMethod = (HttpRequestBase) context.getProperty(BaseHttpRequestTransport.HTTP_METHOD); String path = PropertyExpander.expandProperties(context, request.getPath()); StringBuffer query = new StringBuffer(); String encoding = System.getProperty("soapui.request.encoding", StringUtils.unquote(request.getEncoding())); StringToStringMap responseProperties = (StringToStringMap) context .getProperty(BaseHttpRequestTransport.RESPONSE_PROPERTIES); MimeMultipart formMp = "multipart/form-data".equals(request.getMediaType()) && httpMethod instanceof HttpEntityEnclosingRequestBase ? new MimeMultipart() : null; RestParamsPropertyHolder params = request.getParams(); for (int c = 0; c < params.getPropertyCount(); c++) { RestParamProperty param = params.getPropertyAt(c); String value = PropertyExpander.expandProperties(context, param.getValue()); responseProperties.put(param.getName(), value); List<String> valueParts = sendEmptyParameters(request) || (!StringUtils.hasContent(value) && param.getRequired()) ? RestUtils.splitMultipleParametersEmptyIncluded(value, request.getMultiValueDelimiter()) : RestUtils.splitMultipleParameters(value, request.getMultiValueDelimiter()); // skip HEADER and TEMPLATE parameter encoding (TEMPLATE is encoded by // the URI handling further down) if (value != null && param.getStyle() != ParameterStyle.HEADER && param.getStyle() != ParameterStyle.TEMPLATE && !param.isDisableUrlEncoding()) { try { if (StringUtils.hasContent(encoding)) { value = URLEncoder.encode(value, encoding); for (int i = 0; i < valueParts.size(); i++) valueParts.set(i, URLEncoder.encode(valueParts.get(i), encoding)); } else { value = URLEncoder.encode(value); for (int i = 0; i < valueParts.size(); i++) valueParts.set(i, URLEncoder.encode(valueParts.get(i))); } } catch (UnsupportedEncodingException e1) { SoapUI.logError(e1); value = URLEncoder.encode(value); for (int i = 0; i < valueParts.size(); i++) valueParts.set(i, URLEncoder.encode(valueParts.get(i))); } // URLEncoder replaces space with "+", but we want "%20". value = value.replaceAll("\\+", "%20"); for (int i = 0; i < valueParts.size(); i++) valueParts.set(i, valueParts.get(i).replaceAll("\\+", "%20")); } if (param.getStyle() == ParameterStyle.QUERY && !sendEmptyParameters(request)) { if (!StringUtils.hasContent(value) && !param.getRequired()) continue; } switch (param.getStyle()) { case HEADER: for (String valuePart : valueParts) httpMethod.addHeader(param.getName(), valuePart); break; case QUERY: if (formMp == null || !request.isPostQueryString()) { for (String valuePart : valueParts) { if (query.length() > 0) query.append('&'); query.append(URLEncoder.encode(param.getName())); query.append('='); if (StringUtils.hasContent(valuePart)) query.append(valuePart); } } else { try { addFormMultipart(request, formMp, param.getName(), responseProperties.get(param.getName())); } catch (MessagingException e) { SoapUI.logError(e); } } break; case TEMPLATE: try { value = getEncodedValue(value, encoding, param.isDisableUrlEncoding(), request.getSettings().getBoolean(HttpSettings.ENCODED_URLS)); path = path.replaceAll("\\{" + param.getName() + "\\}", value == null ? "" : value); } catch (UnsupportedEncodingException e) { SoapUI.logError(e); } break; case MATRIX: try { value = getEncodedValue(value, encoding, param.isDisableUrlEncoding(), request.getSettings().getBoolean(HttpSettings.ENCODED_URLS)); } catch (UnsupportedEncodingException e) { SoapUI.logError(e); } if (param.getType().equals(XmlBoolean.type.getName())) { if (value.toUpperCase().equals("TRUE") || value.equals("1")) { path += ";" + param.getName(); } } else { path += ";" + param.getName(); if (StringUtils.hasContent(value)) { path += "=" + value; } } case PLAIN: break; } } if (request.getSettings().getBoolean(HttpSettings.FORWARD_SLASHES)) path = PathUtils.fixForwardSlashesInPath(path); if (PathUtils.isHttpPath(path)) { try { // URI(String) automatically URLencodes the input, so we need to // decode it first... URI uri = new URI(path, request.getSettings().getBoolean(HttpSettings.ENCODED_URLS)); context.setProperty(BaseHttpRequestTransport.REQUEST_URI, uri); java.net.URI oldUri = httpMethod.getURI(); httpMethod.setURI(new java.net.URI(oldUri.getScheme(), oldUri.getUserInfo(), oldUri.getHost(), oldUri.getPort(), (uri.getPath()) == null ? "/" : uri.getPath(), oldUri.getQuery(), oldUri.getFragment())); } catch (Exception e) { SoapUI.logError(e); } } else if (StringUtils.hasContent(path)) { try { java.net.URI oldUri = httpMethod.getURI(); String pathToSet = StringUtils.hasContent(oldUri.getRawPath()) && !"/".equals(oldUri.getRawPath()) ? oldUri.getRawPath() + path : path; java.net.URI newUri = URIUtils.createURI(oldUri.getScheme(), oldUri.getHost(), oldUri.getPort(), pathToSet, oldUri.getQuery(), oldUri.getFragment()); httpMethod.setURI(newUri); context.setProperty(BaseHttpRequestTransport.REQUEST_URI, new URI(newUri.toString(), request.getSettings().getBoolean(HttpSettings.ENCODED_URLS))); } catch (Exception e) { SoapUI.logError(e); } } if (query.length() > 0 && !request.isPostQueryString()) { try { java.net.URI oldUri = httpMethod.getURI(); httpMethod.setURI(URIUtils.createURI(oldUri.getScheme(), oldUri.getHost(), oldUri.getPort(), oldUri.getRawPath(), query.toString(), oldUri.getFragment())); } catch (Exception e) { SoapUI.logError(e); } } if (request instanceof RestRequest) { String acceptEncoding = ((RestRequest) request).getAccept(); if (StringUtils.hasContent(acceptEncoding)) { httpMethod.setHeader("Accept", acceptEncoding); } } if (formMp != null) { // create request message try { if (request.hasRequestBody() && httpMethod instanceof HttpEntityEnclosingRequest) { String requestContent = PropertyExpander.expandProperties(context, request.getRequestContent(), request.isEntitizeProperties()); if (StringUtils.hasContent(requestContent)) { initRootPart(request, requestContent, formMp); } } for (Attachment attachment : request.getAttachments()) { MimeBodyPart part = new PreencodedMimeBodyPart("binary"); if (attachment instanceof FileAttachment<?>) { String name = attachment.getName(); if (StringUtils.hasContent(attachment.getContentID()) && !name.equals(attachment.getContentID())) name = attachment.getContentID(); part.setDisposition( "form-data; name=\"" + name + "\"; filename=\"" + attachment.getName() + "\""); } else part.setDisposition("form-data; name=\"" + attachment.getName() + "\""); part.setDataHandler(new DataHandler(new AttachmentDataSource(attachment))); formMp.addBodyPart(part); } MimeMessage message = new MimeMessage(AttachmentUtils.JAVAMAIL_SESSION); message.setContent(formMp); message.saveChanges(); RestRequestMimeMessageRequestEntity mimeMessageRequestEntity = new RestRequestMimeMessageRequestEntity( message, request); ((HttpEntityEnclosingRequest) httpMethod).setEntity(mimeMessageRequestEntity); httpMethod.setHeader("Content-Type", mimeMessageRequestEntity.getContentType().getValue()); httpMethod.setHeader("MIME-Version", "1.0"); } catch (Throwable e) { SoapUI.logError(e); } } else if (request.hasRequestBody() && httpMethod instanceof HttpEntityEnclosingRequest) { if (StringUtils.hasContent(request.getMediaType())) httpMethod.setHeader("Content-Type", getContentTypeHeader(request.getMediaType(), encoding)); if (request.isPostQueryString()) { try { ((HttpEntityEnclosingRequest) httpMethod).setEntity(new StringEntity(query.toString())); } catch (UnsupportedEncodingException e) { SoapUI.logError(e); } } else { String requestContent = PropertyExpander.expandProperties(context, request.getRequestContent(), request.isEntitizeProperties()); List<Attachment> attachments = new ArrayList<Attachment>(); for (Attachment attachment : request.getAttachments()) { if (attachment.getContentType().equals(request.getMediaType())) { attachments.add(attachment); } } if (StringUtils.hasContent(requestContent) && attachments.isEmpty()) { try { byte[] content = encoding == null ? requestContent.getBytes() : requestContent.getBytes(encoding); ((HttpEntityEnclosingRequest) httpMethod).setEntity(new ByteArrayEntity(content)); } catch (UnsupportedEncodingException e) { ((HttpEntityEnclosingRequest) httpMethod) .setEntity(new ByteArrayEntity(requestContent.getBytes())); } } else if (attachments.size() > 0) { try { MimeMultipart mp = null; if (StringUtils.hasContent(requestContent)) { mp = new MimeMultipart(); initRootPart(request, requestContent, mp); } else if (attachments.size() == 1) { ((HttpEntityEnclosingRequest) httpMethod) .setEntity(new InputStreamEntity(attachments.get(0).getInputStream(), -1)); httpMethod.setHeader("Content-Type", getContentTypeHeader(request.getMediaType(), encoding)); } if (((HttpEntityEnclosingRequest) httpMethod).getEntity() == null) { if (mp == null) mp = new MimeMultipart(); // init mimeparts AttachmentUtils.addMimeParts(request, attachments, mp, new StringToStringMap()); // create request message MimeMessage message = new MimeMessage(AttachmentUtils.JAVAMAIL_SESSION); message.setContent(mp); message.saveChanges(); RestRequestMimeMessageRequestEntity mimeMessageRequestEntity = new RestRequestMimeMessageRequestEntity( message, request); ((HttpEntityEnclosingRequest) httpMethod).setEntity(mimeMessageRequestEntity); httpMethod.setHeader("Content-Type", getContentTypeHeader( mimeMessageRequestEntity.getContentType().getValue(), encoding)); httpMethod.setHeader("MIME-Version", "1.0"); } } catch (Exception e) { SoapUI.logError(e); } } } } }
From source file:org.mahasen.client.Search.java
/** * @param propertyName/* w w w. j a v a 2 s. c o m*/ * @param isRangeBase * @param value1 * @param value2 * @return * @throws IOException * @throws URISyntaxException * @throws AuthenticationExceptionException * * @throws MahasenClientException */ private HttpResponse sendRequest(String propertyName, boolean isRangeBase, String value1, String value2) throws IOException, URISyntaxException, AuthenticationExceptionException, MahasenClientException { httpclient = new DefaultHttpClient(); HttpResponse response = null; String userName = clientLoginData.getUserName(); String passWord = clientLoginData.getPassWord(); String hostAndPort = clientLoginData.getHostNameAndPort(); String userId = clientLoginData.getUserId(userName, passWord); Boolean isLogged = clientLoginData.isLoggedIn(); System.out.println(" Is Logged : " + isLogged); if (isLogged == true) { httpclient = WebClientSSLWrapper.wrapClient(httpclient); ArrayList<NameValuePair> qparams = new ArrayList<NameValuePair>(); qparams.add(new BasicNameValuePair("propertyName", propertyName)); qparams.add(new BasicNameValuePair("isRangeBase", String.valueOf(isRangeBase))); if (isRangeBase == true) { qparams.add(new BasicNameValuePair("initialValue", value1)); qparams.add(new BasicNameValuePair("lastValue", value2)); } else { qparams.add(new BasicNameValuePair("propertyValue", value1)); } URI uri = URIUtils.createURI("https", hostAndPort, -1, "/mahasen/search_ajaxprocessor.jsp", URLEncodedUtils.format(qparams, "UTF-8"), null); HttpPost httppost = new HttpPost(uri); System.out.println("executing request " + httppost.getRequestLine()); response = httpclient.execute(httppost); } else { System.out.println("User has to be logged in to perform this function"); } return response; }
From source file:com.jzboy.couchdb.http.URITemplates.java
/** * URI used to query a view/* ww w. ja v a2s . c om*/ */ public static URI queryView(String host, int port, String dbName, String designDocName, String viewName, String query) throws URISyntaxException { String path = String.format("%s/_design/%s/_view/%s", dbName, designDocName, viewName); return URIUtils.createURI("http", host, port, path, query, null); }