当前位置: 首页>>代码示例>>Java>>正文


Java Request.getUrl方法代码示例

本文整理汇总了Java中retrofit.client.Request.getUrl方法的典型用法代码示例。如果您正苦于以下问题:Java Request.getUrl方法的具体用法?Java Request.getUrl怎么用?Java Request.getUrl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在retrofit.client.Request的用法示例。


在下文中一共展示了Request.getUrl方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: execute

import retrofit.client.Request; //导入方法依赖的package包/类
@Override
public Response execute(Request request) throws IOException {
	try {
		List<Header> headers = new LinkedList<Header>(request.getHeaders());

		// if logged in add auth header
		Optional<Account> account = loginManager.getAccount();
		if (account.isPresent()) {
			String token = loginManager.getToken(account.get());
			Header authHeader = new Header("Authorization", "Bearer " + token);
			headers.add(authHeader);
		}

		Request signedRequest = new Request(
				request.getMethod(),
				request.getUrl(),
				headers,
				request.getBody());

		return super.execute(signedRequest);

	} catch (GoogleAuthException gae) {
		throw new IOException(gae);
	}
}
 
开发者ID:jvalue,项目名称:hochwasser-app,代码行数:26,代码来源:AuthClient.java

示例2: execute

import retrofit.client.Request; //导入方法依赖的package包/类
@Override
public Response execute(Request request) throws IOException {
    List<Matcher<? super Request>> unmatchedRoutes = new LinkedList<>();
    for (Route route : routes) {
        if (route.requestMatcher.matches(request)) return route.response.createFrom(request);
        unmatchedRoutes.add(route.requestMatcher);
    }
    StringDescription description = new StringDescription();
    AnyOf.anyOf(unmatchedRoutes).describeTo(description);
    return new Response(
            request.getUrl(),
            404,
            "No route matched",
            Collections.<Header>emptyList(), 
            new TypedString("No matching route found. expected:\n" + description.toString())
    );
}
 
开发者ID:ccmtaylor,项目名称:retromock,代码行数:18,代码来源:MockClient.java

示例3: prepareHttpRequest

import retrofit.client.Request; //导入方法依赖的package包/类
public static HttpRequest prepareHttpRequest(final Request request) throws IOException {

        // Extract details from incoming request from Retrofit
        final String requestUrl = request.getUrl();
        final String requestMethod = request.getMethod();
        final List<Header> requestHeaders = request.getHeaders();

        // URL and Method
        final HttpRequest httpRequest = new HttpRequest(requestUrl, requestMethod);

        // Headers
        for (Header header: requestHeaders) {
            httpRequest.header(header.getName(), header.getValue());
        }

        return httpRequest;
    }
 
开发者ID:groodt,项目名称:http-request-retrofit-client,代码行数:18,代码来源:HttpRequestClient.java

示例4: execute

import retrofit.client.Request; //导入方法依赖的package包/类
@Override
public Response execute(Request request) throws IOException {
    Map<String, String> headersMap = MutableMap.of();
    for (Header header: request.getHeaders()) {
        headersMap.put(header.getName(), header.getValue());
    }

    String mimeType = "text/plain"; // Default Content-Type used in Brooklyn Ambari
    byte[] content = null;
    TypedOutput body = request.getBody();
    if (body != null) {
        mimeType = request.getBody().mimeType();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try {
            body.writeTo(baos);
            content = baos.toByteArray();
        } finally {
            Streams.closeQuietly(baos);
        }
    }

    final HttpResponse response = httpExecutor.execute(new HttpRequest.Builder()
            .headers(headersMap)
            .uri(URI.create(request.getUrl()))
            .method(request.getMethod())
            .body(content)
            .build());

    List<Header> responseHeaders = Lists.newArrayList();
    for (Map.Entry<String, String> entry: response.headers().entries()) {
        responseHeaders.add(new Header(entry.getKey(), entry.getValue()));
    }
    TypedInput responseBody = new TypedByteArray(mimeType, ByteStreams.toByteArray(response.getContent()));
    return new Response(request.getUrl(), 
            response.code(), 
            (response.reasonPhrase() != null) ? response.reasonPhrase() : "", 
            responseHeaders, 
            responseBody);
}
 
开发者ID:brooklyncentral,项目名称:brooklyn-ambari,代码行数:40,代码来源:AmbariRestClient.java

示例5: execute

