本文整理汇总了Java中org.apache.commons.httpclient.URI类的典型用法代码示例。如果您正苦于以下问题:Java URI类的具体用法?Java URI怎么用?Java URI使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
URI类属于org.apache.commons.httpclient包,在下文中一共展示了URI类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeURI
import org.apache.commons.httpclient.URI; //导入依赖的package包/类
/**
* Execute a transaction method given a complete URI.
* @param method the transaction method
* @param headers HTTP header values to send
* @param uri a properly urlencoded URI
* @return the HTTP response code
* @throws IOException
*/
public int executeURI(HttpMethod method, Header[] headers, String uri)
throws IOException {
method.setURI(new URI(uri, true));
for (Map.Entry<String, String> e: extraHeaders.entrySet()) {
method.addRequestHeader(e.getKey(), e.getValue());
}
if (headers != null) {
for (Header header: headers) {
method.addRequestHeader(header);
}
}
long startTime = System.currentTimeMillis();
int code = httpClient.executeMethod(method);
long endTime = System.currentTimeMillis();
if (LOG.isDebugEnabled()) {
LOG.debug(method.getName() + " " + uri + " " + code + " " +
method.getStatusText() + " in " + (endTime - startTime) + " ms");
}
return code;
}
示例2: executePathOnly
import org.apache.commons.httpclient.URI; //导入依赖的package包/类
/**
* Execute a transaction method given only the path. Will select at random
* one of the members of the supplied cluster definition and iterate through
* the list until a transaction can be successfully completed. The
* definition of success here is a complete HTTP transaction, irrespective
* of result code.
* @param cluster the cluster definition
* @param method the transaction method
* @param headers HTTP header values to send
* @param path the properly urlencoded path
* @return the HTTP response code
* @throws IOException
*/
public int executePathOnly(Cluster cluster, HttpMethod method,
Header[] headers, String path) throws IOException {
IOException lastException;
if (cluster.nodes.size() < 1) {
throw new IOException("Cluster is empty");
}
int start = (int)Math.round((cluster.nodes.size() - 1) * Math.random());
int i = start;
do {
cluster.lastHost = cluster.nodes.get(i);
try {
StringBuilder sb = new StringBuilder();
sb.append("http://");
sb.append(cluster.lastHost);
sb.append(path);
URI uri = new URI(sb.toString(), true);
return executeURI(method, headers, uri.toString());
} catch (IOException e) {
lastException = e;
}
} while (++i != start && i < cluster.nodes.size());
throw lastException;
}
示例3: checkHttpSchemeSpecificPartSlashPrefix
import org.apache.commons.httpclient.URI; //导入依赖的package包/类
/**
* 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);
}
}
开发者ID:netarchivesuite,项目名称:netarchivesuite-svngit-migration,代码行数:31,代码来源:NetarchiveSuiteUURIFactory.java
示例4: executeURI
import org.apache.commons.httpclient.URI; //导入依赖的package包/类
/**
* Execute a transaction method given a complete URI.
* @param method the transaction method
* @param headers HTTP header values to send
* @param uri a properly urlencoded URI
* @return the HTTP response code
* @throws IOException
*/
public int executeURI(HttpMethod method, Header[] headers, String uri)
throws IOException {
method.setURI(new URI(uri, true));
if (headers != null) {
for (Header header: headers) {
method.addRequestHeader(header);
}
}
long startTime = System.currentTimeMillis();
int code = httpClient.executeMethod(method);
long endTime = System.currentTimeMillis();
if (LOG.isDebugEnabled()) {
LOG.debug(method.getName() + " " + uri + " " + code + " " +
method.getStatusText() + " in " + (endTime - startTime) + " ms");
}
return code;
}
示例5: getForObject
import org.apache.commons.httpclient.URI; //导入依赖的package包/类
/**
* Typical web service client class to get a string representation of the
* response.
*
* @param requestUrl
* Relative request URL
* @param mapperClass
* Class to which the response should cast to.
* @return JAXB deserialized response
*/
protected Object getForObject( final String requestUrl, Class< ? > mapperClass, String parameters )
{
Object domainObject = null;
HttpClient client = new HttpClient();
try
{
PostMethod request = new PostMethod();
request.setURI( new URI( getAbsoluteUrl( requestUrl + REQUEST_URL_SUFFIX + parameters ), false ) );
request.addRequestHeader( CONTENT_TYPE, APPLICATION_XML );
String apiToken = jenkinsClientProperties.getJenkinsApiToken();
if ( !apiToken.isEmpty() )
{
request.setDoAuthentication( true );
}
domainObject = sendRequestToJenkins( mapperClass, domainObject, client, request, apiToken );
}
catch ( Exception e )
{
LOGGER.error( e.getMessage() );
}
return domainObject;
}
示例6: performBuildOperationsViaGet
import org.apache.commons.httpclient.URI; //导入依赖的package包/类
/**
* Perform build Operations Via GET
*
* @param requestUrl
* Relative request URL
* @param mapperClass
* Class to which the response should cast to.
* @return JAXB deserialized response
*/
protected Object performBuildOperationsViaGet( final String requestUrl, Class< ? > mapperClass )
{
Object domainObject = null;
HttpClient client = new HttpClient();
try
{
GetMethod request = new GetMethod();
request.setURI( new URI( getAbsoluteUrl( requestUrl ), false ) );
request.addRequestHeader( CONTENT_TYPE, APPLICATION_XML );
String apiToken = jenkinsClientProperties.getJenkinsApiToken();
if ( !apiToken.isEmpty() )
{
request.setDoAuthentication( true );
}
domainObject = sendRequestToJenkins( mapperClass, domainObject, client, request, apiToken );
}
catch ( Exception e )
{
LOGGER.error( e.getMessage() );
}
return domainObject;
}
示例7: getHost
import org.apache.commons.httpclient.URI; //导入依赖的package包/类
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;
}
示例8: getHttpUrl
import org.apache.commons.httpclient.URI; //导入依赖的package包/类
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();
}
示例9: handleCertificateExceptionAndRetry
import org.apache.commons.httpclient.URI; //导入依赖的package包/类
@Nullable
private static HttpMethod handleCertificateExceptionAndRetry(@NotNull IOException e, @NotNull String host,
@NotNull HttpClient client, @NotNull URI uri,
@NotNull ThrowableConvertor<String, HttpMethod, IOException> methodCreator)
throws IOException {
if (!isCertificateException(e)) {
throw e;
}
if (isTrusted(host)) {
// creating a special configuration that allows connections to non-trusted HTTPS hosts
// see the javadoc to EasySSLProtocolSocketFactory for details
Protocol easyHttps = new Protocol("https", (ProtocolSocketFactory)new EasySSLProtocolSocketFactory(), 443);
HostConfiguration hc = new HostConfiguration();
hc.setHost(host, 443, easyHttps);
String relativeUri = new URI(uri.getPathQuery(), false).getURI();
// it is important to use relative URI here, otherwise our custom protocol won't work.
// we have to recreate the method, because HttpMethod#setUri won't overwrite the host,
// and changing host by hands (HttpMethodBase#setHostConfiguration) is deprecated.
HttpMethod method = methodCreator.convert(relativeUri);
client.executeMethod(hc, method);
return method;
}
throw e;
}
示例10: encodeAuthority
import org.apache.commons.httpclient.URI; //导入依赖的package包/类
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;
}
示例11: encodePath
import org.apache.commons.httpclient.URI; //导入依赖的package包/类
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;
}
示例12: testParamValidity_GetLogCollection
import org.apache.commons.httpclient.URI; //导入依赖的package包/类
@Test
public void testParamValidity_GetLogCollection() throws Exception {
//Mandatory only
URI uri = methodMaker.getLogCollectionMethod(serviceUrl, datasetId, null).getURI();
assertContainsURLParam(uri, "datasetid", datasetId);
assertDoesntContainURLParam(uri, "mosaicsvc");
//Optional Params
uri = methodMaker.getLogCollectionMethod(serviceUrl, datasetId, true).getURI();
assertContainsURLParam(uri, "datasetid", datasetId);
assertContainsURLParam(uri, "mosaicsvc", "yes");
uri = methodMaker.getLogCollectionMethod(serviceUrl, datasetId, false).getURI();
assertContainsURLParam(uri, "datasetid", datasetId);
assertContainsURLParam(uri, "mosaicsvc", "no");
}
示例13: testYilgarnGeochemistryFilter
import org.apache.commons.httpclient.URI; //导入依赖的package包/类
/**
* Test doing geochemistry filter and getting all values
*/
@Test
public void testYilgarnGeochemistryFilter() throws Exception{
final String kmlBlob = "kmlBlob";
final String serviceUrl = "http://service/wfs";
final String geologicName = "filter info";
final int maxFeatures = 0;
final String bbox = null;
final String expectedGML = "<gml/>";
context.checking(new Expectations() {{
oneOf(mockWfsService).getWfsResponseAsKml(with(equal(serviceUrl)), with(equal("gsml:GeologicUnit")), with(any(String.class)), with(equal(maxFeatures)), with(equal((String)null)));will(returnValue(new WFSTransformedResponse(expectedGML, kmlBlob, mockMethod)));
allowing(mockMethod).getURI();will(returnValue(new URI(serviceUrl, true)));
}});
ModelAndView modelAndView = controller.doYilgarnGeochemistryFilter(serviceUrl, geologicName, bbox, maxFeatures);
Assert.assertNotNull(modelAndView);
Map<String, Object> model = modelAndView.getModel();
Assert.assertEquals(true, model.get("success"));
Assert.assertNotNull(model.get("data"));
}
示例14: testYilgarnGeochemistryFilterCount
import org.apache.commons.httpclient.URI; //导入依赖的package包/类
/**
* Test doing geochemistry filter and getting the count of all values
*/
@Test
public void testYilgarnGeochemistryFilterCount() throws Exception{
final String serviceUrl = "http://service/wfs";
final String geologicName = "filter info";
final int maxFeatures = 134;
final String bbox = null;
final int numberOfFeatures = 123;
context.checking(new Expectations() {{
oneOf(mockWfsService).getWfsFeatureCount(with(equal(serviceUrl)), with(equal("gsml:GeologicUnit")), with(any(String.class)), with(equal(maxFeatures)), with((String) null));will(returnValue(new WFSCountResponse(numberOfFeatures)));
allowing(mockMethod).getURI();will(returnValue(new URI(serviceUrl, true)));
}});
ModelAndView modelAndView = controller.doYilgarnGeochemistryCount(serviceUrl, geologicName, bbox, maxFeatures);
Assert.assertNotNull(modelAndView);
Map<String, Object> model = modelAndView.getModel();
Assert.assertEquals(true, model.get("success"));
Assert.assertNotNull(model.get("data"));
Assert.assertEquals(new Integer(numberOfFeatures), model.get("data"));
}
示例15: testYilgarnGeochemistryFilterCountError
import org.apache.commons.httpclient.URI; //导入依赖的package包/类
/**
* Test doing geochemistry filter and getting the count of all values fails gracefully
*/
@Test
public void testYilgarnGeochemistryFilterCountError() throws Exception{
final String serviceUrl = "http://service/wfs";
final String geologicName = "filter info";
final int maxFeatures = 134;
final String bbox = null;
context.checking(new Expectations() {{
oneOf(mockWfsService).getWfsFeatureCount(with(equal(serviceUrl)), with(equal("gsml:GeologicUnit")), with(any(String.class)), with(equal(maxFeatures)), with((String) null));will(throwException(new PortalServiceException(mockMethod, new ConnectException())));
allowing(mockMethod).getURI();will(returnValue(new URI(serviceUrl, true)));
}});
ModelAndView modelAndView = controller.doYilgarnGeochemistryCount(serviceUrl, geologicName, bbox, maxFeatures);
Assert.assertNotNull(modelAndView);
Map<String, Object> model = modelAndView.getModel();
Assert.assertEquals(false, model.get("success"));
}