List of usage examples for java.net URI getHost
public String getHost()
From source file:com.microsoft.tfs.core.clients.reporting.ReportingClient.java
/** * <p>// ww w . ja v a2s . c om * TEE will automatically correct the endpoints registered URL when creating * the web service, however we must provide a mechansim to correct fully * qualified URI's provided as additional URI from the same webservice. * </p> * <p> * We compare the passed uri with the registered web service endpoint, if * they share the same root (i.e. http://TFSERVER) then we correct the * passed uri to be the same as the corrected web service enpoint (i.e. * http://tfsserver.mycompany.com) * </p> * * @see WSSClient#getFixedURI(String) */ public String getFixedURI(final String uri) { Check.notNull(uri, "uri"); //$NON-NLS-1$ try { // Get what the server thinks the url is. String url = connection.getRegistrationClient().getServiceInterfaceURL(ToolNames.WAREHOUSE, ServiceInterfaceNames.REPORTING); if (url == null || url.length() == 0) { // Might be a Rosario server url = connection.getRegistrationClient().getServiceInterfaceURL(ToolNames.WAREHOUSE, ServiceInterfaceNames.REPORTING_WEB_SERVICE_URL); if (url == null || url.length() == 0) { // Couldn't figure this out - just give up and return what // we // were passed. return uri; } is2010Server = true; } final URI registeredEndpointUri = new URI(url); final URI passedUri = new URI(uri); if (passedUri.getScheme().equals(registeredEndpointUri.getScheme()) && passedUri.getHost().equals(registeredEndpointUri.getHost()) && passedUri.getPort() == registeredEndpointUri.getPort()) { final URI endpointUri = ((SOAPService) getProxy()).getEndpoint(); final URI fixedUri = new URI(endpointUri.getScheme(), endpointUri.getHost(), passedUri.getPath(), passedUri.getQuery(), passedUri.getFragment()); return fixedUri.toASCIIString(); } } catch (final URISyntaxException e) { // ignore; } return uri; }
From source file:com.abiquo.abiserver.pojo.service.RemoteService.java
/** * Sets the uri./*from w w w. jav a2 s . co m*/ * * @param uri the new uri */ public void setUri(final String uri) { this.uri = uri; URI u = URI.create(uri); this.protocol = fixProtocol(u.getScheme()); this.domainName = u.getHost(); this.port = u.getPort(); if (port == -1) { port = 80; } this.serviceMapping = u.getPath(); if (serviceMapping.startsWith("/")) { serviceMapping = serviceMapping.replaceFirst("/", ""); } }
From source file:tv.arte.resteventapi.core.services.impl.EventServiceImpl.java
/** * {@inheritDoc}//ww w. j a v a2 s. com */ public RestEvent createRestEvent(RestEventPostRequestParam restEventPostRequestParam) throws RestEventApiValidationException { /* * Database access validations - START */ if (logger.isDebugEnabled()) logger.debug("Start advanced validations requiring database access"); if (restEventPostRequestParam.getId() != null || restEventRepository.exists(restEventPostRequestParam.getId())) { throw new RestEventApiValidationException(Arrays.asList( new FieldValidationError(RestEventApiError.PRE_DEFINED.RIA_ERR_V_ID_NOT_AVAILABLE, "id"))); } try { URI urlToCall = new URI(restEventPostRequestParam.getUrl()); String domain = urlToCall.getHost(); String wwwPrefix = "www."; if (domain.startsWith(wwwPrefix)) { domain = domain.substring(wwwPrefix.length()); } if (!domainAuthorizationRepository.exists(domain)) { throw new RestEventApiValidationException( Arrays.asList(RestEventApiError.PRE_DEFINED.RIA_ERR_V_DOMAIN_NOT_QUERYABLE)); } } catch (URISyntaxException e) { throw new RestEventApiValidationException(Arrays.asList(new FieldValidationError( RestEventApiError.PRE_DEFINED.RIA_ERR_V_URL_DOMAIN_UNEXTRACTABLE, "url"))); } if (logger.isDebugEnabled()) logger.debug("End advanced validations requiring database access. Validations passed."); /* * Database access validations - END */ RestEvent newRestEvent = new RestEvent(); if (StringUtils.isNotBlank(restEventPostRequestParam.getId())) { newRestEvent.setId(restEventPostRequestParam.getId()); } else { String newId = UUID.randomUUID().toString(); final int maxLoops = 10000; int currentLoop = 0; while (restEventRepository.exists(newId)) { newId = UUID.randomUUID().toString(); currentLoop++; if (currentLoop >= maxLoops) { throw new RestEventApiRuntimeException( "Cannot generate id for a new rest event. The maximum number of loops has been reached."); } } newRestEvent.setId(newId); } newRestEvent.setBody(restEventPostRequestParam.getBody()); newRestEvent.setHeaders(restEventPostRequestParam.getHeaders()); newRestEvent.setInterval(restEventPostRequestParam.getInterval()); newRestEvent.setMaxAttempts(restEventPostRequestParam.getMaxAttempts()); newRestEvent.setMethod(restEventPostRequestParam.getMethod()); newRestEvent.setTimeout(restEventPostRequestParam.getTimeout()); newRestEvent.setTriggerDate(restEventPostRequestParam.getTriggerDate()); newRestEvent.setUrl(restEventPostRequestParam.getUrl()); newRestEvent.setCounter(0); newRestEvent.setStatus(RestEventStatus.BUFFER); newRestEvent.setNextExecution(restEventPostRequestParam.getTriggerDate()); //TODO: Remove the automatic increment of the version once the @Version annotation is working properly newRestEvent.setVersion(1L); newRestEvent.setCreationDate(Calendar.getInstance().getTime()); restEventRepository.save(newRestEvent); return newRestEvent; }
From source file:com.subgraph.vega.internal.http.requests.HttpRequestBuilder.java
@Override public synchronized void setFromUri(URI uri) { if (uri.getScheme() != null) { scheme = uri.getScheme();//from www.j a v a2 s . c o m if (uri.getHost() != null) { host = uri.getHost(); hostPort = uri.getPort(); if (hostPort == -1) { hostPort = getSchemeDefaultPort(scheme); } } } setPathFromUri(uri); }
From source file:com.brightcove.zartan.common.helper.MediaAPIHelper.java
/** * Executes a file upload write api call against the given URI. This is useful for create_video * and add_image//w ww. j a v a2 s . co m * * @param json the json representation of the call you are making * @param file the file you are uploading * @param uri the api servlet you want to execute against * @return json response from api * @throws BadEnvironmentException * @throws MediaAPIException */ public JsonNode executeWrite(JsonNode json, File file, URI uri) throws BadEnvironmentException, MediaAPIException { mLog.debug("using " + uri.getHost() + " on port " + uri.getPort() + " for api write"); HttpPost method = new HttpPost(uri); MultipartEntity entityIn = new MultipartEntity(); FileBody fileBody = null; if (file != null) { fileBody = new FileBody(file); } try { entityIn.addPart("JSON-RPC", new StringBody(json.toString(), Charset.forName("UTF-8"))); } catch (UnsupportedEncodingException e) { throw new BadEnvironmentException("UTF-8 no longer supported"); } if (file != null) { entityIn.addPart(file.getName(), fileBody); } method.setEntity(entityIn); return executeCall(method); }
From source file:kuona.jenkins.analyser.JenkinsClient.java
/** * Create an authenticated Jenkins HTTP client * * @param uri Location of the jenkins server (ex. http://localhost:8080) * @param username Username to use when connecting * @param password Password or auth token to use when connecting *//* w ww . java 2s . c o m*/ public JenkinsClient(Project project, URI uri, String username, String password) { this(project, uri); if (isNotBlank(username)) { CredentialsProvider provider = client.getCredentialsProvider(); AuthScope scope = new AuthScope(uri.getHost(), uri.getPort(), "realm"); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password); provider.setCredentials(scope, credentials); localContext = new BasicHttpContext(); localContext.setAttribute("preemptive-auth", new BasicScheme()); client.addRequestInterceptor(new PreemptiveAuth(), 0); } }
From source file:org.apache.cxf.transport.http.asyncclient.CXFHttpAsyncRequestProducer.java
public HttpHost getTarget() { URI uri = request.getURI(); if (uri == null) { throw new IllegalStateException("Request URI is null"); }//from www . ja v a 2s . c om if (!uri.isAbsolute()) { throw new IllegalStateException("Request URI is not absolute"); } return new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); }
From source file:org.apache.hadoop.gateway.shell.Hadoop.java
private CloseableHttpClient createClient(ClientContext clientContext) throws GeneralSecurityException { // SSL/*from ww w . j ava 2 s. co m*/ HostnameVerifier hostnameVerifier = NoopHostnameVerifier.INSTANCE; TrustStrategy trustStrategy = null; if (clientContext.connection().secure()) { hostnameVerifier = SSLConnectionSocketFactory.getDefaultHostnameVerifier(); } else { trustStrategy = TrustSelfSignedStrategy.INSTANCE; System.out.println("**************** WARNING ******************\n" + "This is an insecure client instance and may\n" + "leave the interactions subject to a man in\n" + "the middle attack. Please use the login()\n" + "method instead of loginInsecure() for any\n" + "sensitive or production usecases.\n" + "*******************************************"); } KeyStore trustStore = getTrustStore(); SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(trustStore, trustStrategy).build(); Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", new SSLConnectionSocketFactory(sslContext, hostnameVerifier)).build(); // Pool PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(registry); connectionManager.setMaxTotal(clientContext.pool().maxTotal()); connectionManager.setDefaultMaxPerRoute(clientContext.pool().defaultMaxPerRoute()); ConnectionConfig connectionConfig = ConnectionConfig.custom() .setBufferSize(clientContext.connection().bufferSize()).build(); connectionManager.setDefaultConnectionConfig(connectionConfig); SocketConfig socketConfig = SocketConfig.custom().setSoKeepAlive(clientContext.socket().keepalive()) .setSoLinger(clientContext.socket().linger()) .setSoReuseAddress(clientContext.socket().reuseAddress()) .setSoTimeout(clientContext.socket().timeout()).setTcpNoDelay(clientContext.socket().tcpNoDelay()) .build(); connectionManager.setDefaultSocketConfig(socketConfig); // Auth URI uri = URI.create(clientContext.url()); host = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); CredentialsProvider credentialsProvider = null; if (clientContext.username() != null && clientContext.password() != null) { credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(new AuthScope(host.getHostName(), host.getPort()), new UsernamePasswordCredentials(clientContext.username(), clientContext.password())); AuthCache authCache = new BasicAuthCache(); BasicScheme authScheme = new BasicScheme(); authCache.put(host, authScheme); context = new BasicHttpContext(); context.setAttribute(org.apache.http.client.protocol.HttpClientContext.AUTH_CACHE, authCache); } return HttpClients.custom().setConnectionManager(connectionManager) .setDefaultCredentialsProvider(credentialsProvider).build(); }