List of usage examples for java.net URI getPort
public int getPort()
From source file:org.obm.satellite.client.ConnectionImpl.java
private void post(String hostName, String host, String path) { try {/*from w ww . jav a2 s. c o m*/ URI uri = new URIBuilder().setScheme(configuration.getSatelliteProtocol().getScheme()).setHost(host) .setPort(configuration.getSatellitePort()).setPath(String.format(path, hostName)).build(); StatusLine statusLine = Executor.newInstance(client) .authPreemptive(new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme())) .auth(configuration.getUsername(), configuration.getPassword().getStringValue()) .execute(Request.Post(uri)).returnResponse().getStatusLine(); if (statusLine.getStatusCode() != HttpStatus.SC_OK) { throw new SatteliteClientException(String.format("The MTA at %s returned %s", host, statusLine)); } } catch (IOException e) { throw new ConnectionException(e); } catch (URISyntaxException e) { throw new SatteliteClientException(e); } }
From source file:com.seajas.search.contender.service.modifier.AbstractModifierService.java
/** * Retrieve the FTP client belonging to the given URI. * /*from www.j a v a2s . c o m*/ * @param uri * @return FTPClient */ protected FTPClient retrieveFtpClient(final URI uri) { // Create the FTP client FTPClient ftpClient = uri.getScheme().equalsIgnoreCase("ftps") ? new FTPSClient() : new FTPClient(); try { ftpClient.connect(uri.getHost(), uri.getPort() != -1 ? uri.getPort() : 21); if (!FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) { ftpClient.disconnect(); logger.error("Could not connect to the given FTP server " + uri.getHost() + (uri.getPort() != -1 ? ":" + uri.getPort() : "") + " - " + ftpClient.getReplyString()); return null; } if (StringUtils.hasText(uri.getUserInfo())) { if (uri.getUserInfo().contains(":")) ftpClient.login(uri.getUserInfo().substring(0, uri.getUserInfo().indexOf(":")), uri.getUserInfo().substring(uri.getUserInfo().indexOf(":") + 1)); else ftpClient.login(uri.getUserInfo(), ""); } if (!FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) { ftpClient.disconnect(); logger.error("Could not login to the given FTP server " + uri.getHost() + (uri.getPort() != -1 ? ":" + uri.getPort() : "") + " - " + ftpClient.getReplyString()); return null; } // Switch to PASV and BINARY mode ftpClient.enterLocalPassiveMode(); ftpClient.setFileType(FTP.BINARY_FILE_TYPE); return ftpClient; } catch (IOException e) { logger.error("Could not close input stream during archive processing", e); } return null; }
From source file:org.cleverbus.core.common.ws.transport.http.CloseableHttpComponentsMessageSender.java
/** * Sets the maximum number of connections per host for the underlying HttpClient. The maximum number of connections * per host can be set in a form accepted by the {@code java.util.Properties} class, like as follows: * <p/>//from ww w .j ava 2 s.c o m * <pre> * https://esb.cleverbus.org/esb/=1 * http://esb.cleverbus.org:8080/esb/=7 * http://esb.cleverbus.org/esb/=10 * </pre> * <p/> * The host can be specified as a URI (with scheme and port). * * @param maxConnectionsPerHost a properties object specifying the maximum number of connection * @see PoolingHttpClientConnectionManager#setMaxPerRoute(org.apache.http.conn.routing.HttpRoute, int) */ @Override public void setMaxConnectionsPerHost(Map<String, String> maxConnectionsPerHost) throws URISyntaxException { for (Map.Entry<String, String> entry : maxConnectionsPerHost.entrySet()) { URI uri = new URI(entry.getKey()); HttpHost host = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); HttpRoute route = new HttpRoute(host); PoolingHttpClientConnectionManager connectionManager = (PoolingHttpClientConnectionManager) getConnPoolControl(); int max = Integer.parseInt(entry.getValue()); connectionManager.setMaxPerRoute(route, max); BasicScheme basicAuth = new BasicScheme(); authCache.get().put(host, basicAuth); } }
From source file:info.magnolia.ui.admincentral.shellapp.favorites.FavoritesPresenter.java
String getWebAppRootURI() { final URI currentUri = UI.getCurrent().getPage().getLocation(); String instancePrefix = currentUri.getScheme() + "://" + currentUri.getHost(); if (currentUri.getPort() > -1) { instancePrefix += ":" + currentUri.getPort(); }/*from ww w. ja v a2 s.com*/ instancePrefix += currentUri.getPath(); // Path contains the ctx if (StringUtils.isNotBlank(currentUri.getQuery())) { instancePrefix += "?" + currentUri.getQuery(); } return instancePrefix; }
From source file:se.vgregion.urlservice.services.DefaultUrlServiceService.java
@Override public UrlWithHash expandPath(URI url) { String domain = url.getHost(); if (url.getPort() > 0) { domain += ":" + url.getPort(); }//from ww w . java 2 s . co m return expandPath(url.getPath()); }
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. ja va 2s. 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.pentaho.di.trans.ael.websocket.SessionConfigurator.java
private HttpContext getContext(URI uri) { HttpClientContext httpClientContext = HttpClientContext.create(); //used by httpclient version >= 4.3 httpClientContext.setAttribute(HttpClientContext.HTTP_ROUTE, new HttpRoute(new HttpHost(uri.getHost(), uri.getPort()))); //used by httpclient version 4.2 httpClientContext.setAttribute(HttpClientContext.HTTP_TARGET_HOST, new HttpHost(uri.getHost(), uri.getPort())); return httpClientContext; }
From source file:com.seajas.search.attender.service.mail.MailService.java
/** * Switch the e-mail sender to the inputted mail server, if applicable. */// ww w.ja v a2 s . c o m public void updateWorkingMailServer() { // Use the mail-server override if one has been entered and validated if (attenderService.validateCurrentMailServerDetails()) try { MailSettings settings = attenderService.getMailServerDetails(); URI hostnameURI = settings.getHostnameUri(); ((JavaMailSenderImpl) sender).setHost(hostnameURI.getHost()); Integer schemeStandardPort = "smtps".equals(hostnameURI.getScheme()) ? 465 : 25; ((JavaMailSenderImpl) sender) .setPort(hostnameURI.getPort() != -1 ? hostnameURI.getPort() : schemeStandardPort); if (!StringUtils.isEmpty(settings.getUsername())) ((JavaMailSenderImpl) sender).setUsername(settings.getUsername()); if (!StringUtils.isEmpty(settings.getPassword())) ((JavaMailSenderImpl) sender).setPassword(settings.getPassword()); ((JavaMailSenderImpl) sender).setProtocol(hostnameURI.getScheme()); if (StringUtils.isEmpty(settings.getUsername()) && StringUtils.isEmpty(settings.getPassword())) ((JavaMailSenderImpl) sender).getJavaMailProperties() .setProperty("mail." + hostnameURI.getScheme() + ".auth", "true"); fromAddress = settings.getSender(); } catch (URISyntaxException e) { logger.error("Could not set the given mail settings."); } }
From source file:org.everit.osgi.authentication.cas.tests.SampleApp.java
public SampleApp(final String hostname, final Filter sessionAuthenticationFilter, final Servlet sessionLogoutServlet, final Filter casAuthenticationFilter, final EventListener casAuthenticationEventListener, final AuthenticationContext authenticationContext) throws Exception { super();// w ww . j a v a 2 s . c o m this.hostname = hostname; server = new Server(0); // Initialize servlet context ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS); servletContextHandler.setVirtualHosts(new String[] { hostname }); servletContextHandler.addFilter(new FilterHolder(sessionAuthenticationFilter), "/*", null); servletContextHandler.addFilter(new FilterHolder(casAuthenticationFilter), "/*", null); servletContextHandler.addServlet( new ServletHolder("helloWorldServlet", new HelloWorldServlet(authenticationContext)), HELLO_SERVLET_ALIAS); servletContextHandler.addServlet(new ServletHolder("sessionLogoutServlet", sessionLogoutServlet), LOGOUT_SERVLET_ALIAS); servletContextHandler.addEventListener(casAuthenticationEventListener); server.setHandler(servletContextHandler); // Initialize session management HashSessionManager sessionManager = new HashSessionManager(); String sessionStoreDirecotry = System.getProperty("jetty.session.store.directory"); sessionManager.setStoreDirectory(new File(sessionStoreDirecotry)); sessionManager.setLazyLoad(true); // required to initialize the servlet context before restoring the sessions sessionManager.addEventListener(casAuthenticationEventListener); SessionHandler sessionHandler = servletContextHandler.getSessionHandler(); sessionHandler.setSessionManager(sessionManager); start(); URI serverUri = server.getURI(); port = serverUri.getPort(); String testServerURI = serverUri.toString(); String testServerURL = testServerURI.substring(0, testServerURI.length() - 1); helloServiceUrl = testServerURL + HELLO_SERVLET_ALIAS; sessionLogoutUrl = testServerURL + "/logout"; loggedOutUrl = testServerURL + "/logged-out.html"; failedUrl = testServerURL + "/failed.html"; }
From source file:com.microsoft.tfs.core.clients.reporting.ReportingClient.java
/** * <p>//from www . java 2 s. c o m * 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; }