List of usage examples for java.net URI getPort
public int getPort()
From source file:org.fcrepo.kernel.impl.identifiers.HttpPidMinter.java
/** * Setup authentication in httpclient./*from www. j a v a 2 s. c om*/ **/ protected HttpClient buildClient() { HttpClientBuilder builder = HttpClientBuilder.create().useSystemProperties() .setConnectionManager(new PoolingHttpClientConnectionManager()); if (!isBlank(username) && !isBlank(password)) { final URI uri = URI.create(url); final CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(uri.getHost(), uri.getPort()), new UsernamePasswordCredentials(username, password)); builder = builder.setDefaultCredentialsProvider(credsProvider); } return builder.build(); }
From source file:nl.esciencecenter.octopus.webservice.job.OctopusManager.java
/** * Submit a job request.//from ww w .j a va2 s .c om * * @param request The job request * @param httpClient http client used to reporting status to job callback. * @return SandboxedJob job * * @throws OctopusIOException * @throws OctopusException * @throws URISyntaxException */ public SandboxedJob submitJob(JobSubmitRequest request, HttpClient httpClient) throws OctopusIOException, OctopusException, URISyntaxException { Credential credential = configuration.getCredential(); // filesystems cant have path in them so strip eg. file:///tmp to file:/// URI s = configuration.getSandboxRoot(); URI sandboxURI = new URI(s.getScheme(), s.getUserInfo(), s.getHost(), s.getPort(), "/", s.getQuery(), s.getFragment()); //create sandbox FileSystem sandboxFS = octopus.files().newFileSystem(sandboxURI, credential, null); String sandboxRoot = configuration.getSandboxRoot().getPath(); AbsolutePath sandboxRootPath = octopus.files().newPath(sandboxFS, new RelativePath(sandboxRoot)); Sandbox sandbox = request.toSandbox(octopus, sandboxRootPath, null); // create job description JobDescription description = request.toJobDescription(); description.setQueueName(configuration.getQueue()); description.setWorkingDirectory(sandbox.getPath().getPath()); long cancelTimeout = configuration.getPollConfiguration().getCancelTimeout(); // CancelTimeout is in milliseconds and MaxTime must be in minutes, so convert it int maxTime = (int) TimeUnit.MINUTES.convert(cancelTimeout, TimeUnit.MILLISECONDS); description.setMaxTime(maxTime); // stage input files sandbox.upload(); // submit job Job job = octopus.jobs().submitJob(scheduler, description); // store job in jobs map SandboxedJob sjob = new SandboxedJob(sandbox, job, request, httpClient); jobs.put(sjob.getIdentifier(), sjob); // JobsPoller will poll job status and download sandbox when job is done. return sjob; }
From source file:tools.devnull.boteco.client.rest.impl.DefaultRestConfiguration.java
@Override public RestConfiguration withAuthentication(String user, String password) { // Create AuthCache instance AuthCache authCache = new BasicAuthCache(); // Generate BASIC scheme object and add it to the local auth cache BasicScheme basicAuth = new BasicScheme(); CredentialsProvider provider = new BasicCredentialsProvider(); URI uri = request.getURI(); authCache.put(new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()), basicAuth); provider.setCredentials(new AuthScope(uri.getHost(), AuthScope.ANY_PORT), new UsernamePasswordCredentials(user, password)); this.context.setCredentialsProvider(provider); this.context.setAuthCache(authCache); return this; }
From source file:com.whizzosoftware.hobson.wemo.WeMoPlugin.java
protected String minifyURI(URI uri) { if ("http".equals(uri.getScheme()) && uri.getPath().endsWith("setup.xml")) { if (uri.getPort() == 49153) { return uri.getHost(); } else {// w w w.j a v a 2 s. c o m return uri.getHost() + ":" + uri.getPort(); } } else { return uri.toASCIIString(); } }
From source file:org.soyatec.windowsazure.authenticate.SharedKeyCredentialsWrapper.java
/** * Append the signedString to the uri.//from w w w .j a va2 s.c o m * * @param uri * @param signedString * @return The uri after be appended with signedString. */ private URI appendSignString(URI uri, String signedString) { try { return URIUtils.createURI(uri.getScheme(), uri.getHost(), uri.getPort(), HttpUtilities.getNormalizePath(uri), (uri.getQuery() == null ? Utilities.emptyString() : uri.getQuery()) + "&" + signedString, uri.getFragment()); } catch (URISyntaxException e) { Logger.error("", e); } return uri; }
From source file:org.sonatype.nexus.client.rest.jersey.NexusClientFactoryImpl.java
/** * NXCM-4547 JERSEY-1293 Enforce proxy setting on httpclient * <p/>/*from w ww. j a v a 2s . c om*/ * Revisit for jersey 1.13. */ private void enforceProxyUri(final ApacheHttpClient4Config config, final ApacheHttpClient4 client) { final Object proxyProperty = config.getProperties().get(PROPERTY_PROXY_URI); if (proxyProperty != null) { final URI uri = getProxyUri(proxyProperty); final HttpHost proxy = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); client.getClientHandler().getHttpClient().getParams().setParameter(DEFAULT_PROXY, proxy); } }
From source file:org.dspace.identifier.ezid.EZIDRequest.java
/** * Prepare a context for requests concerning a specific identifier or * authority prefix.//from w w w.j a v a2 s .c om * * @param scheme URL scheme for access to the EZID service. * @param host Host name for access to the EZID service. * @param authority DOI authority prefix, e.g. "10.5072/FK2". * @param username an EZID user identity. * @param password user's password, or {@code null} for none. * @throws URISyntaxException if host or authority is bad. */ EZIDRequest(String scheme, String host, String authority, String username, String password) throws URISyntaxException { this.scheme = scheme; this.host = host; if (authority.charAt(authority.length() - 1) == '/') { this.authority = authority.substring(0, authority.length() - 1); } else { this.authority = authority; } client = new DefaultHttpClient(); if (null != username) { URI uri = new URI(scheme, host, null, null); client.getCredentialsProvider().setCredentials(new AuthScope(uri.getHost(), uri.getPort()), new UsernamePasswordCredentials(username, password)); } }
From source file:com.tascape.reactor.report.SuiteResultExportTestRailView.java
private void getParameters() throws URISyntaxException { Map<String, String> map = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap(); String v = map.get("srid"); if (v != null) { this.srid = v; LOG.debug("srid={}", this.srid); }//from www . java 2 s . c o m String ref = FacesContext.getCurrentInstance().getExternalContext().getRequestHeaderMap().get("referer"); URI u = new URI(ref); this.logBaseUrl = u.getScheme() + "://" + u.getHost() + ":" + u.getPort() + "/logs/" + srid + "/"; LOG.debug("logBaseUrl={}", logBaseUrl); }
From source file:org.wso2.carbon.http2.transport.Http2TransportSender.java
/** * Handels requests come from Axis2 Engine * * @param msgCtx//from w ww .j av a2 s .c o m * @param targetEPR * @param trpOut * @throws AxisFault */ public void sendMessage(MessageContext msgCtx, String targetEPR, OutTransportInfo trpOut) throws AxisFault { try { if (targetEPR.toLowerCase().contains("http2://")) { targetEPR = targetEPR.replaceFirst("http2://", "http://"); } else if (targetEPR.toLowerCase().contains("https2://")) { targetEPR = targetEPR.replaceFirst("https2://", "https://"); } URI uri = new URI(targetEPR); String scheme = uri.getScheme() != null ? uri.getScheme() : "http"; String hostname = uri.getHost(); int port = uri.getPort(); if (port == -1) { // use default if ("http".equals(scheme)) { port = 80; } else if ("https".equals(scheme)) { port = 443; } } HttpHost target = new HttpHost(hostname, port, scheme); boolean secure = "https".equals(target.getSchemeName()); HttpHost proxy = proxyConfig.selectProxy(target); msgCtx.setProperty(PassThroughConstants.PROXY_PROFILE_TARGET_HOST, target.getHostName()); HttpRoute route; if (proxy != null) { route = new HttpRoute(target, null, proxy, secure); } else { route = new HttpRoute(target, null, secure); } Http2TargetRequestUtil util = new Http2TargetRequestUtil(targetConfiguration, route); msgCtx.setProperty(Http2Constants.PASSTHROUGH_TARGET, util); if (msgCtx.getProperty(PassThroughConstants.PASS_THROUGH_PIPE) == null) { Pipe pipe = new Pipe(targetConfiguration.getBufferFactory().getBuffer(), "Test", targetConfiguration); msgCtx.setProperty(PassThroughConstants.PASS_THROUGH_PIPE, pipe); msgCtx.setProperty(PassThroughConstants.MESSAGE_BUILDER_INVOKED, Boolean.TRUE); } Http2ClientHandler clientHandler = connectionFactory.getChannelHandler(target); String tenantDomain = (msgCtx.getProperty(MultitenantConstants.TENANT_DOMAIN) == null) ? null : (String) msgCtx.getProperty(MultitenantConstants.TENANT_DOMAIN); String dispatchSequence = (msgCtx.getProperty(Http2Constants.HTTP2_DISPATCH_SEQUENCE) == null) ? null : (String) msgCtx.getProperty(Http2Constants.HTTP2_DISPATCH_SEQUENCE); String errorSequence = (msgCtx.getProperty(Http2Constants.HTTP2_ERROR_SEQUENCE) == null) ? null : (String) msgCtx.getProperty(Http2Constants.HTTP2_ERROR_SEQUENCE); InboundResponseSender responseSender = (msgCtx .getProperty(InboundEndpointConstants.INBOUND_ENDPOINT_RESPONSE_WORKER) == null) ? null : (InboundResponseSender) msgCtx .getProperty(InboundEndpointConstants.INBOUND_ENDPOINT_RESPONSE_WORKER); boolean serverPushEnabled = (msgCtx .getProperty(Http2Constants.HTTP2_PUSH_PROMISE_REQEUST_ENABLED) == null) ? false : (boolean) msgCtx.getProperty(Http2Constants.HTTP2_PUSH_PROMISE_REQEUST_ENABLED); clientHandler.setResponseReceiver(tenantDomain, dispatchSequence, errorSequence, responseSender, targetConfiguration, serverPushEnabled); clientHandler.channelWrite(msgCtx); } catch (URISyntaxException e) { log.error("Error parsing the http2 endpoint url"); throw new AxisFault(e.getMessage()); } }
From source file:com.okta.sdk.impl.http.httpclient.HttpClientRequestFactory.java
/** * Configures the headers in the specified Apache HTTP request. *//* w w w. j av a2 s.co m*/ private void applyHeaders(HttpRequestBase httpRequest, Request request) { /* * Apache HttpClient omits the port number in the Host header (even if * we explicitly specify it) if it's the default port for the protocol * in use. To ensure that we use the same Host header in the request and * in the calculated string to sign (even if Apache HttpClient changed * and started honoring our explicit host with endpoint), we follow this * same behavior here and in the RequestAuthenticator. */ URI endpoint = request.getResourceUrl(); String hostHeader = endpoint.getHost(); if (!RequestUtils.isDefaultPort(endpoint)) { hostHeader += ":" + endpoint.getPort(); } httpRequest.addHeader("Host", hostHeader); httpRequest.addHeader("Accept-Encoding", "gzip"); // Copy over any other headers already in our request for (Map.Entry<String, List<String>> entry : request.getHeaders().entrySet()) { String key = entry.getKey(); List<String> value = entry.getValue(); /* * HttpClient4 fills in the Content-Length header and complains if * it's already present, so we skip it here. We also skip the Host * header to avoid sending it twice, which will interfere with some * signing schemes. */ if (!"Content-Length".equalsIgnoreCase(key) && !"Host".equalsIgnoreCase(key)) { String delimited = Strings.collectionToCommaDelimitedString(value); httpRequest.addHeader(key, delimited); } } }