import retrofit.client.Request; //导入方法依赖的package包/类
@Override
public Response execute(Request request) throws IOException {
    String requestUrl = request.getUrl();
    requestUrl = requestUrl.split("9091")[1];
    if (urlToResponseMap.keySet().contains(requestUrl)) {
        return urlToResponseMap.get(requestUrl);
    }
    return null;
}
 
开发者ID:SIGLUS,项目名称:lmis-moz-mobile,代码行数:10,代码来源:MockClient.java

示例6: convertResult

import retrofit.client.Request; //导入方法依赖的package包/类
private Response convertResult(Request request, Result result) throws IOException {
	Map<String, String> headerMap = result.getHeaders();
	TypedInput input = new TypedByteArray(headerMap.get("Content-Type"), result.getDecodedBody());
	List<Header> headers = new ArrayList<Header>(headerMap.size());
	for (Entry<String, String> entry : headerMap.entrySet()) {
		headers.add(new Header(entry.getKey(), entry.getValue()));
	}
	return new Response(request.getUrl(), result.getStatus(), result.getStatusLine(), headers, input);
}
 
开发者ID:aloha-app,项目名称:libcurldroid,代码行数:10,代码来源:RetrofitCurlClient.java

示例7: execute

import retrofit.client.Request; //导入方法依赖的package包/类
@Override
public Response execute(Request request) throws IOException {
    Response response = super.execute(request);
    if (response.getStatus() == 401) {
        // Unauthorized, attempt to refresh access token
        String refreshToken = mAuthModel.getRefreshToken();
        if (refreshToken == null) {
            return response;
        }
        mAuthModel = sAuthService.refreshToken(refreshToken);
        mAuthModel.setContext(mContext);
        mAuthModel.saveTokens();

        // Switch out auth token in request
        List<Header> headers = new ArrayList<Header>();
        for (Header header : request.getHeaders()) {
            if (header.getName().equals("Authorization")) {
                headers.add(new Header("Authorization", "Bearer " + mAuthModel.getUserToken()));
            } else {
                headers.add(header);
            }
        }

        // Retry request
        Request updatedRequest = new Request(request.getMethod(), request.getUrl(), headers, request.getBody());
        return super.execute(updatedRequest);
    } else {
        return response;
    }
}
 
开发者ID:openglasgow,项目名称:glasgow-cycling-android,代码行数:31,代码来源:ApiClientModule.java

示例8: sign

import retrofit.client.Request; //导入方法依赖的package包/类
/**
 * internal sign function of the request.
 *
 * @param request the request
 * @return the request
 */
private Request sign(final Request request) {
	if (request != null && request.getHeaders() != null) {
		try {
			List<Header> modifiedHeaders = new ArrayList<Header>();

			// duplicate the headers if there is already something
			if (request.getHeaders().isEmpty()) {
				for (int i = 0; i < request.getHeaders().size(); i++) {
					Header header = request.getHeaders().get(i);
					// avoid duplication otherwise it will repeted forever
					if (!modifiedHeaders.contains(header)) {
						modifiedHeaders.add(header);
					}
				}
			}

			// signing thing
			modifiedHeaders.add(new Header("X-Ovh-Application", applicationKey));
			modifiedHeaders.add(new Header("Content-type", "application/json"));

			return new Request(request.getMethod(), request.getUrl(), modifiedHeaders, request.getBody());
		} catch (Exception e) {
			exceptionHandler.handleException(e);
		}
	}
	return request;
}
 
开发者ID:ovhlabs,项目名称:java-runabove,代码行数:34,代码来源:CredentialClient.java

示例9: getResponse

import retrofit.client.Request; //导入方法依赖的package包/类
public static Response getResponse(final Request request, final HttpRequest httpRequest) throws IOException {
    // Execute request and get response
    final int responseCode = httpRequest.code();
    final String responseMessage = httpRequest.message();
    final String responseCharset = getValidCharSet(httpRequest);
    final byte[] bodyBytes = httpRequest.body().getBytes(responseCharset);

    // Prepare response headers
    Map<String, List<String>> httpRequestResponseHeaders = httpRequest.headers();
    List<Header> retrofitResponseHeaders = transformHttpResponseHeadersToRetrofitHeaders(httpRequestResponseHeaders);

    // Prepare response data
    TypedInput typedInput = new TypedInput() {
        @Override
        public String mimeType() {
            return httpRequest.contentType();
        }

        @Override
        public long length() {
            return bodyBytes.length;
        }

        @Override
        public InputStream in() throws IOException {
            return new ByteArrayInputStream(bodyBytes);
        }
    };

    // Response object for Retrofit
    return new Response(request.getUrl(), responseCode, responseMessage, retrofitResponseHeaders, typedInput);
}
 
