本文整理了Java中org.restlet.Response
类的一些代码示例,展示了Response
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response
类的具体详情如下:
包路径:org.restlet.Response
类名称:Response
[英]Generic response sent by server connectors. It is then received by client connectors. Responses are uniform across all types of connectors, protocols and components.
[中]服务器连接器发送的一般响应。然后由客户端连接器接收。所有类型的连接器、协议和组件的响应都是一致的。
代码示例来源:origin: uber/chaperone
public Representation post(Representation entity) {
try {
final String topicName = (String) getRequest().getAttributes().get("topicName");
String jsonRequest = entity.getText();
TopicPartition topicPartitionInfo = null;
if ((jsonRequest == null || jsonRequest.isEmpty()) && topicName != null
getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
return new StringRepresentation(String.format(
"Failed to add new topic: %s, it is already existed!", topicPartitionInfo.getTopic()));
getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
return new StringRepresentation(
String.format("Failed to add new topic, with exception: %s", e));
代码示例来源:origin: org.restlet.gae/org.restlet.ext.freemarker
@Override
protected void afterHandle(Request request, Response response) {
if (response.isEntityAvailable()
&& response.getEntity().getEncodings()
.contains(Encoding.FREEMARKER)) {
TemplateRepresentation representation = new TemplateRepresentation(
response.getEntity(), this.configuration, response
.getEntity().getMediaType());
representation.setDataModel(createDataModel(request, response));
response.setEntity(representation);
}
}
代码示例来源:origin: org.restlet.osgi/org.restlet.ext.oauth
@Override
public Representation handleInbound(Response response) {
Representation result = null;
// Verify that the request was synchronous
if (response.getRequest().isSynchronous()) {
if (response.getStatus().isError()) {
doError(response.getStatus());
// DO NOT DISPOSE THE RESPONSE.
}/* else { */
result = (response == null) ? null : response.getEntity();
/* } */
}
return result;
}
代码示例来源:origin: uber/chaperone
@Test
public void testPost() {
// Create topic
Request request = ControllerRequestURLBuilder.baseUrl(REQUEST_URL)
.getTopicCreationRequestUrl("testTopic1", 16);
Response response = HTTP_CLIENT.handle(request);
Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
Assert.assertEquals(response.getEntityAsText(),
"Successfully add new topic: {topic: testTopic1, partition: 16}");
Assert.assertTrue(ZK_CLIENT.exists("/" + HELIX_CLUSTER_NAME + "/CONFIGS/RESOURCE/testTopic1"));
// Create existed topic
request = ControllerRequestURLBuilder.baseUrl(REQUEST_URL)
.getTopicCreationRequestUrl("testTopic1", 16);
response = HTTP_CLIENT.handle(request);
Assert.assertEquals(response.getStatus(), Status.CLIENT_ERROR_NOT_FOUND);
Assert.assertEquals(response.getEntityAsText(),
"Failed to add new topic: testTopic1, it is already existed!");
// Delete topic
request =
ControllerRequestURLBuilder.baseUrl(REQUEST_URL).getTopicDeleteRequestUrl("testTopic1");
response = HTTP_CLIENT.handle(request);
Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
Assert.assertEquals(response.getEntityAsText(),
"Successfully finished delete topic: testTopic1");
}
代码示例来源:origin: org.restlet.osgi/org.restlet
/**
* Displays a synthesis of the response like an HTTP status line.
*
* @return A synthesis of the response like an HTTP status line.
*/
public String toString() {
return ((getRequest() == null) ? "?" : getRequest().getProtocol())
+ " - " + getStatus();
}
}
代码示例来源:origin: org.restlet.gae/org.restlet.ext.platform
/**
* Generates a CallLog for the request and adds it to the buffer.
*
* @param request
* The Request object associated with the request.
* @param response
* The Response object associated with the request.
* @param duration
* The duration of the request in milliseconds.
* @param startTime
* The time at which the request arrived to the agent as an
* epoch.
*/
public void addCallLogToBuffer(Request request, Response response,
int duration, long startTime) {
CallLog callLog = new CallLog();
callLog.setDate(new Date(startTime));
callLog.setDuration(duration);
callLog.setMethod(request.getMethod().getName());
callLog.setPath(request.getResourceRef().getPath());
callLog.setRemoteIp(request.getClientInfo().getUpstreamAddress());
callLog.setStatusCode(response.getStatus().getCode());
callLog.setUserAgent(request.getClientInfo().getAgent());
callLog.setUserToken((request.getClientInfo().getUser() == null) ? ""
: request.getClientInfo().getUser().getIdentifier());
callLogs.add(callLog);
if (callLogs.size() >= bufferSize) {
flushLogs();
}
}
代码示例来源:origin: org.restlet.android/org.restlet.ext.xml
Reference baseRef = new Reference(base);
targetRef = new Reference(baseRef, href);
} else {
targetRef = new Reference(href);
String targetUri = targetRef.getTargetRef().toString();
Response response = this.context.getClientDispatcher().handle(
new Request(Method.GET, targetUri));
if (response.getStatus().isSuccess()
&& response.isEntityAvailable()) {
try {
result = new StreamSource(response.getEntity().getStream());
result.setSystemId(targetUri);
this.context.getLogger().log(Level.WARNING,
"I/O error while getting the response stream", e);
代码示例来源:origin: org.restlet.jse/org.restlet.ext.json
/**
* Assumes that there is a "callback" query parameter available in the URI
* query string, containing the name of the JavaScript callback method.
*/
@Override
public void afterHandle(Request request, Response response) {
// Check the presence of the callback parameter
String callback = request.getResourceRef().getQueryAsForm()
.getFirstValue("callback");
if (callback != null) {
Representation entity = response.getEntity();
if (entity != null
&& ("text".equals(entity.getMediaType().getMainType()) || MediaType.APPLICATION_JSON
.equals(entity.getMediaType()))) {
response.setEntity(new JsonpRepresentation(callback, response
.getStatus(), response.getEntity()));
response.setStatus(Status.SUCCESS_OK);
}
}
}
代码示例来源:origin: org.restlet.osgi/org.restlet
ClientCall httpCall) {
response.setStatus(status);
response.getServerInfo().setAddress(httpCall.getServerAddress());
response.getServerInfo().setPort(httpCall.getServerPort());
response.setEntity(httpCall.getResponseEntity(response));
if (response.getEntity() != null) {
if (response.getEntity().isEmpty()) {
response.getEntity().release();
} else if (response.getRequest().getMethod().equals(Method.HEAD)) {
response.getEntity().release();
} else if (response.getStatus().equals(Status.SUCCESS_NO_CONTENT)) {
response.getEntity().release();
} else if (response.getStatus()
.equals(Status.SUCCESS_RESET_CONTENT)) {
response.getEntity().release();
response.setEntity(null);
} else if (response.getStatus().equals(
Status.REDIRECTION_NOT_MODIFIED)) {
response.getEntity().release();
} else if (response.getStatus().isInformational()) {
response.getEntity().release();
response.setEntity(null);
代码示例来源:origin: org.restlet.osgi/org.restlet
@Override
protected void afterHandle(Request request, Response response) {
if (getRangeService().isEnabled()) {
response.getServerInfo().setAcceptingRanges(true);
if (request.getMethod().isSafe() && response.isEntityAvailable()) {
Range responseRange = response.getEntity().getRange();
boolean rangedEntity = responseRange != null && isBytesRange(responseRange);
if (response.getStatus().isSuccess()) {
if (Status.SUCCESS_PARTIAL_CONTENT.equals(response.getStatus())) {
if (!rangedEntity) {
getLogger()
if (request.getRanges().size() == 1
&& (!request.getConditions().hasSomeRange()
|| request.getConditions().getRangeStatus(response.getEntity()).isSuccess())) {
if ((!response.getEntity().hasKnownSize())
&& ((requestedRange.getIndex() == Range.INDEX_LAST
|| requestedRange.getSize() == Range.SIZE_MAX)
response.setStatus(Status.SERVER_ERROR_INTERNAL);
getLogger()
.warning(
"Unable to serve this range since at least the end index of the range cannot be computed.");
response.setEntity(null);
} else if (!requestedRange.equals(responseRange)) {
if (rangedEntity) {
代码示例来源:origin: apache/attic-polygene-java
responseHandler = deleteHandler;
Request request = new Request( Method.DELETE, new Reference( reference.toUri() ).toString() );
contextResourceFactory.updateCommandRequest( request );
while( true )
Response response = new Response( request );
try
if( !response.getStatus().isSuccess() )
if( e.getStatus().equals( Status.CONNECTOR_ERROR_COMMUNICATION ) ||
e.getStatus().equals( Status.CONNECTOR_ERROR_CONNECTION ) )
response.getEntity().exhaust();
代码示例来源:origin: uber/uReplicator
Form params = getRequest().getResourceRef().getQueryAsForm();
String srcCluster = params.getFirstValue("src");
String dstCluster = params.getFirstValue("dst");
String routeId = params.getFirstValue("routeid");
if (srcCluster == null || dstCluster == null || routeId == null) {
getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
return new StringRepresentation("Missing parameters for whitelisting topic " + topicName
+ " in federated uReplicator");
getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
String resp = String.format("Failed to add new topic: %s, src=%s, dst=%s, routeid=%s",
topicName, srcCluster, dstCluster, routeId);
if (topicPartitionInfo == null) {
LOGGER.warn("failed to whitelist topic {} on mm because of not exists in src cluster", topicName);
getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
return new StringRepresentation(String.format(
"Failed to add new topic: %s, it's not exsited in source kafka cluster!", topicName));
getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
return new StringRepresentation(String.format(
"Failed to add new topic: %s, it is already existed!", topicPartitionInfo.getTopic()));
getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
return new StringRepresentation(
String.format("Failed to add new topic, with exception: %s", e));
代码示例来源:origin: com.github.ansell.oas/oas-webservice-impl
/**
* Tests whether the RDF/JSON page when there are no annotations is correct.
*/
@Test
public void testAnnotationListEmptyJson() throws Exception
{
final ClientResource getResource =
new ClientResource(this.getUrl(this.propertyUtil.get(OasProps.PROP_BULK_FETCH_ANNOTATION_PATH,
OasProps.DEF_BULK_FETCH_ANNOTATION_PATH)));
final Representation results = getResource.get(RestletUtilMediaType.APPLICATION_RDF_JSON);
// Expecting HTTP 200 OK response
Assert.assertEquals(200, getResource.getResponse().getStatus().getCode());
// Expecting application/json MIME type for response
Assert.assertEquals(RestletUtilMediaType.APPLICATION_RDF_JSON.getName(), results.getMediaType().getName());
this.assertRdf(results.getStream(), RDFFormat.RDFJSON, 0);
}
代码示例来源:origin: org.restlet.android/org.restlet.ext.atom
/**
* Returns the feed representation.
*
* @return The feed representation.
* @throws Exception
*/
public Feed getFeed() throws Exception {
final Reference feedRef = getHref();
if (feedRef.isRelative()) {
feedRef.setBaseRef(getWorkspace().getService().getReference());
}
final Request request = new Request(Method.GET, feedRef.getTargetRef());
final Response response = getWorkspace().getService()
.getClientDispatcher().handle(request);
if (response.getStatus().equals(Status.SUCCESS_OK)) {
return new Feed(response.getEntity());
}
throw new Exception(
"Couldn't get the feed representation. Status returned: "
+ response.getStatus());
}
代码示例来源:origin: org.restlet.osgi/org.restlet
/**
* If the response entity comes back with no identifier, automatically set
* the request's resource reference's identifier. This is very useful to
* resolve relative references in XSLT for example.
*/
@Override
protected void afterHandle(Request request, Response response) {
if ((response.getEntity() != null)
&& (response.getEntity().getLocationRef() == null)) {
response.getEntity().setLocationRef(
request.getResourceRef().getTargetRef().toString());
}
}
代码示例来源:origin: org.restlet.jse/org.restlet.example
@Override
public void handle(Request request, Response response) {
String entity = "Method : " + request.getMethod()
+ "\nResource URI : " + request.getResourceRef()
+ "\nIP address : " + request.getClientInfo().getAddress()
+ "\nAgent name : " + request.getClientInfo().getAgentName()
+ "\nAgent version: "
+ request.getClientInfo().getAgentVersion();
response.setEntity(entity, MediaType.TEXT_PLAIN);
}
代码示例来源:origin: org.restlet.jse/org.restlet.example
@Override
public void challenge(Response response, boolean stale) {
// Load the FreeMarker template
Representation ftl = new ClientResource(
LocalReference.createClapReference(getClass().getPackage())
+ "/Login.ftl").get();
// Wraps the bean with a FreeMarker representation
response.setEntity(new TemplateRepresentation(ftl, response
.getRequest().getResourceRef(), MediaType.TEXT_HTML));
response.setStatus(Status.CLIENT_ERROR_UNAUTHORIZED);
}
代码示例来源:origin: apache/attic-polygene-java
public void updateCache( Response response )
if( response.getRequest().getMethod().equals( Method.DELETE ) )
String path = getIdentityPath( response.getRequest().getResourceRef() );
String id = pathToIdentity.get( path );
if( id != null )
else if( response.getRequest().getMethod().equals( Method.PUT ) || response.getRequest()
.getMethod()
.equals( Method.POST ) )
Tag tag = response.getEntity().getTag();
if( tag != null )
Reference ref = response.getRequest().getResourceRef().clone();
CacheInfo value = new CacheInfo( response.getEntity().getModificationDate().toInstant(), tag);
identityToTimestamp.put( value.getEntity(), value );
代码示例来源:origin: org.restlet.jee/org.restlet.ext.wadl
/**
* Attaches an application created from a WADL description document
* available at a given URI reference.
*
* @param wadlRef
* The URI reference to the WADL description document.
* @return The created WADL application.
*/
public WadlApplication attach(Reference wadlRef) {
WadlApplication result = null;
// Adds some common client connectors to load the WADL documents
if (!getClients().contains(wadlRef.getSchemeProtocol())) {
getClients().add(wadlRef.getSchemeProtocol());
}
// Get the WADL document
final Response response = getContext().getClientDispatcher().handle(
new Request(Method.GET, wadlRef));
if (response.getStatus().isSuccess() && response.isEntityAvailable()) {
result = attach(response.getEntity());
}
return result;
}
代码示例来源:origin: org.restlet.osgi/org.restlet
response.setStatus(Status.CLIENT_ERROR_NOT_FOUND);
} else {
ZipFile zipFile;
zipFile = new ZipFile(file);
} catch (Exception e) {
response.setStatus(Status.SERVER_ERROR_INTERNAL, e);
return;
metadataService);
if (!entity.exists()) {
response.setStatus(Status.CLIENT_ERROR_NOT_FOUND);
} else {
final Representation output;
String fileUri = LocalReference.createFileReference(file)
.toString();
String scheme = request.getResourceRef().getScheme();
String baseUri = scheme + ":" + fileUri + "!/";
metadataService.getDefaultMediaType(),
getTimeToLive());
output.setLocationRef(request.getResourceRef());
Entity.updateMetadata(entity.getName(), output, true,
getMetadataService());
response.setStatus(Status.SUCCESS_OK);
response.setEntity(output);
内容来源于网络,如有侵权,请联系作者删除!