本文整理了Java中org.restlet.data.Response
类的一些代码示例,展示了Response
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response
类的具体详情如下:
包路径:org.restlet.data.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: org.sonatype.nexus/nexus-test-harness-base
public List<PrivilegeStatusResource> getList( ) throws IOException
{
Response response = this.sendMessage( Method.GET, null );
if ( !response.getStatus().isSuccess() )
{
Assert.fail( "Could not get Privilege: " + response.getStatus() +"\n" + response.getEntity().getText());
}
return this.getResourceListFromResponse( response );
}
代码示例来源:origin: org.restlet/org.restlet
/**
* Sets the status.
*
* @param status
* The status to set.
* @param throwable
* The related error or exception.
*/
public void setStatus(Status status, Throwable throwable) {
setStatus(new Status(status, throwable));
}
代码示例来源:origin: internetarchive/heritrix3
@Override
public void acceptRepresentation(Representation entity) throws ResourceException {
Form form = getRequest().getEntityAsForm();
chosenEngine = form.getFirstValue("engine");
String script = form.getFirstValue("script");
if(StringUtils.isBlank(script)) {
script="";
}
ScriptEngine eng = MANAGER.getEngineByName(chosenEngine);
scriptingConsole.bind("scriptResource", this);
scriptingConsole.execute(eng, script);
scriptingConsole.unbind("scriptResource");
//TODO: log script, results somewhere; job log INFO?
getResponse().setEntity(represent());
}
代码示例来源:origin: org.restlet/org.restlet
/**
* Permanently redirects the client to a target URI. The client is expected
* to reuse the same method for the new request.
*
* @param targetRef
* The target URI reference.
*/
public void redirectPermanent(Reference targetRef) {
setLocationRef(targetRef);
setStatus(Status.REDIRECTION_PERMANENT);
}
代码示例来源:origin: org.restlet/org.restlet
final Reference baseRef = new Reference(base);
targetRef = new Reference(baseRef, href);
} else {
targetRef = new Reference(href);
final Response response = this.context.getClientDispatcher()
.get(targetUri);
if (response.getStatus().isSuccess()
&& response.isEntityAvailable()) {
try {
result = new StreamSource(response.getEntity()
.getStream());
result.setSystemId(targetUri);
代码示例来源:origin: org.sonatype.nexus.plugins/nexus-indexer-lucene-plugin
throws ResourceException
String path = parsePathFromUri(request.getResourceRef().toString());
if (!path.endsWith("/")) {
response.redirectPermanent(path + "/");
return null;
String versionHint = null;
Form form = request.getResourceRef().getQueryAsForm();
new IndexBrowserTreeNodeFactory(repository, createRedirectBaseRef(request).toString());
throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND,
"The index is disabled for this repository.");
throw new ResourceException(Status.CLIENT_ERROR_FORBIDDEN, "Access Denied to Repository");
代码示例来源:origin: org.sonatype.nexus/nexus-test-harness-base
protected File downloadSnapshotArtifact( String repository, Gav gav, File parentDir )
throws IOException
{
// @see http://issues.sonatype.org/browse/NEXUS-599
// r=<repoId> -- mandatory
// g=<groupId> -- mandatory
// a=<artifactId> -- mandatory
// v=<version> -- mandatory
// c=<classifier> -- optional
// p=<packaging> -- optional, jar is taken as default
// http://localhost:8087/nexus/service/local/artifact/maven/redirect?r=tasks-snapshot-repo&g=nexus&a=artifact&
// v=1.0-SNAPSHOT
String serviceURI =
"service/local/artifact/maven/redirect?r=" + repository + "&g=" + gav.getGroupId() + "&a="
+ gav.getArtifactId() + "&v=" + gav.getVersion();
Response response = RequestFacade.doGetRequest( serviceURI );
Status status = response.getStatus();
Assert.assertEquals( "Snapshot download should redirect to a new file\n "
+ response.getRequest().getResourceRef().toString() + " \n Error: " + status.getDescription(), 301,
status.getCode() );
Reference redirectRef = response.getRedirectRef();
Assert.assertNotNull( "Snapshot download should redirect to a new file "
+ response.getRequest().getResourceRef().toString(), redirectRef );
serviceURI = redirectRef.toString();
File file = FileUtils.createTempFile( gav.getArtifactId(), '.' + gav.getExtension(), parentDir );
RequestFacade.downloadFile( new URL( serviceURI ), file.getAbsolutePath() );
return file;
}
代码示例来源:origin: org.sonatype.nexus/nexus-it-helper-plugin
public Object get(Context context, Request request, Response response, Variant variant)
throws ResourceException
{
Form form = request.getResourceRef().getQueryAsForm();
final long timeout = Long.parseLong(form.getFirstValue("timeout", "60000"));
try {
final long startTime = System.currentTimeMillis();
while (System.currentTimeMillis() - startTime <= timeout) {
if (!((ManagerImpl) manager).isUpdatePrefixFileJobRunning()) {
response.setStatus(Status.SUCCESS_OK);
return "Ok";
}
Thread.sleep(500);
}
}
catch (final InterruptedException ignore) {
// ignore
}
response.setStatus(Status.SUCCESS_ACCEPTED);
return "Still munching on them...";
}
}
代码示例来源:origin: org.geowebcache/gwc-rest
private void doGet(Request request, Response response) {
Reference resourceRef = request.getResourceRef();
String baseUrl = resourceRef.toString();
if (baseUrl.endsWith("/")) {
baseUrl = baseUrl.substring(0, baseUrl.length() - 1);
}
Representation result = new StringRepresentation(
"<html><body>\n"
+ "<a id=\"logo\" href=\""
+ resourceRef.getParentRef()
+ "\">"
+ "<img src=\""
+ baseUrl
+ "/web/geowebcache_logo.png\" alt=\"\" height=\"100\" width=\"353\" border=\"0\"/></a>\n"
+ "<h3>Resources available from here:</h3>"
+ "<ul>"
+ "<li><h4><a href=\""
+ baseUrl
+ "/layers/\">layers</a></h4>"
+ "Lets you see the configured layers. You can also view a specific layer "
+ " by appending the name of the layer to the URL, DELETE an existing layer "
+ " or POST a new one. Note that the latter operations only make sense when GeoWebCache"
+ " has been configured through geowebcache.xml. You can POST either XML or JSON."
+ "</li>\n" + "<li><h4>seed</h4>" + "" + "</li>\n" + "</ul>"
+ "</body></html>",
MediaType.TEXT_HTML);
response.setEntity(result);
}
}
代码示例来源:origin: org.sonatype.nexus.plugins/nexus-restlet1x-plugin
AccessDeniedException, ResourceException
String resPath = parsePathFromUri(req.getResourceRef().toString());
res.redirectPermanent(createRedirectReference(req).getTargetRef().toString() + "/");
if (Method.HEAD.equals(req.getMethod())) {
return renderHeadResponseItem(context, req, res, variant, store, coll.getResourceStoreRequest(), coll);
Representation result = serialize(context, req, variant, response);
result.setModificationDate(new Date(coll.getModified()));
代码示例来源:origin: org.sonatype.nexus/nexus-test-harness-launcher
public ArtifactInfoResource getInfo(String repositoryId, String itemPath)
throws IOException
{
Response response = null;
String entityText;
try {
response =
RequestFacade.sendMessage("service/local/repositories/" + repositoryId + "/content/" + itemPath + "?describe=info",
Method.GET, new XStreamRepresentation(xstream, "", MediaType.APPLICATION_XML));
entityText = response.getEntity().getText(); // to make Restlet response buffer it
if (response.getStatus().getCode() == Status.REDIRECTION_FOUND.getCode()) {
// follow redirection but only ONCE
RequestFacade.releaseResponse(response);
response = RequestFacade.sendMessage(new URL(response.getLocationRef().toString()), Method.GET, new XStreamRepresentation(xstream, "", MediaType.APPLICATION_XML));
entityText = response.getEntity().getText(); // to make Restlet response buffer it
}
assertThat(response, isSuccessful());
}
finally {
RequestFacade.releaseResponse(response);
}
XStreamRepresentation rep =
new XStreamRepresentation(XStreamFactory.getXmlXStream(), entityText, MediaType.APPLICATION_XML);
ArtifactInfoResourceResponse info =
(ArtifactInfoResourceResponse) rep.getPayload(new ArtifactInfoResourceResponse());
return info.getData();
}
代码示例来源:origin: org.sonatype.nexus.plugins/nexus-restlet1x-plugin
protected String buildUploadFailedHtmlResponse(Throwable t, Request request, Response response) {
try {
handleException(request, response, t);
}
catch (ResourceException e) {
getLogger().debug("Got error while uploading artifact", t);
StringBuilder resp = new StringBuilder();
resp.append("<html><body><error>");
resp.append(StringEscapeUtils.escapeHtml(e.getMessage()));
resp.append("</error></body></html>");
String forceSuccess = request.getResourceRef().getQueryAsForm().getFirstValue("forceSuccess");
if (!"true".equals(forceSuccess)) {
response.setStatus(e.getStatus());
}
return resp.toString();
}
// We have an error at this point, can't get here
return null;
}
代码示例来源:origin: org.geoserver.community/bkprst-core
Method m = request.getMethod();
LockType type;
String path= request.getResourceRef().getPath();
response.setStatus(Status.CLIENT_ERROR_LOCKED);
throw new HttpErrorCodeException(Status.CLIENT_ERROR_LOCKED.getCode());
代码示例来源:origin: org.restlet/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());
} else {
throw new Exception(
"Couldn't get the feed representation. Status returned: "
+ response.getStatus().getDescription());
}
}
代码示例来源:origin: org.sonatype.nexus/nexus-it-helper-plugin
@Override
public void delete(Context context, Request request, Response response)
throws ResourceException
{
String repoId = this.getRepositoryId(request);
try {
getNexusConfiguration().deleteRepository(repoId, true);
response.setStatus(Status.SUCCESS_NO_CONTENT);
}
catch (Exception e) {
getLogger().warn("Unable to delete repository, id=" + repoId);
throw new ResourceException(Status.SERVER_ERROR_INTERNAL, "Unable to delete repository, id=" + repoId);
}
}
代码示例来源:origin: org.restlet/org.restlet.ext.freemarker
@Override
protected void afterHandle(Request request, Response response) {
if (response.isEntityAvailable()
&& response.getEntity().getEncodings().contains(
Encoding.FREEMARKER)) {
final TemplateRepresentation representation = new TemplateRepresentation(
response.getEntity(), this.configuration, response
.getEntity().getMediaType());
if (this.dataModel == null) {
representation.setDataModel(request, response);
} else {
representation.setDataModel(this.dataModel);
}
response.setEntity(representation);
}
}
代码示例来源:origin: org.geowebcache/gwc-rest
public void doPost(Request req, Response resp) throws RestletException {
Form form = req.getEntityAsForm();
"Unknown or malformed request. Please try again, somtimes the form "
+"is not properly received. This frequently happens on the first POST "
+"after a restart. The POST was to " + req.getResourceRef().getPath(),
Status.CLIENT_ERROR_BAD_REQUEST );
doc.append("</body></html>");
resp.setEntity(doc.toString(), MediaType.TEXT_HTML);
代码示例来源:origin: org.sonatype.nexus/nexus-test-harness-launcher
public static void removeAllTarget()
throws IOException
{
List<RepositoryTargetListResource> targets = getList();
for (RepositoryTargetListResource target : targets) {
Status status =
RequestFacade.sendMessage("service/local/repo_targets/" + target.getId(), Method.DELETE).getStatus();
Assert.assertTrue("Failt to delete: " + status.getDescription(), status.isSuccess());
}
}
代码示例来源:origin: org.sonatype.nexus/nexus-test-harness-launcher
public RepositoryTargetResource getResourceFromResponse(Response response)
throws IOException
{
String responseString = response.getEntity().getText();
return this.getResourceFromResponse(responseString);
}
代码示例来源:origin: org.restlet/org.restlet
/**
* Asks the resource to delete itself and all its representations.The
* default behavior is to invoke the {@link #removeRepresentations()}
* method.
*
* @deprecated Use the {@link #removeRepresentations()} method instead.
*/
@Deprecated
public void delete() {
try {
removeRepresentations();
} catch (ResourceException re) {
getResponse().setStatus(re.getStatus(), re);
}
}
内容来源于网络,如有侵权,请联系作者删除!