Java Code Examples for org.apache.commons.httpclient.URIException

The following are top voted examples for showing how to use org.apache.commons.httpclient.URIException. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: alfresco-repository   File: SolrQueryHTTPClient.java   View source code 6 votes vote down vote up
protected JSONResult postSolrQuery(HttpClient httpClient, String url, JSONObject body, SolrJsonProcessor<?> jsonProcessor, String spellCheckParams)
            throws UnsupportedEncodingException, IOException, HttpException, URIException,
            JSONException
{
    JSONObject json = postQuery(httpClient, url, body);
    if (spellCheckParams != null)
    {
        SpellCheckDecisionManager manager = new SpellCheckDecisionManager(json, url, body, spellCheckParams);
        if (manager.isCollate())
        {
            json = postQuery(httpClient, manager.getUrl(), body);
        }
        json.put("spellcheck", manager.getSpellCheckJsonValue());
    }

        JSONResult results = jsonProcessor.getResult(json);

        if (s_logger.isDebugEnabled())
        {
            s_logger.debug("Sent :" + url);
            s_logger.debug("   with: " + body.toString());
            s_logger.debug("Got: " + results.getNumberFound() + " in " + results.getQueryTime() + " ms");
        }
        
        return results;
}
 
Example 2
Project: dlface   File: MethodBuilder.java   View source code 6 votes vote down vote up
/**
 * Returns result POST method.<br/>
 * Result POST method is composed by baseURL + action (if baseURL is not null).<br/>
 * All parameters are set and encoded.
 * At least one of the parameter has to be not null and the string has to start with 'http'.
 *
 * @return new instance of HttpMethod with POST request
 * @throws BuildMethodException if something goes wrong
 */
public HttpMethod toPostMethod() throws BuildMethodException {
    if (referer != null)
        client.setReferer(referer);
    String s = generateURL();
    if (encodePathAndQuery)
        try {
            s = URIUtil.encodePathQuery(s, encoding);
        } catch (URIException e) {
            throw new BuildMethodException("Cannot create URI");
        }
    s = checkURI(s);
    final PostMethod postMethod = client.getPostMethod(s);
    for (Map.Entry<String, String> entry : parameters.entrySet()) {
        postMethod.addParameter(entry.getKey(), (encodeParameters) ? encode(entry.getValue()) : entry.getValue());
    }
    setAdditionalHeaders(postMethod);
    return postMethod;
}
 
Example 3
Project: Equella   File: AttachmentResourceServiceImpl.java   View source code 6 votes vote down vote up
@Override
public URI getPackageZipFileUrl(Item item, Attachment attachment)
{
	try
	{
		// Need the_IMS folder, not the _SCORM folder ...?
		String zipFileUrl = institutionService.institutionalise("file/" + item.getItemId() + '/')
			+ FileSystemConstants.IMS_FOLDER + '/'
			+ URIUtil.encodePath(attachment.getUrl(), Charsets.UTF_8.toString());
		return new URI(zipFileUrl);
	}
	catch( URISyntaxException | URIException e )
	{
		throw new RuntimeException(e);
	}
}
 
Example 4
Project: hadoop   File: MockStorageInterface.java   View source code 6 votes vote down vote up
@Override
public CloudBlobContainerWrapper getContainerReference(String name)
    throws URISyntaxException, StorageException {
  String fullUri;
  try {
    fullUri = baseUriString + "/" + URIUtil.encodePath(name);
  } catch (URIException e) {
    throw new RuntimeException("problem encoding fullUri", e);
  }

  MockCloudBlobContainerWrapper container = new MockCloudBlobContainerWrapper(
      fullUri, name);
  // Check if we have a pre-existing container with that name, and prime
  // the wrapper with that knowledge if it's found.
  for (PreExistingContainer existing : preExistingContainers) {
    if (fullUri.equalsIgnoreCase(existing.containerUri)) {
      // We have a pre-existing container. Mark the wrapper as created and
      // make sure we use the metadata for it.
      container.created = true;
      backingStore.setContainerMetadata(existing.containerMetadata);
      break;
    }
  }
  return container;
}
 
Example 5
Project: hadoop   File: MockStorageInterface.java   View source code 6 votes vote down vote up
private String fullUriString(String relativePath, boolean withTrailingSlash) {
  String fullUri;

  String baseUri = this.baseUri;
  if (!baseUri.endsWith("/")) {
    baseUri += "/";
  }
  if (withTrailingSlash && !relativePath.equals("")
      && !relativePath.endsWith("/")) {
    relativePath += "/";
  }

  try {
    fullUri = baseUri + URIUtil.encodePath(relativePath);
  } catch (URIException e) {
    throw new RuntimeException("problem encoding fullUri", e);
  }

  return fullUri;
}
 
