本文整理汇总了Java中com.sun.jersey.api.client.ClientRequest类的典型用法代码示例。如果您正苦于以下问题:Java ClientRequest类的具体用法?Java ClientRequest怎么用?Java ClientRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ClientRequest类属于com.sun.jersey.api.client包,在下文中一共展示了ClientRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handle
import com.sun.jersey.api.client.ClientRequest; //导入依赖的package包/类
@Override
public ClientResponse handle(ClientRequest request) throws ClientHandlerException {
long id = ++_id;
StringBuilder requestString = new StringBuilder();
logRequest(id, request, requestString);
LoggingBean loggingBean = new LoggingBean();
loggingBean.setCommandName(request.getMethod() + ":" + request.getURI());
loggingBean.setArgs(new String[] { request.getURI().getPath(), request.getURI().getQuery() });
ClientResponse response = getNext().handle(request);
loggingBean.setResult(response.toString());
StringBuilder responseString = logResponse(id, response);
LoggingBean detailsLoggingBean = new LoggingBean();
detailsLoggingBean.setArgs(new String[] { noPrifix(requestString).toString() });
detailsLoggingBean.setResult(noPrifix(responseString).toString());
loggingBean.getSubLogs().add(detailsLoggingBean);
TestBaseProvider.instance().get().getLog().add(loggingBean);
return response;
}
示例2: printRequestHeaders
import com.sun.jersey.api.client.ClientRequest; //导入依赖的package包/类
private void printRequestHeaders(StringBuilder b, long id, MultivaluedMap<String, Object> headers) {
for (Map.Entry<String, List<Object>> e : headers.entrySet()) {
List<Object> val = e.getValue();
String header = e.getKey();
if (val.size() == 1) {
prefixId(b, id).append(REQUEST_PREFIX).append(header).append(": ")
.append(ClientRequest.getHeaderValue(val.get(0))).append("\n");
} else {
StringBuilder sb = new StringBuilder();
boolean add = false;
for (Object o : val) {
if (add) {
sb.append(',');
}
add = true;
sb.append(ClientRequest.getHeaderValue(o));
}
prefixId(b, id).append(REQUEST_PREFIX).append(header).append(": ").append(sb.toString()).append("\n");
}
}
}
示例3: handle
import com.sun.jersey.api.client.ClientRequest; //导入依赖的package包/类
@Override
public ClientResponse handle(ClientRequest cr) throws ClientHandlerException
{
URIBuilder uriBuilder = new URIBuilder(cr.getURI());
String path = uriBuilder.getPath();
uriBuilder.setPath(converter.convertCommandPath(path));
try {
cr.setURI(uriBuilder.build());
ClientResponse response = getNext().handle(cr);
String newEntity = converter.convertResponse(path, response.getEntity(String.class));
response.setEntityInputStream(new ByteArrayInputStream(newEntity.getBytes()));
return response;
} catch (Exception ex) {
throw new ClientHandlerException(ex);
}
}
示例4: handle
import com.sun.jersey.api.client.ClientRequest; //导入依赖的package包/类
@Override
public ClientResponse handle(ClientRequest request)
throws ClientHandlerException {
String uuid = UUID.randomUUID().toString();
if (LOGGER.isDebugEnabled()) {
logRequest(uuid, request);
}
ClientResponse response = getNext().handle(request);
if (LOGGER.isDebugEnabled()) {
logResponse(uuid, response);
}
return response;
}
示例5: logRequest
import com.sun.jersey.api.client.ClientRequest; //导入依赖的package包/类
private void logRequest(String uuid, ClientRequest request) {
final StringBuffer sb = new StringBuffer();
sb.append(uuid + "\n" + request.getMethod() + " " + request.getURI()
+ "\n");
request.getHeaders().forEach(
(k, v) -> {
String value = v.stream()
.map(e -> (e == null ? "" : e.toString()))
.collect(Collectors.joining(";"));
sb.append(k + ": " + value + "\n");
});
Optional.ofNullable(request.getEntity()).ifPresent(
e -> sb.append("Body: " + e));
LOGGER.debug(sb.toString());
}
示例6: handle
import com.sun.jersey.api.client.ClientRequest; //导入依赖的package包/类
@Override
public ClientResponse handle(ClientRequest request) throws ClientHandlerException {
String userAgent = "";
try {
Properties prop = ResourceUtil.loadProperiesOnResourceFolder(Constant.RAPID_API_RESOURCE);
userAgent = prop.getProperty(Constant.RAPID_SDK_USER_AGENT_PARAM);
if (StringUtils.isBlank(userAgent)) {
throw new Exception("Resource file " + Constant.RAPID_API_RESOURCE + " is invalid.");
}
} catch (Exception e) {
LOGGER.error("User Agent could not be loaded", e);
}
request.getHeaders().putSingle(HttpHeaders.USER_AGENT, userAgent);
if (this.apiVersion != null) {
request.getHeaders().putSingle("X-EWAY-APIVERSION", this.apiVersion);
}
return getNext().handle(request);
}
示例7: getSerializedEntity
import com.sun.jersey.api.client.ClientRequest; //导入依赖的package包/类
/**
* Get the serialized representation of the request entity. This is used when generating the client
* signature, because this is the representation that the server will receive and use when it generates
* the server-side signature to compare to the client-side signature.
*
* @see com.sun.jersey.client.urlconnection.URLConnectionClientHandler
*/
private byte[] getSerializedEntity(ClientRequest request) {
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
// By using the RequestWriter parent class, we match the behavior of entity writing from
// for example, com.sun.jersey.client.urlconnection.URLConnectionClientHandler.
writeRequestEntity(request, new RequestEntityWriterListener() {
public void onRequestEntitySize(long size) throws IOException {
}
public OutputStream onGetOutputStream() throws IOException {
return outputStream;
}
});
} catch (IOException e) {
throw new ClientHandlerException("Unable to serialize request entity", e);
}
return outputStream.toByteArray();
}
示例8: handle
import com.sun.jersey.api.client.ClientRequest; //导入依赖的package包/类
@Override
public ClientResponse handle(ClientRequest request) throws ClientHandlerException {
MultivaluedMap headers = request.getHeaders();
try {
if(cloudSpace != null) {
headers.add("x-tmrk-cloudspace", cloudSpace);
}
String signature = sign(request, headers);
headers.add("x-tmrk-authorization", new StringBuilder().append("CloudApi AccessKey=").append(getAccessKey()).append(" SignatureType=").append("HmacSHA256").append(" Signature=").append(signature).toString());
} catch (Exception ex) {
throw new ClientHandlerException("Error signing request headers", ex);
}
return getNext().handle(request);
}
示例9: getCanonicalizedResource
import com.sun.jersey.api.client.ClientRequest; //导入依赖的package包/类
private static String getCanonicalizedResource(ClientRequest request) {
Map<String, Object> queryMap = new TreeMap();
String query = request.getURI().getQuery();
if ((query != null) && (query.length() > 0)) {
String[] parts = query.split("&");
for (String part : parts) {
String[] nameValue = part.split("=");
if (nameValue.length == 2) {
queryMap.put(nameValue[0].toLowerCase(), nameValue[1]);
}
}
}
StringBuilder builder = new StringBuilder();
builder.append(request.getURI().getPath().toLowerCase()).append('\n');
for (Map.Entry entry : queryMap.entrySet()) {
builder.append((String) entry.getKey()).append(':').append((String) entry.getValue()).append('\n');
}
return builder.toString();
}
示例10: setup
import com.sun.jersey.api.client.ClientRequest; //导入依赖的package包/类
@Before
public void setup() {
dummy = context.mock(ClientHandler.class);
authFilter = new BasicAuthFilter("admin", "lamepass");
ReflectionTestUtils.setField(authFilter, "next", dummy);
clientRequest = context.mock(ClientRequest.class);
headers = new MultivaluedMapImpl();
context.checking(new Expectations() {
{
allowing(clientRequest).getHeaders();
will(returnValue(headers));
allowing(dummy).handle(with(aNonNull(ClientRequest.class)));
will(returnValue(null));
}
});
}
示例11: handle
import com.sun.jersey.api.client.ClientRequest; //导入依赖的package包/类
@Override
public ClientResponse handle(ClientRequest request) throws ClientHandlerException {
addTokenToRequest(request);
ClientResponse response = getNext().handle(request);
// Handle a redirect
if (response.getClientResponseStatus() == ClientResponse.Status.FOUND) {
if (response.getHeaders().containsKey(HttpHeaders.LOCATION)) {
String location = response.getHeaders().getFirst(HttpHeaders.LOCATION);
final ClientRequest newRequest = ClientRequest.create().build(URI.create(location), request.getMethod());
// Handle the token from the existing response, add to this new request
checkResponseForToken(response);
addTokenToRequest(newRequest);
// Call handler to perform redirect to new page
response = handle(newRequest);
}
}
checkResponseForToken(response);
return response;
}
示例12: handle
import com.sun.jersey.api.client.ClientRequest; //导入依赖的package包/类
@Override
public ClientResponse handle(ClientRequest request) throws ClientHandlerException {
ClientResponse response = getNext().handle(request);
int status = response.getStatus();
if (status >= 400 && status < 600) {
if (isSupportedType(response.getType())) {
ServiceErrorRestRep serviceError;
try {
serviceError = response.getEntity(ServiceErrorRestRep.class);
} catch (Exception e) {
// Cause to fall-through to default exception
log.error("Error parsing error message", e);
serviceError = null;
}
if (serviceError != null) {
logAndThrow(new ServiceErrorException(status, serviceError));
}
}
// Fallback for unknown entity types
String content = response.getEntity(String.class);
logAndThrow(new ViPRHttpException(status, content));
}
return response;
}
示例13: handle
import com.sun.jersey.api.client.ClientRequest; //导入依赖的package包/类
@Override
public ClientResponse handle(ClientRequest clientRequest) {
Throwable cause = null;
for (int retryCount = 1; retryCount <= maxRetries; retryCount++) {
try {
ClientResponse response = getNext().handle(clientRequest);
return response;
} catch (ServiceErrorException e) {
if (!e.isRetryable()) {
throw e;
}
cause = e;
}
log.info("Request failed {}, retrying (count: {})", clientRequest.getURI().toString(), retryCount);
try {
Thread.sleep(retryInterval);
} catch (InterruptedException exception) {
// Ignore this
}
}
throw new ViPRException("Retry limit exceeded", cause);
}
示例14: printRequestHeaders
import com.sun.jersey.api.client.ClientRequest; //导入依赖的package包/类
private void printRequestHeaders(StringBuilder b, long id, MultivaluedMap<String, Object> headers) {
for (Map.Entry<String, List<Object>> e : headers.entrySet()) {
List<Object> val = e.getValue();
String header = e.getKey();
if(val.size() == 1) {
prefixId(b, id).append(REQUEST_PREFIX).append(header).append(": ").append(ClientRequest.getHeaderValue(val.get(0))).append("\n");
} else {
StringBuilder sb = new StringBuilder();
boolean add = false;
for(Object o : val) {
if(add) sb.append(',');
add = true;
sb.append(ClientRequest.getHeaderValue(o));
}
prefixId(b, id).append(REQUEST_PREFIX).append(header).append(": ").append(sb.toString()).append("\n");
}
}
}
示例15: readSourceDescription
import com.sun.jersey.api.client.ClientRequest; //导入依赖的package包/类
public SourceDescriptionState readSourceDescription(SourceReference sourceReference, StateTransitionOption... options) {
Link link = sourceReference.getLink(Rel.DESCRIPTION);
link = link == null ? sourceReference.getLink(Rel.SELF) : link;
org.gedcomx.common.URI href;
if (link != null) {
href = link.getHref();
}
else {
href = sourceReference.getDescriptionRef();
}
if (href == null) {
throw new GedcomxApplicationException("Source description cannot be read: missing link.");
}
ClientRequest request = createAuthenticatedGedcomxRequest().build(href.toURI(), HttpMethod.GET);
return this.stateFactory.newSourceDescriptionState(request, invoke(request, options), this.accessToken);
}