本文整理汇总了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);
}
}
示例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())
);
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
}
示例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;
}
示例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);
}
示例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()));
}
示例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()));
}
示例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;
}
示例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()));
}