Example 6
Project: hadoop   File: ServletUtil.java   View source code 6 votes vote down vote up
/**
 * Parse and decode the path component from the given request.
 * @param request Http request to parse
 * @param servletName the name of servlet that precedes the path
 * @return decoded path component, null if UTF-8 is not supported
 */
public static String getDecodedPath(final HttpServletRequest request, String servletName) {
  try {
    return URIUtil.decode(getRawPath(request, servletName), "UTF-8");
  } catch (URIException e) {
    throw new AssertionError("JVM does not support UTF-8"); // should never happen!
  }
}
 
Example 7
Project: aliyun-oss-hadoop-fs   File: MockStorageInterface.java   View source code 6 votes vote down vote up
@Override
public CloudBlobContainerWrapper getContainerReference(String name)
    throws URISyntaxException, StorageException {
  String fullUri;
  try {
    fullUri = baseUriString + "/" + URIUtil.encodePath(name);
  } catch (URIException e) {
    throw new RuntimeException("problem encoding fullUri", e);
  }

  MockCloudBlobContainerWrapper container = new MockCloudBlobContainerWrapper(
      fullUri, name);
  // Check if we have a pre-existing container with that name, and prime
  // the wrapper with that knowledge if it's found.
  for (PreExistingContainer existing : preExistingContainers) {
    if (fullUri.equalsIgnoreCase(existing.containerUri)) {
      // We have a pre-existing container. Mark the wrapper as created and
      // make sure we use the metadata for it.
      container.created = true;
      backingStore.setContainerMetadata(existing.containerMetadata);
      break;
    }
  }
  return container;
}
 
Example 8
Project: aliyun-oss-hadoop-fs   File: MockStorageInterface.java   View source code 6 votes vote down vote up
private String fullUriString(String relativePath, boolean withTrailingSlash) {
  String fullUri;

  String baseUri = this.baseUri;
  if (!baseUri.endsWith("/")) {
    baseUri += "/";
  }
  if (withTrailingSlash && !relativePath.equals("")
      && !relativePath.endsWith("/")) {
    relativePath += "/";
  }

  try {
    fullUri = baseUri + URIUtil.encodePath(relativePath);
  } catch (URIException e) {
    throw new RuntimeException("problem encoding fullUri", e);
  }

  return fullUri;
}
 
Example 9
Project: big-c   File: MockStorageInterface.java   View source code 6 votes vote down vote up
@Override
public CloudBlobContainerWrapper getContainerReference(String name)
    throws URISyntaxException, StorageException {
  String fullUri;
  try {
    fullUri = baseUriString + "/" + URIUtil.encodePath(name);
  } catch (URIException e) {
    throw new RuntimeException("problem encoding fullUri", e);
  }

  MockCloudBlobContainerWrapper container = new MockCloudBlobContainerWrapper(
      fullUri, name);
  // Check if we have a pre-existing container with that name, and prime
  // the wrapper with that knowledge if it's found.
  for (PreExistingContainer existing : preExistingContainers) {
    if (fullUri.equalsIgnoreCase(existing.containerUri)) {
      // We have a pre-existing container. Mark the wrapper as created and
      // make sure we use the metadata for it.
      container.created = true;
      backingStore.setContainerMetadata(existing.containerMetadata);
      break;
    }
  }
  return container;
}
 
Example 10
Project: big-c   File: MockStorageInterface.java   View source code 6 votes vote down vote up
private String fullUriString(String relativePath, boolean withTrailingSlash) {
  String fullUri;

  String baseUri = this.baseUri;
  if (!baseUri.endsWith("/")) {
    baseUri += "/";
  }
  if (withTrailingSlash && !relativePath.equals("")
      && !relativePath.endsWith("/")) {
    relativePath += "/";
  }

  try {
    fullUri = baseUri + URIUtil.encodePath(relativePath);
  } catch (URIException e) {
    throw new RuntimeException("problem encoding fullUri", e);
  }

  return fullUri;
}
 
Example 11
Project: motu   File: HttpClientCAS.java   View source code 6 votes vote down vote up
public static String debugHttpMethod(HttpMethod method) {
    StringBuffer stringBuffer = new StringBuffer();
    stringBuffer.append("\nName:");
    stringBuffer.append(method.getName());
    stringBuffer.append("\n");
    stringBuffer.append("\nPath:");
    stringBuffer.append(method.getPath());
    stringBuffer.append("\n");
    stringBuffer.append("\nQueryString:");
    stringBuffer.append(method.getQueryString());
    stringBuffer.append("\n");
    stringBuffer.append("\nUri:");
    try {
        stringBuffer.append(method.getURI().toString());
    } catch (URIException e) {
        // Do nothing
    }
    stringBuffer.append("\n");
    HttpMethodParams httpMethodParams = method.getParams();
    stringBuffer.append("\nHttpMethodParams:");
    stringBuffer.append(httpMethodParams.toString());

    return stringBuffer.toString();

}
 
