List of usage examples for java.net URI getFragment
public String getFragment()
From source file:podd.tab.TabImporter.java
/** * Populate the podd objects that have embedded children with the embedded children * @throws PoddTabException /*www.j a v a 2s . c o m*/ */ private void populateWithEmbeddedChildren() throws PoddTabException { if (idPoddEntityMap != null) { for (Map.Entry<String, PoddEntityWrapper> entry : idPoddEntityMap.entrySet()) { String id = entry.getKey(); PoddEntityWrapper pew = entry.getValue(); if (!pew.getIsEmbedded()) { List<PoddEntityWrapper> embeddedChildren = this.parentIdEmbeddedChildMap.get(id); if (embeddedChildren != null) { for (PoddEntityWrapper embeddedChild : embeddedChildren) { // Assign all of the embedded object IDs if they don't already have it try { if (embeddedChild.getPoddEntity().getId() == null) { // Randomly generate an ID URI idURI = new URI( PoddModelNamespace.PODD_MODEL.uri + UUID.randomUUID().toString()); embeddedChild.getPoddEntity().setId(idURI); } } catch (URISyntaxException e) { e.printStackTrace(); LOGGER.error("Found exception", e); throw new PoddTabException(e); } // Also explicity add the relationship property between the parent and its embedded child URI childObjectTypeURI = embeddedChild.getPoddEntity().getObjectTypeURI(); String childObjectType = childObjectTypeURI.getFragment(); URI relationshipURI = this.getModelURI(childObjectType, true); // Add the relationship property to the PoddEntity PoddObjectProperty objProperty = new PoddObjectProperty(); objProperty.setProperty(relationshipURI); objProperty.setValue(embeddedChild.getPoddEntity().getId().toString()); pew.getPoddEntity().addProperty(objProperty); pew.addEmbeddedChild(embeddedChild); } } } } } }
From source file:org.apache.http.impl.client.DefaultRedirectHandler.java
public URI getLocationURI(final HttpResponse response, final HttpContext context) throws ProtocolException { Args.notNull(response, "HTTP response"); //get the location header to find out where to redirect to final Header locationHeader = response.getFirstHeader("location"); if (locationHeader == null) { // got a redirect response, but no location header throw new ProtocolException( "Received redirect response " + response.getStatusLine() + " but no location header"); }//from w w w .j av a2 s . c om final String location = locationHeader.getValue(); if (this.log.isDebugEnabled()) { this.log.debug("Redirect requested to location '" + location + "'"); } URI uri; try { uri = new URI(location); } catch (final URISyntaxException ex) { throw new ProtocolException("Invalid redirect URI: " + location, ex); } final HttpParams params = response.getParams(); // rfc2616 demands the location value be a complete URI // Location = "Location" ":" absoluteURI if (!uri.isAbsolute()) { if (params.isParameterTrue(ClientPNames.REJECT_RELATIVE_REDIRECT)) { throw new ProtocolException("Relative redirect location '" + uri + "' not allowed"); } // Adjust location URI final HttpHost target = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST); Asserts.notNull(target, "Target host"); final HttpRequest request = (HttpRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST); try { final URI requestURI = new URI(request.getRequestLine().getUri()); final URI absoluteRequestURI = URIUtils.rewriteURI(requestURI, target, true); uri = URIUtils.resolve(absoluteRequestURI, uri); } catch (final URISyntaxException ex) { throw new ProtocolException(ex.getMessage(), ex); } } if (params.isParameterFalse(ClientPNames.ALLOW_CIRCULAR_REDIRECTS)) { RedirectLocations redirectLocations = (RedirectLocations) context.getAttribute(REDIRECT_LOCATIONS); if (redirectLocations == null) { redirectLocations = new RedirectLocations(); context.setAttribute(REDIRECT_LOCATIONS, redirectLocations); } final URI redirectURI; if (uri.getFragment() != null) { try { final HttpHost target = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); redirectURI = URIUtils.rewriteURI(uri, target, true); } catch (final URISyntaxException ex) { throw new ProtocolException(ex.getMessage(), ex); } } else { redirectURI = uri; } if (redirectLocations.contains(redirectURI)) { throw new CircularRedirectException("Circular redirect to '" + redirectURI + "'"); } else { redirectLocations.add(redirectURI); } } return uri; }
From source file:com.mongolduu.android.ng.misc.RedirectHandler.java
public URI getLocationURI(final HttpResponse response, final HttpContext context) throws ProtocolException { if (response == null) { throw new IllegalArgumentException("HTTP response may not be null"); }/* w w w . j a v a 2 s . c o m*/ // get the location header to find out where to redirect to Header locationHeader = response.getFirstHeader("location"); if (locationHeader == null) { // got a redirect response, but no location header throw new ProtocolException( "Received redirect response " + response.getStatusLine() + " but no location header"); } // HERE IS THE MODIFIED LINE OF CODE String location = locationHeader.getValue().replaceAll(" ", "%20"); URI uri; try { uri = new URI(location); } catch (URISyntaxException ex) { throw new ProtocolException("Invalid redirect URI: " + location, ex); } HttpParams params = response.getParams(); // rfc2616 demands the location value be a complete URI // Location = "Location" ":" absoluteURI if (!uri.isAbsolute()) { if (params.isParameterTrue(ClientPNames.REJECT_RELATIVE_REDIRECT)) { throw new ProtocolException("Relative redirect location '" + uri + "' not allowed"); } // Adjust location URI HttpHost target = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST); if (target == null) { throw new IllegalStateException("Target host not available " + "in the HTTP context"); } HttpRequest request = (HttpRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST); try { URI requestURI = new URI(request.getRequestLine().getUri()); URI absoluteRequestURI = URIUtils.rewriteURI(requestURI, target, true); uri = URIUtils.resolve(absoluteRequestURI, uri); } catch (URISyntaxException ex) { throw new ProtocolException(ex.getMessage(), ex); } } if (params.isParameterFalse(ClientPNames.ALLOW_CIRCULAR_REDIRECTS)) { RedirectLocations redirectLocations = (RedirectLocations) context.getAttribute(REDIRECT_LOCATIONS); if (redirectLocations == null) { redirectLocations = new RedirectLocations(); context.setAttribute(REDIRECT_LOCATIONS, redirectLocations); } URI redirectURI; if (uri.getFragment() != null) { try { HttpHost target = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); redirectURI = URIUtils.rewriteURI(uri, target, true); } catch (URISyntaxException ex) { throw new ProtocolException(ex.getMessage(), ex); } } else { redirectURI = uri; } if (redirectLocations.contains(redirectURI)) { throw new CircularRedirectException("Circular redirect to '" + redirectURI + "'"); } else { redirectLocations.add(redirectURI); } } return uri; }
From source file:org.apache.hadoop.mapred.JobClient.java
private URI getPathURI(Path destPath, String fragment) throws URISyntaxException { URI pathURI = destPath.toUri(); if (pathURI.getFragment() == null) { if (fragment == null) { pathURI = new URI(pathURI.toString() + "#" + destPath.getName()); } else {// w w w . j a v a2 s . c om pathURI = new URI(pathURI.toString() + "#" + fragment); } } return pathURI; }
From source file:org.codice.ddf.catalog.content.impl.FileSystemStorageProvider.java
private ContentItem readContent(URI uri) throws StorageException { Path file = getContentFilePath(uri); if (file == null) { throw new StorageException("Unable to find file for content ID: " + uri.getSchemeSpecificPart()); }//from w w w .jav a 2 s.co m String extension = FilenameUtils.getExtension(file.getFileName().toString()); String mimeType; try (InputStream fileInputStream = Files.newInputStream(file)) { mimeType = mimeTypeMapper.guessMimeType(fileInputStream, extension); } catch (Exception e) { LOGGER.warn("Could not determine mime type for file extension = {}; defaulting to {}", extension, DEFAULT_MIME_TYPE); mimeType = DEFAULT_MIME_TYPE; } if (mimeType == null || DEFAULT_MIME_TYPE.equals(mimeType)) { try { mimeType = Files.probeContentType(file); } catch (IOException e) { LOGGER.warn("Unable to determine mime type using Java Files service.", e); mimeType = DEFAULT_MIME_TYPE; } } LOGGER.debug("mimeType = {}", mimeType); long size = 0; try { size = Files.size(file); } catch (IOException e) { LOGGER.warn("Unable to retrieve size of file: {}", file.toAbsolutePath().toString(), e); } return new ContentItemImpl(uri.getSchemeSpecificPart(), uri.getFragment(), com.google.common.io.Files.asByteSource(file.toFile()), mimeType, file.getFileName().toString(), size, null); }
From source file:com.amytech.android.library.utils.asynchttp.MyRedirectHandler.java
@Override public URI getLocationURI(final HttpResponse response, final HttpContext context) throws ProtocolException { if (response == null) { throw new IllegalArgumentException("HTTP response may not be null"); }/*from w w w . j a va 2s . c o m*/ // get the location header to find out where to redirect to Header locationHeader = response.getFirstHeader("location"); if (locationHeader == null) { // got a redirect response, but no location header throw new ProtocolException( "Received redirect response " + response.getStatusLine() + " but no location header"); } // HERE IS THE MODIFIED LINE OF CODE String location = locationHeader.getValue().replaceAll(" ", "%20"); URI uri; try { uri = new URI(location); } catch (URISyntaxException ex) { throw new ProtocolException("Invalid redirect URI: " + location, ex); } HttpParams params = response.getParams(); // rfc2616 demands the location value be a complete URI // Location = "Location" ":" absoluteURI if (!uri.isAbsolute()) { if (params.isParameterTrue(ClientPNames.REJECT_RELATIVE_REDIRECT)) { throw new ProtocolException("Relative redirect location '" + uri + "' not allowed"); } // Adjust location URI HttpHost target = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST); if (target == null) { throw new IllegalStateException("Target host not available " + "in the HTTP context"); } HttpRequest request = (HttpRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST); try { URI requestURI = new URI(request.getRequestLine().getUri()); URI absoluteRequestURI = URIUtils.rewriteURI(requestURI, target, true); uri = URIUtils.resolve(absoluteRequestURI, uri); } catch (URISyntaxException ex) { throw new ProtocolException(ex.getMessage(), ex); } } if (params.isParameterFalse(ClientPNames.ALLOW_CIRCULAR_REDIRECTS)) { RedirectLocations redirectLocations = (RedirectLocations) context.getAttribute(REDIRECT_LOCATIONS); if (redirectLocations == null) { redirectLocations = new RedirectLocations(); context.setAttribute(REDIRECT_LOCATIONS, redirectLocations); } URI redirectURI; if (uri.getFragment() != null) { try { HttpHost target = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); redirectURI = URIUtils.rewriteURI(uri, target, true); } catch (URISyntaxException ex) { throw new ProtocolException(ex.getMessage(), ex); } } else { redirectURI = uri; } if (redirectLocations.contains(redirectURI)) { throw new CircularRedirectException("Circular redirect to '" + redirectURI + "'"); } else { redirectLocations.add(redirectURI); } } return uri; }
From source file:cn.com.loopj.android.http.MyRedirectHandler.java
@Override public URI getLocationURI(final HttpResponse response, final HttpContext context) throws ProtocolException { if (response == null) { throw new IllegalArgumentException("HTTP response may not be null"); }/*from w w w . j a v a 2 s . co m*/ //get the location header to find out where to redirect to Header locationHeader = response.getFirstHeader("location"); if (locationHeader == null) { // got a redirect response, but no location header throw new ProtocolException( "Received redirect response " + response.getStatusLine() + " but no location header"); } //HERE IS THE MODIFIED LINE OF CODE String location = locationHeader.getValue().replaceAll(" ", "%20"); URI uri; try { uri = new URI(location); } catch (URISyntaxException ex) { throw new ProtocolException("Invalid redirect URI: " + location, ex); } HttpParams params = response.getParams(); // rfc2616 demands the location value be a complete URI // Location = "Location" ":" absoluteURI if (!uri.isAbsolute()) { if (params.isParameterTrue(ClientPNames.REJECT_RELATIVE_REDIRECT)) { throw new ProtocolException("Relative redirect location '" + uri + "' not allowed"); } // Adjust location URI HttpHost target = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST); if (target == null) { throw new IllegalStateException("Target host not available " + "in the HTTP context"); } HttpRequest request = (HttpRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST); try { URI requestURI = new URI(request.getRequestLine().getUri()); URI absoluteRequestURI = URIUtils.rewriteURI(requestURI, target, true); uri = URIUtils.resolve(absoluteRequestURI, uri); } catch (URISyntaxException ex) { throw new ProtocolException(ex.getMessage(), ex); } } if (params.isParameterFalse(ClientPNames.ALLOW_CIRCULAR_REDIRECTS)) { RedirectLocations redirectLocations = (RedirectLocations) context.getAttribute(REDIRECT_LOCATIONS); if (redirectLocations == null) { redirectLocations = new RedirectLocations(); context.setAttribute(REDIRECT_LOCATIONS, redirectLocations); } URI redirectURI; if (uri.getFragment() != null) { try { HttpHost target = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); redirectURI = URIUtils.rewriteURI(uri, target, true); } catch (URISyntaxException ex) { throw new ProtocolException(ex.getMessage(), ex); } } else { redirectURI = uri; } if (redirectLocations.contains(redirectURI)) { throw new CircularRedirectException("Circular redirect to '" + redirectURI + "'"); } else { redirectLocations.add(redirectURI); } } return uri; }
From source file:com.bincode.util.DefaultRedirectHandler.java
public URI getLocationURI(final HttpResponse response, final HttpContext context) throws ProtocolException { if (response == null) { throw new IllegalArgumentException("HTTP response may not be null"); }// w w w . j a va 2 s . co m //get the location header to find out where to redirect to Header locationHeader = response.getFirstHeader("location"); if (locationHeader == null) { // got a redirect response, but no location header throw new ProtocolException( "Received redirect response " + response.getStatusLine() + " but no location header"); } String location = locationHeader.getValue(); if (this.log.isDebugEnabled()) { this.log.debug("Redirect requested to location '" + location + "'"); } URI uri; try { uri = new URI(location); } catch (URISyntaxException ex) { throw new ProtocolException("Invalid redirect URI: " + location, ex); } HttpParams params = response.getParams(); // rfc2616 demands the location value be a complete URI // Location = "Location" ":" absoluteURI if (!uri.isAbsolute()) { if (params.isParameterTrue(ClientPNames.REJECT_RELATIVE_REDIRECT)) { throw new ProtocolException("Relative redirect location '" + uri + "' not allowed"); } // Adjust location URI HttpHost target = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST); if (target == null) { throw new IllegalStateException("Target host not available " + "in the HTTP context"); } HttpRequest request = (HttpRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST); try { URI requestURI = new URI(request.getRequestLine().getUri()); URI absoluteRequestURI = URIUtils.rewriteURI(requestURI, target, true); uri = URIUtils.resolve(absoluteRequestURI, uri); } catch (URISyntaxException ex) { throw new ProtocolException(ex.getMessage(), ex); } } if (params.isParameterFalse(ClientPNames.ALLOW_CIRCULAR_REDIRECTS)) { RedirectLocations redirectLocations = (RedirectLocations) context.getAttribute(REDIRECT_LOCATIONS); if (redirectLocations == null) { redirectLocations = new RedirectLocations(); context.setAttribute(REDIRECT_LOCATIONS, redirectLocations); } URI redirectURI; if (uri.getFragment() != null) { try { HttpHost target = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); redirectURI = URIUtils.rewriteURI(uri, target, true); } catch (URISyntaxException ex) { throw new ProtocolException(ex.getMessage(), ex); } } else { redirectURI = uri; } if (redirectLocations.contains(redirectURI)) { throw new CircularRedirectException("Circular redirect to '" + redirectURI + "'"); } else { redirectLocations.add(redirectURI); } } return uri; }
From source file:org.apache.nifi.web.api.VersionsResource.java
private String lockVersionControl(final URI originalUri, final String groupId) throws URISyntaxException { final URI createRequestUri = new URI(originalUri.getScheme(), originalUri.getUserInfo(), originalUri.getHost(), originalUri.getPort(), "/nifi-api/versions/active-requests", null, originalUri.getFragment()); final NodeResponse clusterResponse; try {//from www .j a v a2 s .c om // create an active request entity to indicate the group id final CreateActiveRequestEntity activeRequestEntity = new CreateActiveRequestEntity(); activeRequestEntity.setProcessGroupId(groupId); final Map<String, String> headers = new HashMap<>(); headers.put("content-type", MediaType.APPLICATION_JSON); if (getReplicationTarget() == ReplicationTarget.CLUSTER_NODES) { clusterResponse = getRequestReplicator() .replicate(HttpMethod.POST, createRequestUri, activeRequestEntity, headers) .awaitMergedResponse(); } else { clusterResponse = getRequestReplicator().forwardToCoordinator(getClusterCoordinatorNode(), HttpMethod.POST, createRequestUri, activeRequestEntity, headers).awaitMergedResponse(); } } catch (final InterruptedException ie) { Thread.currentThread().interrupt(); throw new RuntimeException( "Interrupted while updating Version Control Information for Process Group with ID " + groupId + ".", ie); } if (clusterResponse.getStatus() != Status.OK.getStatusCode()) { final String errorResponse = getResponseEntity(clusterResponse, String.class); throw new IllegalStateException( "Failed to create a Version Control Request across all nodes in the cluster. Received response code " + clusterResponse.getStatus() + " with content: " + errorResponse); } final String requestId = getResponseEntity(clusterResponse, String.class); return requestId; }
From source file:org.soyatec.windowsazure.internal.util.HttpUtilities.java
/** * Create a request URI./* w w w. j a v a 2s . co m*/ * * @param baseUri * @param usePathStyleUris * @param accountName * @param containerName * @param blobName * @param timeout * @param queryParameters * @param uriComponents * @param appendQuery * @return URI */ public static URI createRequestUri(URI baseUri, boolean usePathStyleUris, String accountName, String containerName, String blobName, TimeSpan timeout, NameValueCollection queryParameters, ResourceUriComponents uriComponents, String appendQuery) { URI uri = HttpRequestAccessor.constructResourceUri(baseUri, uriComponents, usePathStyleUris); if (queryParameters != null) { if (queryParameters.get(QueryParams.QueryParamTimeout) == null && timeout != null) { queryParameters.put(QueryParams.QueryParamTimeout, timeout.toSeconds()); } StringBuilder sb = new StringBuilder(); boolean firstParam = true; boolean appendBlockAtTail = false; for (Object key : queryParameters.keySet()) { String queryKey = (String) key; if (queryKey.equalsIgnoreCase(QueryParams.QueryParamBlockId)) { appendBlockAtTail = true; continue; } if (!firstParam) { sb.append("&"); } sb.append(Utilities.encode(queryKey)); sb.append('='); sb.append(Utilities.encode(queryParameters.getSingleValue(queryKey))); firstParam = false; } /* * You shuold add blockid as the last query parameters for put block * request, or an exception you will get. */ if (appendBlockAtTail) { String queryKey = QueryParams.QueryParamBlockId; sb.append("&"); sb.append(Utilities.encode(queryKey)); sb.append('='); sb.append(Utilities.encode(queryParameters.getSingleValue(queryKey))); } if (!Utilities.isNullOrEmpty(appendQuery)) { if (sb.length() > 0) { sb.append("&"); } // @NOTE: escape char sb.append(appendQuery.replaceAll(" ", "%20")); } if (sb.length() > 0) { try { String p = getNormalizePath(uri).replaceAll(" ", "%20"); return URIUtils.createURI(uri.getScheme(), uri.getHost(), uri.getPort(), p, (uri.getQuery() == null ? Utilities.emptyString() : uri.getQuery()) + sb.toString(), uri.getFragment()); } catch (URISyntaxException e) { Logger.error("", e); } } return uri; } else { return uri; } }