List of usage examples for java.net URI toString
public String toString()
From source file:com.microsoft.alm.common.utils.UrlHelper.java
public static String getHttpsUrlFromHttpUrl(final String httpUrl) { final URI uri = createUri(httpUrl); String httpsUrl = httpUrl;//from ww w. j av a2 s . c o m if (uri != null && StringUtils.equalsIgnoreCase(uri.getScheme(), "http")) { final URI httpsUri = createUri("https://" + uri.getAuthority() + uri.getPath()); httpsUrl = httpsUri.toString(); } if (StringUtils.startsWithIgnoreCase(httpsUrl, "https://")) { return httpsUrl; } else { return null; } }
From source file:URISupport.java
/** * @param uri/* ww w .jav a2 s .c o m*/ * @param rc * @param ssp * @param p * @throws URISyntaxException */ private static void parseComposite(URI uri, CompositeData rc, String ssp) throws URISyntaxException { String componentString; String params; if (!checkParenthesis(ssp)) { throw new URISyntaxException(uri.toString(), "Not a matching number of '(' and ')' parenthesis"); } int p; int intialParen = ssp.indexOf("("); if (intialParen == 0) { rc.host = ssp.substring(0, intialParen); p = rc.host.indexOf("/"); if (p >= 0) { rc.path = rc.host.substring(p); rc.host = rc.host.substring(0, p); } p = ssp.lastIndexOf(")"); componentString = ssp.substring(intialParen + 1, p); params = ssp.substring(p + 1).trim(); } else { componentString = ssp; params = ""; } String components[] = splitComponents(componentString); rc.components = new URI[components.length]; for (int i = 0; i < components.length; i++) { rc.components[i] = new URI(components[i].trim()); } p = params.indexOf("?"); if (p >= 0) { if (p > 0) { rc.path = stripPrefix(params.substring(0, p), "/"); } rc.parameters = parseQuery(params.substring(p + 1)); } else { if (params.length() > 0) { rc.path = stripPrefix(params, "/"); } rc.parameters = emptyMap(); } }
From source file:com.microsoft.alm.common.utils.UrlHelper.java
public static URI resolveEndpointUri(URI baseUri, String endpointPath) { if (!baseUri.getPath().endsWith("/")) { baseUri = createUri(baseUri.toString() + "/"); }// www .j a va 2s . co m if (endpointPath.startsWith("/")) { endpointPath = endpointPath.substring(1); } return baseUri.resolve(endpointPath); }
From source file:com.microsoft.tfs.core.clients.registration.RegistrationData.java
public static RegistrationData load(final PersistenceStore cacheStore, final URI serverURI) { Check.notNull(cacheStore, "cacheStore"); //$NON-NLS-1$ Check.notNull(serverURI, "serverURI"); //$NON-NLS-1$ final ServerMap serverMap = ServerMap.load(cacheStore); final String uriString = serverURI.toString(); final String instanceID = serverMap.getServerID(uriString); if (instanceID == null) { return null; }// w w w .j a v a 2 s. c o m final String childLocationName = RegistrationData.makeChildLocationName(serverURI, instanceID); return RegistrationData.load(cacheStore, childLocationName); }
From source file:com.microsoft.alm.common.utils.UrlHelper.java
public static URI getCreateWorkItemURI(final URI projectUri) { //TODO: this url isn't exactly correct because we don't know the WI Type to create return UrlHelper.createUri(projectUri.toString().concat(URL_SEPARATOR).concat(URL_WIT_PATH_SEGMENT)); }
From source file:org.kie.smoke.wb.util.RestUtil.java
public static <T, G> T getQuery(URL deploymentUrl, String relativeUrl, String mediaType, int status, String user, String password, Map<String, String> queryParams, Class... responseTypes) { URIBuilder uriBuilder = null;//from w w w. j a va 2 s . c o m try { String uriStr = createBaseUriString(deploymentUrl, relativeUrl); uriBuilder = new URIBuilder(uriStr); } catch (URISyntaxException urise) { logAndFail("Invalid uri :" + deploymentUrl.toString(), urise); } for (Entry<String, String> paramEntry : queryParams.entrySet()) { uriBuilder.addParameter(paramEntry.getKey(), paramEntry.getValue()); } URI uri = null; String uriStr = null; try { uri = uriBuilder.build(); uriStr = uri.toString(); } catch (URISyntaxException urise) { logAndFail("Invalid uri!", urise); } ResponseHandler<T> rh = createResponseHandler(mediaType, status, responseTypes); // @formatter:off Request request = Request.Get(uri).addHeader(HttpHeaders.ACCEPT, mediaType.toString()) .addHeader(HttpHeaders.AUTHORIZATION, basicAuthenticationHeader(user, password)); // @formatter:off Response resp = null; try { logOp("GET", uriStr); resp = request.execute(); } catch (Exception e) { logAndFail("[GET] " + uriStr, e); } try { return resp.handleResponse(rh); } catch (Exception e) { logAndFail("Failed retrieving response from [GET] " + uriStr, e); } // never happens return null; }
From source file:org.kie.remote.tests.base.RestUtil.java
public static <T, G> T getQuery(URL deploymentUrl, String relativeUrl, String mediaType, int status, String user, String password, Map<String, String> queryParams, Class... responseTypes) { URIBuilder uriBuilder = null;/* w w w.ja v a 2s .co m*/ try { String uriStr = createBaseUriString(deploymentUrl, relativeUrl); uriBuilder = new URIBuilder(uriStr); } catch (URISyntaxException urise) { failAndLog("Invalid uri :" + deploymentUrl.toString(), urise); } for (Entry<String, String> paramEntry : queryParams.entrySet()) { String param = paramEntry.getKey(); String value = paramEntry.getValue(); uriBuilder.addParameter(paramEntry.getKey(), paramEntry.getValue()); } URI uri = null; String uriStr = null; try { uri = uriBuilder.build(); uriStr = uri.toString(); } catch (URISyntaxException urise) { failAndLog("Invalid uri!", urise); } ResponseHandler<T> rh = createResponseHandler(mediaType, status, responseTypes); // @formatter:off Request request = Request.Get(uri).addHeader(HttpHeaders.ACCEPT, mediaType.toString()) .addHeader(HttpHeaders.AUTHORIZATION, basicAuthenticationHeader(user, password)); // @formatter:off Response resp = null; try { logOp("GET", uriStr); resp = request.execute(); } catch (Exception e) { failAndLog("[GET] " + uriStr, e); } try { return resp.handleResponse(rh); } catch (Exception e) { failAndLog("Failed retrieving response from [GET] " + uriStr, e); } // never happens return null; }
From source file:com.vmware.identity.openidconnect.common.AuthenticationErrorResponse.java
private static HTTPResponse ajaxRedirectResponse(URI redirectLocation) throws SerializeException { HTTPResponse httpResponse = new HTTPResponse(HTTPResponse.SC_OK); try {//ww w. j ava2s .c o m httpResponse.setContentType(new ContentType("text/html;charset=UTF-8")); } catch (ParseException e) { throw new SerializeException("could not set response type header", e); } httpResponse.setCacheControl("no-cache, no-store"); httpResponse.setPragma("no-cache"); httpResponse.setContent(redirectLocation.toString()); return httpResponse; }
From source file:com.liferay.jira.metrics.util.JiraETLUtil.java
private static void _loadIssueMetricsFromJiraByProjectAndStatuses(JiraProject jiraProject, List<JiraStatus> jiraStatuses) throws JiraConnectionException, PortalException, SystemException { Date date = new Date(); List<String> statusNames = new ArrayList<String>(); for (JiraStatus jiraStatus : jiraStatuses) { statusNames.add(jiraStatus.getName()); }//w w w .j a va 2 s. c o m List<IssuesMetric> issuesMetricList = _jiraClient.getIssuesMetricsByProjectStatus(jiraProject.getKey(), statusNames); for (IssuesMetric issueMetric : issuesMetricList) { BasicComponent issuesMetricComponent = issueMetric.getComponent(); URI componentUri = issuesMetricComponent.getSelf(); JiraComponent jiraComponent = JiraComponentLocalServiceUtil .getJiraComponentByUri(componentUri.toString()); JiraStatus jiraStatus = JiraStatusLocalServiceUtil.getJiraStatusByName(issueMetric.getStatusName()); Priority priority = issueMetric.getPriority(); JiraMetric jiraMetric = null; long jiraPriorityId = IssuesMetric.EMPTY_PRIORITY; if (priority != null) { JiraPriority jiraPriority = JiraPriorityLocalServiceUtil .getJiraPriorityByValue(priority.getId().toString()); jiraPriorityId = jiraPriority.getJiraPriorityId(); } try { jiraMetric = JiraMetricLocalServiceUtil.addJiraMetric(jiraComponent.getJiraProjectId(), jiraComponent.getJiraComponentId(), jiraStatus.getJiraStatusId(), jiraPriorityId, date, issueMetric.getTotal()); if (_log.isInfoEnabled()) { _log.info("[" + jiraMetric.getJiraProjectId() + "][" + jiraMetric.getJiraComponentId() + "][" + jiraMetric.getJiraStatusId() + "][" + jiraPriorityId + "] imported sucessfully"); } } catch (DuplicateJiraMetricException djme) { if (!PortletPropsValues.MERGE_STRATEGY.equals("update")) { return; } if (_log.isWarnEnabled()) { _log.warn("Jira Metric [" + jiraComponent.getJiraProjectId() + "][" + jiraComponent.getJiraComponentId() + "][" + jiraStatus.getJiraStatusId() + "][" + jiraPriorityId + "][" + date + "] already exists. Let's update it."); } jiraMetric = JiraMetricLocalServiceUtil.getJiraMetric(jiraComponent.getJiraProjectId(), jiraComponent.getJiraComponentId(), jiraStatus.getJiraStatusId(), jiraPriorityId, date); jiraMetric.setTotal(issueMetric.getTotal()); jiraMetric.setModifiedDate(new Date()); JiraMetricLocalServiceUtil.updateJiraMetric(jiraMetric); if (_log.isInfoEnabled()) { _log.info("[" + jiraMetric.getJiraProjectId() + "][" + jiraMetric.getJiraComponentId() + "][" + jiraMetric.getJiraStatusId() + "]" + " updated sucessfully"); } } } }
From source file:de.mpg.imeji.presentation.util.SearchAndExportHelper.java
public static String getCitation(Publication publication) { URI uri = publication.getUri(); URI searchAndExportUri = URI.create("http://" + uri.getHost() + "/search/SearchAndExport"); String itemId = null;/*w w w.ja va2 s.c o m*/ if (uri.getQuery() != null && uri.getQuery().contains("itemId=")) { itemId = uri.getQuery().split("itemId=")[1]; } else if (uri.getPath() != null && uri.getPath().contains("/item/")) { itemId = uri.getPath().split("/item/")[1]; } if (UrlHelper.isValidURI(searchAndExportUri)) { try { HttpClient client = new HttpClient(); String exportUri = searchAndExportUri.toString() + "?cqlQuery=" + URLEncoder.encode( "escidoc.objid=" + itemId + " or escidoc.property.version.objid=" + itemId, "ISO-8859-1") + "&exportFormat=" + publication.getExportFormat() + "&outputFormat=html_linked"; GetMethod method = new GetMethod(exportUri); client.executeMethod(method); return method.getResponseBodyAsString(); } catch (Exception e) { return null; } } return null; }