Example 12
Project: hadoop-2.6.0-cdh5.4.3   File: MockStorageInterface.java   View source code 6 votes vote down vote up
@Override
public CloudBlobContainerWrapper getContainerReference(String name)
    throws URISyntaxException, StorageException {
  String fullUri;
  try {
    fullUri = baseUriString + "/" + URIUtil.encodePath(name);
  } catch (URIException e) {
    throw new RuntimeException("problem encoding fullUri", e);
  }

  MockCloudBlobContainerWrapper container = new MockCloudBlobContainerWrapper(
      fullUri, name);
  // Check if we have a pre-existing container with that name, and prime
  // the wrapper with that knowledge if it's found.
  for (PreExistingContainer existing : preExistingContainers) {
    if (fullUri.equalsIgnoreCase(existing.containerUri)) {
      // We have a pre-existing container. Mark the wrapper as created and
      // make sure we use the metadata for it.
      container.created = true;
      backingStore.setContainerMetadata(existing.containerMetadata);
      break;
    }
  }
  return container;
}
 
Example 13
Project: hadoop-2.6.0-cdh5.4.3   File: MockStorageInterface.java   View source code 6 votes vote down vote up
private String fullUriString(String relativePath, boolean withTrailingSlash) {
  String fullUri;

  String baseUri = this.baseUri;
  if (!baseUri.endsWith("/")) {
    baseUri += "/";
  }
  if (withTrailingSlash && !relativePath.equals("")
      && !relativePath.endsWith("/")) {
    relativePath += "/";
  }

  try {
    fullUri = baseUri + URIUtil.encodePath(relativePath);
  } catch (URIException e) {
    throw new RuntimeException("problem encoding fullUri", e);
  }

  return fullUri;
}
 
Example 14
Project: openhab-hdl   File: SystemsRequest.java   View source code 6 votes vote down vote up
public String prepare() {
	final StringBuilder urlBuilder = new StringBuilder(RESOURCE_URL);
	urlBuilder.append("/");
	urlBuilder.append(this.system_id);
	urlBuilder.append("/summary");
	urlBuilder.append("?key=");
	urlBuilder.append(this.key);
	urlBuilder.append("&user_id=");
	urlBuilder.append(this.user_id);

	try {
		return encodeQuery(urlBuilder.toString());
	} catch (final URIException e) {
		throw new EnphaseenergyException("Could not prepare systems request!", e);
	}
}
 
Example 15
Project: openhab-hdl   File: MeasurementRequest.java   View source code 6 votes vote down vote up
private String buildQueryString() {
	final StringBuilder urlBuilder = new StringBuilder(RESOURCE_URL);
	urlBuilder.append("?access_token=");
	urlBuilder.append(this.accessToken);
	urlBuilder.append("&scale=max");
	urlBuilder.append("&date_end=last");
	urlBuilder.append("&device_id=");
	urlBuilder.append(this.deviceId);
	if (this.moduleId != null) {
		urlBuilder.append("&module_id=");
		urlBuilder.append(this.moduleId);
	}
	urlBuilder.append("&type=");
	for (final Iterator<String> i = this.measures.iterator(); i.hasNext();) {
		urlBuilder.append(i.next());
		if (i.hasNext()) {
			urlBuilder.append(",");
		}
	}

	try {
		return URIUtil.encodeQuery(urlBuilder.toString());
	} catch (final URIException e) {
		throw new NetatmoException(e);
	}
}
 
Example 16
Project: imis-iot-eventing-process   File: KvpSosClient.java   View source code 6 votes vote down vote up
/**
 * Creates the request URL for the specified time span.
 *
 * @param begin the exclusive lower bound of the time span
 * @param end   the exclusive upper bound of the time span
 *
 * @return the request URL
 *
 * @throws MalformedURLException if the URL generation fails
 * @throws URIException          if the URL generation fails
 */
private URL createRequest(DateTime begin, DateTime end)
        throws MalformedURLException, URIException {
    Objects.requireNonNull(begin);
    Objects.requireNonNull(end);
    StringBuilder builder = new StringBuilder();
    builder.append(this.requestTemplate.toString());
    builder.append("&namespaces=").append(URIUtil.encodeQuery("xmlns(om,http://www.opengis.net/om/2.0)"));
    builder.append("&temporalFilter=");
    String temporalFilter = "om:phenomenonTime," +
                            ISODateTimeFormat.dateTime().print(begin) +
                            "/" +
                            ISODateTimeFormat.dateTime().print(end);
    builder.append(URIUtil.encodeQuery(temporalFilter));
    URL url = new URL(builder.toString());
    return url;
}
 
