List of usage examples for java.net URI getPort
public int getPort()
From source file:io.seldon.external.ExternalPredictionServer.java
public JsonNode predict(String client, JsonNode jsonNode, OptionsHolder options) { long timeNow = System.currentTimeMillis(); URI uri = URI.create(options.getStringOption(URL_PROPERTY_NAME)); try {/* w w w.ja v a 2s . c o m*/ URIBuilder builder = new URIBuilder().setScheme("http").setHost(uri.getHost()).setPort(uri.getPort()) .setPath(uri.getPath()).setParameter("client", client) .setParameter("json", jsonNode.toString()); uri = builder.build(); } catch (URISyntaxException e) { throw new APIException(APIException.GENERIC_ERROR); } HttpContext context = HttpClientContext.create(); HttpGet httpGet = new HttpGet(uri); try { if (logger.isDebugEnabled()) logger.debug("Requesting " + httpGet.getURI().toString()); CloseableHttpResponse resp = httpClient.execute(httpGet, context); try { if (resp.getStatusLine().getStatusCode() == 200) { ObjectMapper mapper = new ObjectMapper(); JsonFactory factory = mapper.getFactory(); JsonParser parser = factory.createParser(resp.getEntity().getContent()); JsonNode actualObj = mapper.readTree(parser); return actualObj; } else { logger.error( "Couldn't retrieve prediction from external prediction server -- bad http return code: " + resp.getStatusLine().getStatusCode()); throw new APIException(APIException.GENERIC_ERROR); } } finally { if (resp != null) resp.close(); if (logger.isDebugEnabled()) logger.debug( "External prediction server took " + (System.currentTimeMillis() - timeNow) + "ms"); } } catch (IOException e) { logger.error("Couldn't retrieve prediction from external prediction server - ", e); throw new APIException(APIException.GENERIC_ERROR); } catch (Exception e) { logger.error("Couldn't retrieve prediction from external prediction server - ", e); throw new APIException(APIException.GENERIC_ERROR); } finally { } }
From source file:org.datacleaner.user.MonitorConnection.java
/** * Determines if a {@link URI} matches the configured DC Monitor settings. * // w w w. j a v a 2 s. c o m * @param uri * @return */ public boolean matchesURI(URI uri) { if (uri == null) { return false; } final String host = uri.getHost(); if (host.equals(_hostname)) { final int port = uri.getPort(); if (port == _port || port == -1) { final String path = removeBeginningSlash(uri.getPath()); if (StringUtils.isNullOrEmpty(_contextPath) || path.startsWith(_contextPath)) { return true; } } } return false; }
From source file:com.mirth.connect.connectors.dimse.DICOMMessageReceiver.java
@Override public void doConnect() throws ConnectException { disposing.set(false);/*from www. j a v a 2 s. c om*/ URI uri = endpoint.getEndpointURI().getUri(); try { dcmrcv.setPort(uri.getPort()); dcmrcv.setHostname(uri.getHost()); dcmrcv.setAEtitle("DCMRCV"); String[] only_def_ts = { UID.ImplicitVRLittleEndian }; String[] native_le_ts = { UID.ImplicitVRLittleEndian }; String[] native_ts = { UID.ImplicitVRLittleEndian }; String[] non_retired_ts = { UID.ImplicitVRLittleEndian }; if (StringUtils.isNotBlank(connector.getDest())) { dcmrcv.setDestination(connector.getDest()); } if (connector.isDefts()) { dcmrcv.setTransferSyntax(only_def_ts); } else if (connector.isNativeData()) { if (connector.isBigendian()) { dcmrcv.setTransferSyntax(native_ts); } else { dcmrcv.setTransferSyntax(native_le_ts); } } else if (connector.isBigendian()) { dcmrcv.setTransferSyntax(non_retired_ts); } if (StringUtils.isNotBlank(connector.getApplicationEntity())) { dcmrcv.setAEtitle(connector.getApplicationEntity()); } if (connector.getReaper() != 10) { dcmrcv.setAssociationReaperPeriod(connector.getReaper()); } if (connector.getIdleto() != 60) { dcmrcv.setIdleTimeout(connector.getIdleto()); } if (connector.getRequestto() != 5) { dcmrcv.setRequestTimeout(connector.getRequestto()); } if (connector.getReleaseto() != 5) { dcmrcv.setReleaseTimeout(connector.getReleaseto()); } if (connector.getSoclosedelay() != 50) { dcmrcv.setSocketCloseDelay(connector.getSoclosedelay()); } if (connector.getRspdelay() > 0) { dcmrcv.setDimseRspDelay(connector.getRspdelay()); } if (connector.getRcvpdulen() != 16) { dcmrcv.setMaxPDULengthReceive(connector.getRcvpdulen()); } if (connector.getSndpdulen() != 16) { dcmrcv.setMaxPDULengthSend(connector.getSndpdulen()); } if (connector.getSosndbuf() > 0) { dcmrcv.setSendBufferSize(connector.getSosndbuf()); } if (connector.getSorcvbuf() > 0) { dcmrcv.setReceiveBufferSize(connector.getSorcvbuf()); } if (connector.getBufsize() != 1) { dcmrcv.setFileBufferSize(connector.getBufsize()); } dcmrcv.setPackPDV(connector.isPdv1()); dcmrcv.setTcpNoDelay(!connector.isTcpdelay()); if (connector.getAsync() > 0) { dcmrcv.setMaxOpsPerformed(connector.getAsync()); } dcmrcv.initTransferCapability(); // connection tls settings if (!StringUtils.equals(connector.getTls(), "notls")) { if (connector.getTls().equals("without")) { dcmrcv.setTlsWithoutEncyrption(); } else if (connector.getTls().equals("3des")) { dcmrcv.setTls3DES_EDE_CBC(); } else if (connector.getTls().equals("aes")) { dcmrcv.setTlsAES_128_CBC(); } if (StringUtils.isNotBlank(connector.getTruststore())) { dcmrcv.setTrustStoreURL(connector.getTruststore()); } if (StringUtils.isNotBlank(connector.getTruststorepw())) { dcmrcv.setTrustStorePassword(connector.getTruststorepw()); } if (StringUtils.isNotBlank(connector.getKeypw())) { dcmrcv.setKeyPassword(connector.getKeypw()); } if (StringUtils.isNotBlank(connector.getKeystore())) { dcmrcv.setKeyStoreURL(connector.getKeystore()); } if (StringUtils.isNotBlank(connector.getKeystorepw())) { dcmrcv.setKeyStorePassword(connector.getKeystorepw()); } dcmrcv.setTlsNeedClientAuth(connector.isNoclientauth()); if (!connector.isNossl2()) { dcmrcv.setTlsProtocol(new String[] { "TLSv1", "SSLv3" }); } dcmrcv.initTLS(); } // start the DICOM port dcmrcv.start(); monitoringController.updateStatus(this.connector, connectorType, Event.INITIALIZED); } catch (Exception e) { throw new ConnectException(new Message("DICOM", 1, uri), e, this); } }
From source file:com.netscape.certsrv.client.PKIClient.java
public <T> T createProxy(String subsystem, Class<T> clazz) throws URISyntaxException { if (subsystem == null) { // by default use the subsystem specified in server URI subsystem = getSubsystem();/*from ww w. j a va 2 s. co m*/ } if (subsystem == null) { throw new PKIException("Missing subsystem name."); } URI serverURI = config.getServerURI(); URI resourceURI = new URI(serverURI.getScheme(), serverURI.getUserInfo(), serverURI.getHost(), serverURI.getPort(), "/" + subsystem + "/rest", serverURI.getQuery(), serverURI.getFragment()); return connection.createProxy(resourceURI, clazz); }
From source file:com.brightcove.com.uploader.helper.MediaAPIHelper.java
/** * Executes a file upload write api call against the given URI. * This is useful for create_video and add_image * @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/*from w ww. j a v a2s. c o m*/ * @throws BadEnvironmentException * @throws MediaAPIError */ public JsonNode executeWrite(JsonNode json, File file, URI uri) throws BadEnvironmentException, MediaAPIError { 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:io.fabric8.mq.coordination.KubernetesControl.java
private void populateBrokerStatistics(Pod pod, Container container, J4pClient client) { ObjectName root = null;/* w w w . ja v a2s .co m*/ String attribute = ""; if (client != null) { try { root = BrokerJmxUtils.getRoot(client); attribute = "BrokerName"; Object brokerName = BrokerJmxUtils.getAttribute(client, root, attribute); attribute = "BrokerId"; Object brokerId = BrokerJmxUtils.getAttribute(client, root, attribute); attribute = "OpenWireURL"; Object uriObj = BrokerJmxUtils.getAttribute(client, root, attribute); URI uri = new URI(uriObj.toString()); int port = uri.getPort(); String amqBrokerURI = "tcp://" + pod.getStatus().getPodIP() + ":" + port; BrokerModel brokerModel = model.getBrokerById(brokerId.toString()); if (brokerModel == null) { BrokerView brokerView = new BrokerView(); brokerView.setBrokerName(brokerName.toString()); brokerView.setBrokerId(brokerId.toString()); brokerView.setUri(amqBrokerURI); brokerModel = new BrokerModel(pod, brokerView, model); brokerModel.start(); model.add(brokerModel); //add transports for (MessageDistribution messageDistribution : messageDistributionList) { brokerView.createTransport(messageDistribution); } } else { //transport might not be valid brokerModel.setUri(amqBrokerURI); brokerModel.updateTransport(); } BrokerOverview brokerOverview = new BrokerOverview(); /** * ToDo: totalConnectionsCount is total connections over lifetime of the Broker * so best find a better way of figuring out "active" connections attribute = "TotalConnectionsCount"; Number result = (Number) BrokerJmxUtils.getAttribute(client, root, attribute); brokerOverview.setTotalConnections(result.intValue()); */ populateDestinations(client, root, brokerOverview); brokerModel.setBrokerStatistics(brokerOverview); } catch (Throwable e) { LOG.error("Unable able to get BrokerStatistics from root=" + root + ",attribute: " + attribute, e); } } }
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 *//*from www .jav a2 s .co 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"); }// w ww. j a v a 2 s . c o m 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 w w w .ja v a 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(); }