开发者ID:groodt,项目名称:http-request-retrofit-client,代码行数:33,代码来源:HttpRequestClient.java

示例10: openConnection

import retrofit.client.Request; //导入方法依赖的package包/类
@Override
protected HttpURLConnection openConnection(Request request) throws IOException {
    final URL url = new URL(request.getUrl());
    final String path = url.getPath().substring(
            ICrowdmapConstants.API_VERSION.length()
                    + 1
    ); // Remove the version number from the returned path. plus 1 to take care of the leading slash
    final @ApiKey String key = Util
            .generateSignature(request.getMethod(), path, mCrowdmapApiKeys.getPublicKey(),
                    mCrowdmapApiKeys.getPrivateKey());

    final RequestVariable requestVariable = new RequestVariable("apikey", key);
    final String query = url.getQuery() == null ? "?" : "&";
    return client.open(new URL(request.getUrl() + query + requestVariable.toString()));
}
 
开发者ID:ushahidi,项目名称:Crowdmap-Java,代码行数:16,代码来源:SignRequestClient.java

示例11: execute

import retrofit.client.Request; //导入方法依赖的package包/类
@Override
public Response execute(Request request) throws IOException {
    return new Response(request.getUrl(), httpResponseCode, reason, httpResponseHeaders, new TypedByteArray("application/json", "foobar".getBytes()));
}
 
开发者ID:uphold,项目名称:uphold-sdk-android,代码行数:5,代码来源:MockClientUpholdRetrofitErrorHandlingTest.java

示例12: execute

import retrofit.client.Request; //导入方法依赖的package包/类
@Override
public Response execute( Request request ) throws IOException
{
    if ( !isUserLoggedIn() )
    {
        throw new IOException( "User not logged in" );
    }

    // First, sign the request
    OAuthRequest oAuthRequest = new OAuthRequest( getVerbForMethod( request.getMethod() ), request.getUrl() );
    signingService.signRequest( getAccessToken(), oAuthRequest );

    // Then switch the old headers with signed headers
    Map<String, String> signedHeadersMap = oAuthRequest.getHeaders();
    List<Header> signedHeaders = new ArrayList<Header>( signedHeadersMap.size() );
    for ( Map.Entry<String, String> header : signedHeadersMap.entrySet() )
    {
        signedHeaders.add( new Header( header.getKey(), header.getValue() ) );
    }

    // Switch old url with new url
    String signedUrl = oAuthRequest.getCompleteUrl();
    Helper.debug( signedUrl );

    // Make new request with signed headers and url
    Request signedRequest = new Request( request.getMethod(), signedUrl, signedHeaders, request.getBody() );

    // We need to check status of response in case it failed due to access token expiry
    Response response = super.execute( signedRequest );

    // 401 most likely indicates that access token has expired.
    // Time to refresh and resend the request
    if ( response.getStatus() == 401 && accessTokenCanExpire() )
    {
        // Do ensure that updateAccessToken() stores the value
        // of the updated access token in AccountPrefs.
        updateAccessToken();
        return execute( request );
    }
    return response;
}
 
开发者ID:iTwenty,项目名称:Hashtagger,代码行数:42,代码来源:SitesSigningClient.java

示例13: execute

import retrofit.client.Request; //导入方法依赖的package包/类
public Response execute(Request request) throws IOException {
	String uri = request.getUrl().replaceAll("https:\\/\\/api\\.runabove\\.com\\/1\\.0", "");

	LOG.info("fetching uri: " + uri.toString());
	String responseString = "{\n" + "'validationUrl': 'https://api.runabove.com/login/qdfwb',\n" + "'consumerKey': '63C4VMs4MDpwfGDj4KQEnTjbkvjSJCSY',\n"
			+ "'state': 'pendingTest'\n" + "}";

	return new Response(request.getUrl(), 200, "nothing", Collections.EMPTY_LIST, new TypedByteArray("application/json", responseString.getBytes()));

}
 
开发者ID:ovhlabs,项目名称:java-runabove,代码行数:11,代码来源:MockAuthClient.java


注:本文中的retrofit.client.Request.getUrl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。