Example 17
Project: GRIP   File: HttpSourceTest.java   View source code 6 votes vote down vote up
@Before
public void setUp() throws URIException, URISyntaxException {
  GripServer.JettyServerFactory f = new GripServerTest.TestServerFactory();
  ContextStore contextStore = new ContextStore();
  server = GripServerTest.makeServer(contextStore, f, new Pipeline());
  server.start();
  EventBus eventBus = new EventBus();
  OutputSocket.Factory osf = new MockOutputSocketFactory(eventBus);
  source = new HttpSource(
      origin -> new MockExceptionWitness(eventBus, origin),
      eventBus,
      osf,
      server,
      contextStore,
      GripServer.IMAGE_UPLOAD_PATH);

  logoFile = new File(Files.class.getResource("/edu/wpi/grip/images/GRIP_Logo.png").toURI());
  postClient = HttpClients.createDefault();
}
 
Example 18
Project: converge-1.x   File: MediaItemRendition.java   View source code 6 votes vote down vote up
/**
 * Gets the absolute URL of the {@link MediaItem}. This is
 * dynamically calculated based on the {@link MediaRepository} associated
 * with the {@link MediaItem}.
 *
 * @return Absolute URL of the {@link MediaItem}
 */
public String getAbsoluteFilename() {
    if (mediaItem == null || mediaItem.getCatalogue() == null
            || getFilename() == null) {
        return "#";
    }

    StringBuilder absoluteFilename = new StringBuilder(mediaItem.
            getCatalogue().getWebAccess());
    absoluteFilename.append("/");
    if (!StringUtils.isBlank(getPath())) {
        absoluteFilename.append(FilenameUtils.separatorsToUnix(getPath()));
        absoluteFilename.append("/");
    }

    if (!StringUtils.isBlank(getFilename())) {
        try {
            absoluteFilename.append(URIUtil.encodePath(getFilename(),
                    "UTF-8"));
        } catch (URIException ex) {
            absoluteFilename.append(getFilename());
        }
    }

    return absoluteFilename.toString();
}
 
Example 19
Project: community-edition-old   File: SolrQueryHTTPClient.java   View source code 6 votes vote down vote up
protected JSONResult postSolrQuery(HttpClient httpClient, String url, JSONObject body, SolrJsonProcessor<?> jsonProcessor, String spellCheckParams)
            throws UnsupportedEncodingException, IOException, HttpException, URIException,
            JSONException
{
    JSONObject json = postQuery(httpClient, url, body);
    if (spellCheckParams != null)
    {
        SpellCheckDecisionManager manager = new SpellCheckDecisionManager(json, url, body, spellCheckParams);
        if (manager.isCollate())
        {
            json = postQuery(httpClient, manager.getUrl(), body);
        }
        json.put("spellcheck", manager.getSpellCheckJsonValue());
    }

        JSONResult results = jsonProcessor.getResult(json);

        if (s_logger.isDebugEnabled())
        {
            s_logger.debug("Sent :" + url);
            s_logger.debug("   with: " + body.toString());
            s_logger.debug("Got: " + results.getNumberFound() + " in " + results.getQueryTime() + " ms");
        }
        
        return results;
}
 
Example 20
Project: netarchivesuite-svngit-migration   File: NetarchiveSuiteUURIFactory.java   View source code 6 votes vote down vote up
/**
 * If http(s) scheme, check scheme specific part begins '//'.
 * @throws URIException
 * @see <A href="http://www.faqs.org/rfcs/rfc1738.html">Section 3.1. 
 * Common Internet Scheme Syntax</A>
 */
protected void checkHttpSchemeSpecificPartSlashPrefix(final URI base,
        final String scheme, final String schemeSpecificPart)
        throws URIException {
    if (scheme == null || scheme.length() <= 0) {
        return;
    }
    if (!scheme.equals("http") && !scheme.equals("https")) {
        return;
    }
    if (schemeSpecificPart == null 
            || !schemeSpecificPart.startsWith("//")) {
        // only acceptable if schemes match
        if (base == null || !scheme.equals(base.getScheme())) {
            throw new URIException(
                    "relative URI with scheme only allowed for "
                            + "scheme matching base");
        }
        return;
    }
    if (schemeSpecificPart.length() <= 2) {
        throw new URIException("http scheme specific part is "
                + "too short: " + schemeSpecificPart);
    }
}
 
Example 21
Project: reviki   File: Escape.java   View source code 6 votes vote down vote up
/**
 * Generate a correctly encoded URI string from the given components.
 * 
 * @param path The unencoded path. Will be encoded according to RFC3986.
 * @param query The unencoded query. May be null. Will be x-www-form-urlencoded.
 * @param fragment The unencoded fragment. May be null. Will be encoded according to RFC3986.
 * @param extraPath The <strong>encoded</strong> extra part to append to the path.
 * @return
 */
