List of usage examples for org.apache.http.client.methods HttpUriRequest getURI
URI getURI();
From source file:org.dasein.cloud.azurepack.tests.compute.AzurePackVirtualMachineSupportTest.java
@Test public void lauchVhdVMShouldSendCorrectRequest() throws CloudException, InternalException { final AtomicInteger postCount = new AtomicInteger(0); new StartOrStopVirtualMachinesRequestExecutorMockUp("Start") { @Mock/*from ww w .jav a 2 s .co m*/ public void $init(CloudProvider provider, HttpClientBuilder clientBuilder, HttpUriRequest request, ResponseHandler handler) { String requestUri = request.getURI().toString(); if (request.getMethod().equals("POST") && requestUri.equals(String.format(LIST_VM_RESOURCES, ENDPOINT, ACCOUNT_NO))) { requestResourceType = 21; WAPVirtualMachineModel wapVirtualMachineModel = new WAPVirtualMachineModel(); wapVirtualMachineModel.setName(VM_1_NAME); wapVirtualMachineModel.setCloudId(REGION); wapVirtualMachineModel.setStampId(DATACENTER_ID); wapVirtualMachineModel.setVirtualHardDiskId(VHD_1_ID); wapVirtualMachineModel.setHardwareProfileId(HWP_1_ID); List<WAPNewAdapterModel> adapters = new ArrayList<>(); WAPNewAdapterModel newAdapterModel = new WAPNewAdapterModel(); newAdapterModel.setVmNetworkName(VM_1_NETWORK_NAME); adapters.add(newAdapterModel); wapVirtualMachineModel.setNewVirtualNetworkAdapterInput(adapters); assertPost(request, String.format(LIST_VM_RESOURCES, ENDPOINT, ACCOUNT_NO), new Header[0], wapVirtualMachineModel); } else { super.$init(provider, clientBuilder, request, handler); } responseHandler = handler; } @Mock public Object execute() { if (requestResourceType == 21) { postCount.incrementAndGet(); return mapFromModel(this.responseHandler, createWAPVirtualMachineModel()); } else { return super.execute(); } } }; VMLaunchOptions vmLaunchOptions = VMLaunchOptions.getInstance(HWP_1_ID, VHD_1_ID, VM_1_NAME, VM_1_DESCRIPTION); vmLaunchOptions.inVlan(null, DATACENTER_ID, VM_1_NETWORK_ID); VirtualMachine virtualMachine = azurePackVirtualMachineSupport.launch(vmLaunchOptions); assertEquals("terminate doesn't send DELETE request", 1, postCount.get()); assertVirtualMachine(virtualMachine); }
From source file:org.eclipse.aether.transport.http.HttpTransporter.java
private void prepare(HttpUriRequest request, SharingHttpContext context) { boolean put = HttpPut.METHOD_NAME.equalsIgnoreCase(request.getMethod()); if (state.getWebDav() == null && (put || isPayloadPresent(request))) { try {/*from w ww. ja v a 2s . c o m*/ HttpOptions req = commonHeaders(new HttpOptions(request.getURI())); HttpResponse response = client.execute(server, req, context); state.setWebDav(isWebDav(response)); EntityUtils.consumeQuietly(response.getEntity()); } catch (IOException e) { LOGGER.debug("Failed to prepare HTTP context", e); } } if (put && Boolean.TRUE.equals(state.getWebDav())) { mkdirs(request.getURI(), context); } }
From source file:org.dasein.cloud.azurepack.tests.compute.AzurePackVirtualMachineSupportTest.java
@Test public void lauchTemplateVMShouldSendCorrectRequest() throws CloudException, InternalException { final AtomicInteger postCount = new AtomicInteger(0); new StartOrStopVirtualMachinesRequestExecutorMockUp("Start") { @Mock/*ww w . j a v a 2s . com*/ public void $init(CloudProvider provider, HttpClientBuilder clientBuilder, HttpUriRequest request, ResponseHandler handler) { String requestUri = request.getURI().toString(); if (request.getMethod().equals("POST") && requestUri.equals(String.format(LIST_VM_RESOURCES, ENDPOINT, ACCOUNT_NO))) { requestResourceType = 21; WAPVirtualMachineModel wapVirtualMachineModel = new WAPVirtualMachineModel(); wapVirtualMachineModel.setName(VM_1_NAME); wapVirtualMachineModel.setCloudId(REGION); wapVirtualMachineModel.setStampId(DATACENTER_ID); wapVirtualMachineModel.setVmTemplateId(TPL_1_ID); wapVirtualMachineModel.setProductKey(VM_1_WINDOWS_SERIAL_NUMBER); wapVirtualMachineModel.setLocalAdminUserName(VM_1_BOOTSTRAP_USER); wapVirtualMachineModel.setLocalAdminPassword(VM_1_BOOTSTRAP_PASSWORD); List<WAPNewAdapterModel> adapters = new ArrayList<>(); WAPNewAdapterModel newAdapterModel = new WAPNewAdapterModel(); newAdapterModel.setVmNetworkName(VM_1_NETWORK_NAME); adapters.add(newAdapterModel); wapVirtualMachineModel.setNewVirtualNetworkAdapterInput(adapters); assertPost(request, String.format(LIST_VM_RESOURCES, ENDPOINT, ACCOUNT_NO), new Header[0], wapVirtualMachineModel); } else { super.$init(provider, clientBuilder, request, handler); } responseHandler = handler; } @Mock public Object execute() { if (requestResourceType == 21) { postCount.incrementAndGet(); return mapFromModel(this.responseHandler, createWAPVirtualMachineModel()); } else { return super.execute(); } } }; VMLaunchOptions vmLaunchOptions = VMLaunchOptions.getInstance(HWP_1_ID, TPL_1_ID, VM_1_NAME, VM_1_DESCRIPTION); vmLaunchOptions.inVlan(null, DATACENTER_ID, VM_1_NETWORK_ID); vmLaunchOptions.withWinProductSerialNum(VM_1_WINDOWS_SERIAL_NUMBER); vmLaunchOptions.withBootstrapUser("dummy-user-name-to-be-replaced", VM_1_BOOTSTRAP_PASSWORD); VirtualMachine virtualMachine = azurePackVirtualMachineSupport.launch(vmLaunchOptions); assertEquals("terminate doesn't send DELETE request", 1, postCount.get()); assertVirtualMachine(virtualMachine); }
From source file:com.github.pascalgn.jiracli.web.HttpClient.java
private <T> T execute(final HttpUriRequest request, final Function<Reader, T> function) { return execute(request, true, new Function<HttpEntity, T>() { @Override/*from w w w .ja v a2s. co m*/ public T apply(HttpEntity entity, Set<Hint> hints) { return (entity == null ? null : readResponse(request.getURI(), entity, function)); } }); }
From source file:org.metaeffekt.dcc.controller.execution.RemoteExecutor.java
public void execute(final Commands command, final ConfigurationUnit unit) { // verify initialize (static host-level precondition) was executed // Id<HostName> host = Id.createHostName(unitBasedEndpointUriBuilder.getHost()); // if (!getExecutionStateHandler().alreadySuccessfullyExecuted( // host, Commands.INITIALIZE, host, getExecutionContext().getProfile().getDeploymentId())) { // throw new IllegalStateException( // String.format("Unit based command [%s] requires that the commands [%s] is executed first.", // command, Commands.INITIALIZE)); // }/*from w w w .j a va 2 s .c o m*/ logCommand(command, unit); final Id<DeploymentId> deploymentId = getExecutionContext().getProfile().getDeploymentId(); Id<PackageId> packageId = getExecutionContext().getPackageId(unit, command); Id<UnitId> unitId = unit.getId(); HttpUriRequest request = unitBasedEndpointUriBuilder.buildHttpUriRequest(command, deploymentId, unitId, packageId, loadProperties(unitId, command)); LOG.debug(" Invoking: [{}]", request.getURI()); executeRequest(request, new Callback() { @Override public void process(HttpResponse response) { int statusCode = response.getStatusLine().getStatusCode(); if (200 == statusCode) { LOG.debug("Command [{}] for unit [{}] successfully executed against host [{}:{}].", command, unit.getId(), unitBasedEndpointUriBuilder.getHost(), unitBasedEndpointUriBuilder.getPort()); } else { throw new RuntimeException(String.format( "Unexpected response while executing [%s] for unit [%s] against the host [%s:%s]" + " - status code was [%s]. Remote exception message: [{%s}]", command.toString(), unit.getId(), unitBasedEndpointUriBuilder.getHost(), unitBasedEndpointUriBuilder.getPort(), statusCode, getExceptionMessageFromStream(response))); } } }); }
From source file:org.vietspider.net.client.impl.AbstractHttpClient.java
private HttpHost determineTarget(HttpUriRequest request) { // A null target may be acceptable if there is a default target. // Otherwise, the null target is detected in the director. HttpHost target = null;// www .java 2s.c o m URI requestURI = request.getURI(); if (requestURI.isAbsolute()) { target = new HttpHost(requestURI.getHost(), requestURI.getPort(), requestURI.getScheme()); } return target; }
From source file:com.hardincoding.sonar.subsonic.service.SubsonicMusicService.java
private void detectRedirect(String originalUrl, Context context, HttpContext httpContext) { HttpUriRequest request = (HttpUriRequest) httpContext.getAttribute(ExecutionContext.HTTP_REQUEST); HttpHost host = (HttpHost) httpContext.getAttribute(ExecutionContext.HTTP_TARGET_HOST); // Sometimes the request doesn't contain the "http://host" part so we // must take from the HttpHost object. String redirectedUrl;// w w w .ja va 2 s .c o m if (request.getURI().getScheme() == null) { redirectedUrl = host.toURI() + request.getURI(); } else { redirectedUrl = request.getURI().toString(); } redirectFrom = originalUrl.substring(0, originalUrl.indexOf("/rest/")); redirectTo = redirectedUrl.substring(0, redirectedUrl.indexOf("/rest/")); Log.i(TAG, redirectFrom + " redirects to " + redirectTo); redirectionLastChecked = System.currentTimeMillis(); redirectionNetworkType = getCurrentNetworkType(context); }
From source file:org.teleal.cling.transport.impl.apache.StreamClientImpl.java
@Override public StreamResponseMessage sendRequest(StreamRequestMessage requestMessage) { final UpnpRequest requestOperation = requestMessage.getOperation(); log.fine("Preparing HTTP request message with method '" + requestOperation.getHttpMethodName() + "': " + requestMessage);// ww w . j a v a2 s . c om try { // Create the right HTTP request HttpUriRequest httpRequest = createHttpRequest(requestMessage, requestOperation); HttpParams requestParams = getRequestParams(requestMessage); HttpConnectionParams.setConnectionTimeout(requestParams, 30000); HttpConnectionParams.setSoTimeout(requestParams, 30000); // Set all the headers on the request httpRequest.setParams(requestParams); HeaderUtil.add(httpRequest, requestMessage.getHeaders()); log.fine("Sending HTTP request: " + httpRequest.getURI()); return httpClient.execute(httpRequest, createResponseHandler()); } catch (MethodNotSupportedException ex) { log.warning("Request aborted: " + ex.toString()); return null; } catch (ClientProtocolException ex) { log.warning("HTTP protocol exception executing request: " + requestMessage); log.warning("Cause: " + Exceptions.unwrap(ex)); return null; } catch (IOException ex) { log.fine("Client connection was aborted: " + ex.getMessage()); // Don't // log // stacktrace return null; } }
From source file:com.apigee.sdk.apm.http.impl.client.cache.CachingHttpClient.java
/** * @param request//from w w w. ja va2 s . co m * the request to execute * @param context * the context to use for the execution, or <code>null</code> to * use the default context * @return HttpResponse The cached entry or the result of a backend call * @throws IOException */ public HttpResponse execute(HttpUriRequest request, HttpContext context) throws IOException { URI uri = request.getURI(); HttpHost httpHost = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); return execute(httpHost, request, context); }
From source file:com.twitter.hbc.httpclient.ClientBase.java
@Nullable() @VisibleForTesting//from www . j a v a 2 s . com StatusLine establishConnection(Connection conn, HttpUriRequest request) { logger.info("{} Establishing a connection", name); // establish connection StatusLine status = null; try { addEvent(new ConnectionEvent(EventType.CONNECTION_ATTEMPT, request)); status = conn.connect(request); } catch (UnknownHostException e) { // banking on some httpHosts.nextHost() being legitimate, or else this connection will fail. logger.warn("{} Unknown host - {}", name, request.getURI().getHost()); addEvent(new Event(EventType.CONNECTION_ERROR, e)); } catch (IOException e) { logger.warn("{} IOException caught when establishing connection to {}", name, request.getURI()); addEvent(new Event(EventType.CONNECTION_ERROR, e)); reconnectionManager.handleLinearBackoff(); } catch (Exception e) { logger.error(String.format("%s Unknown exception while establishing connection to %s", name, request.getURI()), e); setExitStatus(new Event(EventType.STOPPED_BY_ERROR, e)); } return status; }