List of usage examples for org.apache.http.client.utils URLEncodedUtils parse
public static List<NameValuePair> parse(final String s, final Charset charset)
From source file:org.n52.sos.web.JdbcUrl.java
protected final void parse(String string) throws URISyntaxException { URI uri = new URI(string); scheme = uri.getScheme();//from w w w .jav a2 s. co m uri = new URI(uri.getSchemeSpecificPart()); type = uri.getScheme(); host = uri.getHost(); port = uri.getPort(); String[] path = uri.getPath().split(SLASH_STRING); if (path.length == 1 && !path[0].isEmpty()) { database = path[0]; } else if (path.length == 2 && path[0].isEmpty() && !path[1].isEmpty()) { database = path[1]; } for (NameValuePair nvp : URLEncodedUtils.parse(uri, "UTF-8")) { if (nvp.getName().equals(QUERY_PARAMETER_USER)) { user = nvp.getValue(); } else if (nvp.getName().equals(QUERY_PARAMETER_PASSWORD)) { password = nvp.getValue(); } } }
From source file:org.github.oauth2.OAuth2BrowserDialog.java
protected Control createDialogArea(Composite parent) { Composite control = (Composite) super.createDialogArea(parent); Composite displayArea = new Composite(control, SWT.NONE); GridLayoutFactory.fillDefaults().applyTo(displayArea); GridDataFactory.fillDefaults().hint(600, 400).grab(true, true).applyTo(displayArea); Browser browser = new Browser(displayArea, SWT.NONE); GridDataFactory.fillDefaults().grab(true, true).applyTo(browser); browser.setUrl(url);/* ww w . ja v a2 s . c o m*/ browser.addLocationListener(new LocationAdapter() { public void changing(LocationEvent event) { if (!event.location.startsWith(redirectUri)) return; URI uri; try { uri = new URI(event.location); } catch (URISyntaxException ignored) { return; } List<NameValuePair> params = URLEncodedUtils.parse(uri, null); for (NameValuePair param : params) if (paramName.equals(param.getName())) { code = param.getValue(); break; } event.doit = false; close(); } }); getShell().setText(Messages.OAuth2BrowserDialog_Title); return control; }
From source file:io.wcm.caravan.io.http.impl.servletclient.HttpServletRequestMapper.java
@Override public Map<String, String[]> getParameterMap() { try {/*from w w w . java 2 s .c o m*/ List<NameValuePair> pairs = URLEncodedUtils.parse(new URI(request.getUrl()), Charsets.UTF_8.toString()); Map<String, Collection<String>> multiMap = Observable.from(pairs) .toMultimap(NameValuePair::getName, NameValuePair::getValue).toBlocking().single(); Builder<String, String[]> builder = ImmutableMap.builder(); multiMap.entrySet().stream().forEach(entry -> { String[] arrayValue = entry.getValue().toArray(new String[entry.getValue().size()]); builder.put(entry.getKey(), arrayValue); }); return builder.build(); } catch (URISyntaxException ex) { ex.printStackTrace(); } return null; }
From source file:com.thoughtworks.go.server.websocket.ConsoleLogSocket.java
private long parseStartLine(UpgradeRequest request) { Optional<NameValuePair> startLine = URLEncodedUtils.parse(request.getRequestURI(), "UTF-8").stream() .filter(pair -> "startLine".equals(pair.getName())).findFirst(); return startLine.isPresent() ? Long.valueOf(startLine.get().getValue()) : 0L; }
From source file:org.openlmis.fulfillment.service.referencedata.UserReferenceDataServiceParameterizedTest.java
private void executeHasRightEndpoint(UUID user, UUID right, UUID program, UUID facility, UUID warehouse, boolean expectedValue) { // given/*from w ww. j a v a 2s .c om*/ UserReferenceDataService service = (UserReferenceDataService) prepareService(); ResponseEntity<ResultDto> response = mock(ResponseEntity.class); // when when(restTemplate.getForEntity(any(URI.class), eq(ResultDto.class))).thenReturn(response); when(response.getBody()).thenReturn(new ResultDto<>(expectedValue)); ResultDto result = service.hasRight(user, right, program, facility, warehouse); // then assertThat(result.getResult(), is(expectedValue)); verify(restTemplate, atLeastOnce()).getForEntity(uriCaptor.capture(), eq(ResultDto.class)); URI uri = uriCaptor.getValue(); List<NameValuePair> parse = URLEncodedUtils.parse(uri, "UTF-8"); assertThat(parse, hasItem(allOf(hasProperty(URI_QUERY_NAME, is("rightId")), hasProperty(URI_QUERY_VALUE, is(right.toString()))))); if (null != program) { assertThat(parse, hasItem(allOf(hasProperty(URI_QUERY_NAME, is("programId")), hasProperty(URI_QUERY_VALUE, is(program.toString()))))); } else { assertThat(parse, not(hasItem(hasProperty(URI_QUERY_NAME, is("programId"))))); } if (null != facility) { assertThat(parse, hasItem(allOf(hasProperty(URI_QUERY_NAME, is("facilityId")), hasProperty(URI_QUERY_VALUE, is(facility.toString()))))); } else { assertThat(parse, not(hasItem(hasProperty(URI_QUERY_NAME, is("facilityId"))))); } if (null != warehouse) { assertThat(parse, hasItem(allOf(hasProperty(URI_QUERY_NAME, is("warehouseId")), hasProperty(URI_QUERY_VALUE, is(warehouse.toString()))))); } else { assertThat(parse, not(hasItem(hasProperty(URI_QUERY_NAME, is("warehouseId"))))); } }
From source file:org.apache.hadoop.security.authentication.server.PseudoAuthenticationHandler.java
private String getUserName(HttpServletRequest request) { String queryString = request.getQueryString(); if (queryString == null || queryString.length() == 0) { return null; }//w w w . j a va2s . com List<NameValuePair> list = URLEncodedUtils.parse(queryString, UTF8_CHARSET); if (list != null) { for (NameValuePair nv : list) { if (PseudoAuthenticator.USER_NAME.equals(nv.getName())) { return nv.getValue(); } } } return null; }
From source file:org.xwiki.wysiwyg.internal.plugin.alfresco.server.TicketAuthenticator.java
@Override public void authenticate(HttpRequestBase request) { String ticket = null;//from w w w . ja v a 2s .co m //get ticket from DB AlfrescoTiket dbTiket = ticketManager.getTicket(); //if there is a ticket for current user,use it if (dbTiket != null) { ticket = dbTiket.getTiket(); } /*if (ticket != null) { if (!ticketManager.validateAuthenticationTicket(ticket)) { //if ticket is not valid on alfresco, perform authentication ticket = getAuthenticationTicket(); } } else { //if there is no ticket in DB, perform authentication ticket = getAuthenticationTicket(); }*/ // Add the ticket to the query string. URI uri = request.getURI(); List<NameValuePair> parameters = URLEncodedUtils.parse(uri, QUERY_STRING_ENCODING); parameters.add(new BasicNameValuePair(AUTH_TICKET_PARAM, ticket)); String query = URLEncodedUtils.format(parameters, QUERY_STRING_ENCODING); try { request.setURI(URIUtils.createURI(uri.getScheme(), uri.getHost(), uri.getPort(), uri.getRawPath(), query, uri.getRawFragment())); } catch (URISyntaxException e) { // This shouldn't happen. } }
From source file:com.scvngr.levelup.core.net.AbstractRequest.java
/** * @param url the URL whose query parameters will be extracted. * @return a map of the query parameters or null if there is an error parsing the URL. *///ww w .ja va2 s .com @Nullable private static Map<String, String> extractQueryParameters(final Uri url) { Map<String, String> params = null; try { final List<NameValuePair> paramsList = URLEncodedUtils.parse(new URI(url.toString()), "utf-8"); params = new HashMap<String, String>(paramsList.size()); for (final NameValuePair nvp : paramsList) { params.put(nvp.getName(), nvp.getValue()); } } catch (final URISyntaxException e) { // failsafe LogManager.e(NullUtils.format("could not parse uri: '%s'. " + "dropping query parameters.", url), e); } return params; }