public static String constructEncodedURI(final String path, final String query, final String fragment, final String extraPath) {
  try {
    StringBuilder sb = new StringBuilder();
    sb.append(URIUtil.encodeWithinPath(path, "UTF-8"));
    if (extraPath != null) {
      sb.append(extraPath);
    }
    if (query != null) {
      sb.append("?");
      sb.append(URIUtil.encodeQuery(query, "UTF-8"));
    }
    if (fragment != null) {
      sb.append("#");
      sb.append(URIUtil.encodeWithinPath(fragment, "UTF-8"));
    }
    return sb.toString();
  }
  catch(URIException ex) {
    throw new Error("Java supports UTF-8!", ex);
  }
}
 
Example 22
Project: reviki   File: WikiUrlsImpl.java   View source code 6 votes vote down vote up
public String pagesRoot(final String wikiName) {
  final String givenWikiName = wikiName == null ? _wiki.getWikiName() : wikiName;
  
  String fixedBaseUrl = _wiki.getFixedBaseUrl(givenWikiName);
  if (fixedBaseUrl != null) {
   if (!fixedBaseUrl.endsWith("/")) {
     fixedBaseUrl += "/";
   }
   return fixedBaseUrl;
  }

  String relative = "/pages/";
  if (givenWikiName != null) {
    try {
      relative += URIUtil.encodeWithinPath(givenWikiName) + "/";
    }
    catch (URIException e) {
      throw new RuntimeException(e);
    }
  }
  return _applicationUrls.url(relative);
}
 
Example 23
Project: pinpoint   File: HttpMethodBaseExecuteMethodInterceptor.java   View source code 6 votes vote down vote up
private String getHost(HttpMethod httpMethod, Object[] args) {
    try {
        final URI url = httpMethod.getURI();
        if (url.isAbsoluteURI()) {
            return getEndpoint(url.getHost(), url.getPort());
        }

        if (isDebug) {
            logger.debug("URI is not absolute. {}", url.getURI());
        }

        // if not found schema, use httpConnection.
        final HttpConnection httpConnection = getHttpConnection(args);
        if (httpConnection != null) {
            final String host = httpConnection.getHost();
            final int port = getPort(httpConnection);
            return getEndpoint(host, port);
        }
    } catch (URIException e) {
        // unexpected error, perhaps of user fault.
        logger.error("[HttpClient3] Fail get URI", e);
    }

    return null;
}
 
Example 24
Project: pinpoint   File: HttpMethodBaseExecuteMethodInterceptor.java   View source code 6 votes vote down vote up
private String getHttpUrl(String host, int port, URI uri, HttpConnection httpConnection) throws URIException {
    final Protocol protocol = httpConnection.getProtocol();
    if (protocol == null) {
        return uri.getURI();
    }
    final StringBuilder sb = new StringBuilder();
    final String scheme = protocol.getScheme();
    sb.append(scheme).append("://");
    sb.append(host);
    // if port is default port number.
    if (port != SKIP_DEFAULT_PORT) {
        sb.append(':').append(port);
    }
    sb.append(uri.getURI());
    return sb.toString();
}
 
Example 25
Project: airavata   File: JSDLUtils.java   View source code 6 votes vote down vote up
public static void addDataStagingTargetElement(JobDefinitionType value, String fileSystem, String file, String uri, int flags) {
	JobDescriptionType jobDescr = getOrCreateJobDescription(value);
	DataStagingType newDS = jobDescr.addNewDataStaging();
	CreationFlagEnumeration.Enum creationFlag = CreationFlagEnumeration.DONT_OVERWRITE;
	if((flags & FLAG_OVERWRITE) != 0) creationFlag = CreationFlagEnumeration.OVERWRITE;
	if((flags & FLAG_APPEND) != 0) creationFlag = CreationFlagEnumeration.APPEND;
	boolean deleteOnTerminate = (flags & FLAG_DELETE_ON_TERMINATE) != 0;
	newDS.setCreationFlag(creationFlag);
	newDS.setDeleteOnTermination(deleteOnTerminate);
	SourceTargetType target = newDS.addNewTarget();

	try {
		if (uri != null) { 
			URIUtils.encodeAll(uri);
			target.setURI(uri);
		}
	} catch (URIException e) {
	}
	newDS.setFileName(file);
	if (fileSystem != null && !fileSystem.equals("Work")) {  //$NON-NLS-1$
		newDS.setFilesystemName(fileSystem);
	}
}
 
