List of usage examples for org.apache.http.client.utils URIBuilder addParameter
public URIBuilder addParameter(final String param, final String value)
From source file:net.shibboleth.idp.oidc.flow.BuildAuthorizationRequestContextAction.java
/** * Check for none prompt pair./* ww w . j a v a 2 s . com*/ * * @param client the client * @param authRequest the auth request * @return the pair */ private Pair<Events, ? extends Object> checkForNonePrompt(final ClientDetailsEntity client, final OIDCAuthorizationRequestContext authRequest) { log.debug("Prompt contains {}", ConnectRequestParameters.PROMPT_NONE); final Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (auth != null) { log.debug("Authentication context is found for {}. Already logged in; continue without prompt", auth.getPrincipal()); return new Pair(Events.Success, auth); } log.info("Client requested no prompt"); if (client != null && authRequest.getRedirectUri() != null) { try { final String url = redirectResolver.resolveRedirect(authRequest.getRedirectUri(), client); log.debug("Initial redirect url resolved for client {} is {}", client.getClientName(), url); final URIBuilder uriBuilder = new URIBuilder(url); if (authRequest.isImplicitResponseType()) { log.debug("Request is asking for implicit grant type. Encoding parameters as fragments"); final StringBuilder builder = new StringBuilder(); builder.append(ConnectRequestParameters.ERROR).append('=') .append(ConnectRequestParameters.LOGIN_REQUIRED); if (!Strings.isNullOrEmpty(authRequest.getState())) { builder.append('&').append(ConnectRequestParameters.STATE).append('=') .append(authRequest.getState()); } uriBuilder.setFragment(builder.toString()); } else { log.debug("Request is asking for code grant type. Encoding parameters as url parameters"); uriBuilder.addParameter(ConnectRequestParameters.ERROR, ConnectRequestParameters.LOGIN_REQUIRED); if (!Strings.isNullOrEmpty(authRequest.getState())) { uriBuilder.addParameter(ConnectRequestParameters.STATE, authRequest.getState()); } } log.debug("Resolved redirect url {}", uriBuilder.toString()); return new Pair<>(Events.Redirect, uriBuilder.toString()); } catch (final URISyntaxException e) { log.error("Can't build redirect URI for prompt=none, sending error instead", e); } } else { log.warn("Access denied. Either client is not found or no redirect uri is specified"); } return new Pair(Events.Failure, null); }
From source file:org.openrdf.http.client.SesameSession.java
public void getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred, RDFHandler handler, Resource... contexts) throws IOException, RDFHandlerException, RepositoryException, UnauthorizedException, QueryInterruptedException { checkRepositoryURL();// ww w.j a va 2 s . c o m try { final boolean useTransaction = transactionURL != null; String baseLocation = useTransaction ? transactionURL : Protocol.getStatementsLocation(getQueryURL()); URIBuilder url = new URIBuilder(baseLocation); if (subj != null) { url.setParameter(Protocol.SUBJECT_PARAM_NAME, Protocol.encodeValue(subj)); } if (pred != null) { url.setParameter(Protocol.PREDICATE_PARAM_NAME, Protocol.encodeValue(pred)); } if (obj != null) { url.setParameter(Protocol.OBJECT_PARAM_NAME, Protocol.encodeValue(obj)); } for (String encodedContext : Protocol.encodeContexts(contexts)) { url.addParameter(Protocol.CONTEXT_PARAM_NAME, encodedContext); } url.setParameter(Protocol.INCLUDE_INFERRED_PARAM_NAME, Boolean.toString(includeInferred)); if (useTransaction) { url.setParameter(Protocol.ACTION_PARAM_NAME, Action.GET.toString()); } HttpUriRequest method = useTransaction ? new HttpPost(url.build()) : new HttpGet(url.build()); try { getRDF(method, handler, true); } catch (MalformedQueryException e) { logger.warn("Server reported unexpected malfored query error", e); throw new RepositoryException(e.getMessage(), e); } } catch (URISyntaxException e) { throw new AssertionError(e); } }
From source file:org.alfresco.po.share.site.document.DocumentLibraryPage.java
/** * The method helps to navigate to a folder or a file from document library. * @param title String/*from w w w.ja v a 2 s .co m*/ * @return HtmlPage */ public HtmlPage browseToEntry(String title) throws Exception { DocumentLibraryPage documentLibraryPage = getCurrentPage().render(); FileDirectoryInfo fileInfo = documentLibraryPage.getFileDirectoryInfo(title); if (fileInfo.isFolder()) { String url = selectEntry(title).getAttribute("href"); String param = selectEntry(title).getAttribute("rel"); param = param.substring(1, param.length()); URIBuilder b = new URIBuilder(url); b.addParameter("filter", param); url = b.build().toString(); driver.navigate().to(url); } else { String url = selectEntry(title).getAttribute("href"); driver.navigate().to(url); } return getCurrentPage(); }
From source file:org.wso2.carbon.identity.application.authentication.framework.handler.request.impl.JITProvisioningPostAuthenticationHandler.java
/** * To add the missing claims.//w w w.j a va 2 s. c om * * @param uriBuilder Relevant URI builder. * @param context Authentication context. */ private void addMissingClaims(URIBuilder uriBuilder, AuthenticationContext context) { String[] missingClaims = FrameworkUtils.getMissingClaims(context); if (StringUtils.isNotEmpty(missingClaims[1])) { if (log.isDebugEnabled()) { String username = context.getSequenceConfig().getAuthenticatedUser() .getAuthenticatedSubjectIdentifier(); String idPName = context.getExternalIdP().getIdPName(); log.debug("Mandatory claims for SP, " + missingClaims[1] + " is missing for the user : " + username + " from the IDP " + idPName); } uriBuilder.addParameter(FrameworkConstants.MISSING_CLAIMS, missingClaims[1]); uriBuilder.addParameter(FrameworkConstants.MISSING_CLAIMS_DISPLAY_NAME, missingClaims[0]); } }
From source file:org.eclipse.rdf4j.http.client.RDF4JProtocolSession.java
public void getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred, RDFHandler handler, Resource... contexts) throws IOException, RDFHandlerException, RepositoryException, UnauthorizedException, QueryInterruptedException { checkRepositoryURL();/* w w w .ja va 2 s .c o m*/ try { final boolean useTransaction = transactionURL != null; String baseLocation = useTransaction ? transactionURL : Protocol.getStatementsLocation(getQueryURL()); URIBuilder url = new URIBuilder(baseLocation); if (subj != null) { url.setParameter(Protocol.SUBJECT_PARAM_NAME, Protocol.encodeValue(subj)); } if (pred != null) { url.setParameter(Protocol.PREDICATE_PARAM_NAME, Protocol.encodeValue(pred)); } if (obj != null) { url.setParameter(Protocol.OBJECT_PARAM_NAME, Protocol.encodeValue(obj)); } for (String encodedContext : Protocol.encodeContexts(contexts)) { url.addParameter(Protocol.CONTEXT_PARAM_NAME, encodedContext); } url.setParameter(Protocol.INCLUDE_INFERRED_PARAM_NAME, Boolean.toString(includeInferred)); if (useTransaction) { url.setParameter(Protocol.ACTION_PARAM_NAME, Action.GET.toString()); } HttpRequestBase method = useTransaction ? new HttpPut(url.build()) : new HttpGet(url.build()); try { getRDF(method, handler, true); } catch (MalformedQueryException e) { logger.warn("Server reported unexpected malfored query error", e); throw new RepositoryException(e.getMessage(), e); } finally { method.reset(); } } catch (URISyntaxException e) { throw new AssertionError(e); } }
From source file:com.redhat.refarch.microservices.trigger.service.TriggerService.java
public JSONObject doPurchase() throws Exception { HttpClient client = new DefaultHttpClient(); //get a customer JSONObject jsonObject = new JSONObject(); jsonObject.put("username", "bobdole"); jsonObject.put("password", "password"); URIBuilder uriBuilder = getUriBuilder("customers", "authenticate"); HttpPost post = new HttpPost(uriBuilder.build()); post.setEntity(new StringEntity(jsonObject.toString(), ContentType.APPLICATION_JSON)); logInfo("Executing " + post); HttpResponse response = client.execute(post); String responseString = EntityUtils.toString(response.getEntity()); logInfo("Got login response " + responseString); JSONObject jsonResponse = new JSONObject(responseString); Customer customer = new Customer(); customer.setId(jsonResponse.getLong("id")); customer.setAddress(jsonResponse.getString("address")); customer.setName(jsonResponse.getString("name")); //initialize an order jsonObject = new JSONObject().put("status", "Initial"); uriBuilder = getUriBuilder("customers", customer.getId(), "orders"); post = new HttpPost(uriBuilder.build()); post.setEntity(new StringEntity(jsonObject.toString(), ContentType.APPLICATION_JSON)); logInfo("Executing " + post); response = client.execute(post);/*from w w w . ja v a 2 s . c o m*/ responseString = EntityUtils.toString(response.getEntity()); logInfo("Got response " + responseString); jsonResponse = new JSONObject(responseString); Long orderId = jsonResponse.getLong("id"); // get an item uriBuilder = getUriBuilder("products"); uriBuilder.addParameter("featured", ""); HttpGet get = new HttpGet(uriBuilder.build()); logInfo("Executing " + get); response = client.execute(get); responseString = EntityUtils.toString(response.getEntity()); logInfo("Got response " + responseString); JSONArray jsonArray = new JSONArray(responseString); List<Map<String, Object>> products = Utils.getList(jsonArray); logInfo("array info " + Arrays.toString(products.toArray())); Map<String, Object> item = products.get(0); // put item on order jsonObject = new JSONObject().put("sku", item.get("sku")).put("quantity", 1); uriBuilder = getUriBuilder("customers", customer.getId(), "orders", orderId, "orderItems"); post = new HttpPost(uriBuilder.build()); post.setEntity(new StringEntity(jsonObject.toString(), ContentType.APPLICATION_JSON)); logInfo("Executing " + post); response = client.execute(post); responseString = EntityUtils.toString(response.getEntity()); logInfo("Got response " + responseString); // billing/process jsonObject = new JSONObject().put("amount", item.get("price")).put("creditCardNumber", 1234567890123456L) .put("expMonth", 1).put("expYear", 2019).put("verificationCode", 123) .put("billingAddress", customer.getAddress()).put("customerName", customer.getName()) .put("customerId", customer.getId()).put("orderNumber", orderId); logInfo(jsonObject.toString()); uriBuilder = getUriBuilder("billing", "process"); post = new HttpPost(uriBuilder.build()); post.setEntity(new StringEntity(jsonObject.toString(), ContentType.APPLICATION_JSON)); logInfo("Executing " + post); response = new DefaultHttpClient().execute(post); responseString = EntityUtils.toString(response.getEntity()); logInfo("Transaction processed as: " + responseString); return new JSONObject(responseString); }