Example 26
Project: airavata   File: JSDLUtils.java   View source code 6 votes vote down vote up
public static void addDataStagingSourceElement(JobDefinitionType value, String uri, String fileSystem, String file, int flags) {
	JobDescriptionType jobDescr = getOrCreateJobDescription(value);

	try {
		uri = (uri == null) ? null : URIUtils.encodeAll(uri);
	} catch (URIException e) {
	}
	DataStagingType newDS = jobDescr.addNewDataStaging();
	CreationFlagEnumeration.Enum creationFlag = CreationFlagEnumeration.DONT_OVERWRITE;
	if((flags & FLAG_OVERWRITE) != 0) creationFlag = CreationFlagEnumeration.OVERWRITE;
	if((flags & FLAG_APPEND) != 0) creationFlag = CreationFlagEnumeration.APPEND;
	boolean deleteOnTerminate = (flags & FLAG_DELETE_ON_TERMINATE) != 0;
	newDS.setCreationFlag(creationFlag);
	newDS.setDeleteOnTermination(deleteOnTerminate);
	SourceTargetType source = newDS.addNewSource();
	source.setURI(uri);
	newDS.setFileName(file);
	if (fileSystem != null && !fileSystem.equals("Work")) {  //$NON-NLS-1$
		newDS.setFilesystemName(fileSystem);
	}
}
 
Example 27
Project: airavata   File: URIUtils.java   View source code 6 votes vote down vote up
public static String encodeAuthority(String uri) throws URIException
{
	int start = uri.indexOf("//");
	if(start == -1) return uri;
	start++;
	int end = uri.indexOf("/",start+1);
	if(end == -1) end = uri.indexOf("?",start+1);
	if(end == -1) end = uri.indexOf("#",start+1);
	if(end == -1) end = uri.length();
	String before = uri.substring(0, start+1);
	String authority= uri.substring(start+1,end);
	String after = uri.substring(end);
	authority = URIUtil.encode(authority, URI.allowed_authority);

	return before+authority+after;
}
 
Example 28
Project: airavata   File: URIUtils.java   View source code 6 votes vote down vote up
public static String encodePath(String uri) throws URIException
{
	int doubleSlashIndex = uri.indexOf("//");
	boolean hasAuthority =  doubleSlashIndex >= 0;
	int start = -1;
	if(hasAuthority)
	{
		start = uri.indexOf("/",doubleSlashIndex+2);
	}
	else
	{
		start = uri.indexOf(":");
	}
	if(start == -1) return uri;
	
	int end = uri.indexOf("?",start+1);
	if(end == -1) end = uri.indexOf("#",start+1);
	if(end == -1) end = uri.length();
	String before = uri.substring(0, start+1);
	String path= uri.substring(start+1,end);
	String after = uri.substring(end);
	path = URIUtil.encode(path, URI.allowed_abs_path);
	return before+path+after;
}
 
Example 29
Project: airavata   File: JSDLUtils.java   View source code 6 votes vote down vote up
public static void addDataStagingTargetElement(JobDefinitionType value, String fileSystem, String file, String uri, int flags) {
	JobDescriptionType jobDescr = getOrCreateJobDescription(value);
	DataStagingType newDS = jobDescr.addNewDataStaging();
	CreationFlagEnumeration.Enum creationFlag = CreationFlagEnumeration.DONT_OVERWRITE;
	if((flags & FLAG_OVERWRITE) != 0) creationFlag = CreationFlagEnumeration.OVERWRITE;
	if((flags & FLAG_APPEND) != 0) creationFlag = CreationFlagEnumeration.APPEND;
	boolean deleteOnTerminate = (flags & FLAG_DELETE_ON_TERMINATE) != 0;
	newDS.setCreationFlag(creationFlag);
	newDS.setDeleteOnTermination(deleteOnTerminate);
	SourceTargetType target = newDS.addNewTarget();

	try {
		if (uri != null) { 
			URIUtils.encodeAll(uri);
			target.setURI(uri);
		}
	} catch (URIException e) {
	}
	newDS.setFileName(file);
	if (fileSystem != null && !fileSystem.equals("Work")) {  //$NON-NLS-1$
		newDS.setFilesystemName(fileSystem);
	}
}
 
Example 30
Project: airavata   File: JSDLUtils.java   View source code 6 votes vote down vote up
public static void addDataStagingSourceElement(JobDefinitionType value, String uri, String fileSystem, String file, int flags) {
	JobDescriptionType jobDescr = getOrCreateJobDescription(value);

	try {
		uri = (uri == null) ? null : URIUtils.encodeAll(uri);
	} catch (URIException e) {
	}
	DataStagingType newDS = jobDescr.addNewDataStaging();
	CreationFlagEnumeration.Enum creationFlag = CreationFlagEnumeration.DONT_OVERWRITE;
	if((flags & FLAG_OVERWRITE) != 0) creationFlag = CreationFlagEnumeration.OVERWRITE;
	if((flags & FLAG_APPEND) != 0) creationFlag = CreationFlagEnumeration.APPEND;
	boolean deleteOnTerminate = (flags & FLAG_DELETE_ON_TERMINATE) != 0;
	newDS.setCreationFlag(creationFlag);
	newDS.setDeleteOnTermination(deleteOnTerminate);
	SourceTargetType source = newDS.addNewSource();
	source.setURI(uri);
	newDS.setFileName(file);
	if (fileSystem != null && !fileSystem.equals("Work")) {  //$NON-NLS-1$
		newDS.setFilesystemName(fileSystem);
	}
}
 
Example 31
Project: airavata   File: URIUtils.java   View source code 6 votes vote down vote up
public static String encodeAuthority(String uri) throws URIException
{
	int start = uri.indexOf("//");
	if(start == -1) return uri;
	start++;
	int end = uri.indexOf("/",start+1);
	if(end == -1) end = uri.indexOf("?",start+1);
	if(end == -1) end = uri.indexOf("#",start+1);
	if(end == -1) end = uri.length();
	String before = uri.substring(0, start+1);
	String authority= uri.substring(start+1,end);
	String after = uri.substring(end);
	authority = URIUtil.encode(authority, URI.allowed_authority);

	return before+authority+after;
}
 
Example 32
Project: airavata   File: URIUtils.java   View source code 6 votes vote down vote up
public static String encodePath(String uri) throws URIException
{
	int doubleSlashIndex = uri.indexOf("//");
	boolean hasAuthority =  doubleSlashIndex >= 0;
	int start = -1;
	if(hasAuthority)
	{
		start = uri.indexOf("/",doubleSlashIndex+2);
	}
	else
	{
		start = uri.indexOf(":");
	}
	if(start == -1) return uri;
	
	int end = uri.indexOf("?",start+1);
	if(end == -1) end = uri.indexOf("#",start+1);
	if(end == -1) end = uri.length();
	String before = uri.substring(0, start+1);
	String path= uri.substring(start+1,end);
	String after = uri.substring(end);
	path = URIUtil.encode(path, URI.allowed_abs_path);
	return before+path+after;
}
 
Example 33
Project: DotCi   File: HttpPoster.java   View source code 6 votes vote down vote up
private HttpHost getProxy(HttpUriRequest method) throws URIException {

        ProxyConfiguration proxy = Jenkins.getInstance().proxy;
        if (proxy == null) return null;

        Proxy p = proxy.createProxy(method.getURI().getHost());
        switch (p.type()) {
            case DIRECT:
                return null;
            case HTTP:
                InetSocketAddress sa = (InetSocketAddress) p.address();
                return new HttpHost(sa.getHostName(), sa.getPort());
            case SOCKS:
            default:
                return null;
        }
    }
 
Example 34
Project: webarchive-commons   File: UsableURITest.java   View source code 6 votes vote down vote up
/**
 * Test of toUnicodeHostString method, of class UsableURI.
 */
public void testToUnicodeHostString() throws URIException {
    assertEquals("http://øx.dk", new UsableURI("http://xn--x-4ga.dk", true, "UTF-8").toUnicodeHostString());
    assertEquals("xn--x-4ga.dk", new UsableURI("xn--x-4ga.dk", true, "UTF-8").toUnicodeHostString());
    assertEquals("http://user:[email protected]øx.dk:8080", new UsableURI("http://user:[email protected]:8080", true, "UTF-8").toUnicodeHostString());
    assertEquals("http://[email protected]øx.dk:8080", new UsableURI("http://[email protected]:8080", true, "UTF-8").toUnicodeHostString());
    assertEquals("http://øx.dk/foo/bar?query=q", new UsableURI("http://xn--x-4ga.dk/foo/bar?query=q", true, "UTF-8").toUnicodeHostString());
    assertEquals("http://127.0.0.1/foo/bar?query=q", new UsableURI("http://127.0.0.1/foo/bar?query=q", true, "UTF-8").toUnicodeHostString());

    // test idn round trip
    // XXX fails because idn is not handled here (it is converted to punycode in UsableURIFactory.fixupDomainlabel())
    // assertEquals("http://øx.dk", new UsableURI("http://øx.dk", false, "UTF-8").toUnicodeHostString());
    // To check the round trip it is then necessary to use the factory method in UsableURIFactory.
    assertEquals("http://øx.dk/", UsableURIFactory.getInstance("http://øx.dk/", "UTF-8").toUnicodeHostString());

    // non-idn domain name
    assertEquals("http://example.org", new UsableURI("http://example.org", true, "UTF-8").toUnicodeHostString());

    // ensure a call to toUnicodeHostString() has no effect on toString()
    UsableURI uri = new UsableURI("http://xn--x-4ga.dk", true, "UTF-8");
    assertEquals("http://øx.dk", uri.toUnicodeHostString());
    uri.setPath(uri.getPath()); // force toString() cached value to be recomputed
    assertEquals("http://xn--x-4ga.dk", uri.toString());
}
 
Example 35
Project: webarchive-commons   File: SURTTokenizer.java   View source code 6 votes vote down vote up
private static String getKey(String url, boolean prefix)
throws URIException {

	String key = addImpliedHttpIfNecessary(url);
	UsableURI uuri = UsableURIFactory.getInstance(key);
	key = uuri.getScheme() + "://" + uuri.getAuthority() + 
		uuri.getEscapedPathQuery();

	key = SURT.fromURI(key);
	
	int hashPos = key.indexOf('#');
	if(hashPos != -1) {
		key = key.substring(0,hashPos);
	}
	
	if(key.startsWith("http://")) {
		key = key.substring(7);
	}
	if(prefix) {
		if(key.endsWith(",)/")) {
			key = key.substring(0,key.length()-3);
		}
	}
	return key;
}
 
Example 36
Project: webarchive-commons   File: UsableURIFactory.java   View source code 6 votes vote down vote up
/**
 * If http(s) scheme, check scheme specific part begins '//'.
 * @throws URIException 
 * @see http://www.faqs.org/rfcs/rfc1738.html Section 3.1. Common Internet
 * Scheme Syntax
 */
protected void checkHttpSchemeSpecificPartSlashPrefix(final URI base,
        final String scheme, final String schemeSpecificPart)
throws URIException {
    if (scheme == null || scheme.length() <= 0) {
        return;
    }
    if (!scheme.equals("http") && !scheme.equals("https")) {
        return;
    }
    if ( schemeSpecificPart == null 
            || !schemeSpecificPart.startsWith("//")) {
        // only acceptable if schemes match
        if (base == null || !scheme.equals(base.getScheme())) {
            throw new URIException(
                    "relative URI with scheme only allowed for " +
                    "scheme matching base");
        } 
        return; 
    }
    if (schemeSpecificPart.length() <= 2) {
        throw new URIException("http scheme specific part is " +
            "too short: " + schemeSpecificPart);
    }
}
 
Example 37
Project: jakarta-slide-webdavclient   File: ResourceProperties.java   View source code 6 votes vote down vote up
public void storeProperties(PropFindMethod propFind)
   throws URIException
{
   // for each content element, check resource type and classify
   for (Enumeration e = propFind.getAllResponseURLs(); e.hasMoreElements(); ) 
   {
      String href = (String) e.nextElement();
      URI uri = new URI(propFind.getURI(), href);
      
      String key = uri.toString();
      List properties = (List)this.resourceMap.get(key);
      if (properties == null) {
         properties = new ArrayList();
         this.resourceMap.put(key, properties);
      }
      for(Enumeration f = propFind.getResponseProperties(href); 
          f.hasMoreElements();) 
      {
         properties.add((Property)f.nextElement());
      }
   }
}
 
Example 38
Project: webarchive-commons   File: SURT.java   View source code 6 votes vote down vote up
public static String toSURT(String input) {
		if(input.startsWith("(")) {
			return input;
		}
		try {
//			String tmp = input;
//			if(tmp == null) {
//				throw new URIException();
//			}
			String tmp = SURTTokenizer.prefixKey(input);
			if(tmp.contains("/")) {
				return tmp;
			}
			return tmp + ",";
		} catch (URIException e) {
			LOG.warning("URI Exception for(" + input + "):" + e.getLocalizedMessage());
//			e.printStackTrace();
			return input;
		}
	}
 
Example 39
Project: webarchive-commons   File: UsableURIFactoryTest.java   View source code 6 votes vote down vote up
public final void testTooLongAfterEscaping() {
    StringBuffer buffer = new StringBuffer("http://www.archive.org/a/");
    // Append bunch of spaces.  When escaped, they'll triple in size.
    for (int i = 0; i < 1024; i++) {
    	buffer.append(" ");
    }
    buffer.append("/index.html");
    String message = null;
    try {
    	UsableURIFactory.getInstance(buffer.toString());
    } catch (URIException e) {
        message = e.getMessage();
    }
    assertTrue("Wrong or no exception: " + message, (message != null) &&
        message.startsWith("Created (escaped) uuri >"));
}
 
Example 40
Project: Tanaguru   File: CrawlConfigurationUtils.java   View source code 6 votes vote down vote up
/**
 * 
 * @param document
 * @param parameters
 * @param urlList
 * @return
 * @throws URIException 
 */
public Document setUpDocument(
        Document document, 
        Set<Parameter> parameters, 
        Collection<String> urlList) throws URIException {
    document = modifyValue(
            getUrlModifier(), 
            document, 
            getUrlListAsUniqueString(urlList), 
            "");
    for (Parameter parameter : parameters) {
        document = modifyHeritrixParameter(document, parameter, urlList.iterator().next());
    }
    if (HttpRequestHandler.getInstance().isProxySet(urlList.iterator().next())) {
        for (HeritrixConfigurationModifier hcm : proxyModifierList) {
            // to respect the hcm interface, the method is called with 3 parameters
            // but the last 2 parameters are ignored (so set as empty strings). 
            // The modifier is already set  with the proxy parameters set 
            // by spring configuration on startup
            document = hcm.modifyDocument(document, "", "");
        }
    }
    return document;
}