本文整理了Java中org.restlet.data.Status.equals()
方法的一些代码示例,展示了Status.equals()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Status.equals()
方法的具体详情如下:
包路径:org.restlet.data.Status
类名称:Status
方法名:equals
[英]Indicates if the status is equal to a given one.
[中]指示状态是否等于给定状态。
代码示例来源:origin: DeviceConnect/DeviceConnect-Android
/**
* Indicates if an error is recoverable, meaning that simply retrying after
* a delay could result in a success. Tests {@link #isConnectorError()} and
* if the status is {@link #CLIENT_ERROR_REQUEST_TIMEOUT} or
* {@link #SERVER_ERROR_GATEWAY_TIMEOUT} or
* {@link #SERVER_ERROR_SERVICE_UNAVAILABLE}.
*
* @return True if the error is recoverable.
*/
public boolean isRecoverableError() {
return isConnectorError()
|| equals(Status.CLIENT_ERROR_REQUEST_TIMEOUT)
|| equals(Status.SERVER_ERROR_GATEWAY_TIMEOUT)
|| equals(Status.SERVER_ERROR_SERVICE_UNAVAILABLE);
}
代码示例来源:origin: org.restlet.osgi/org.restlet
/**
* Indicates if an error is recoverable, meaning that simply retrying after
* a delay could result in a success. Tests {@link #isConnectorError()} and
* if the status is {@link #CLIENT_ERROR_REQUEST_TIMEOUT} or
* {@link #SERVER_ERROR_GATEWAY_TIMEOUT} or
* {@link #SERVER_ERROR_SERVICE_UNAVAILABLE}.
*
* @return True if the error is recoverable.
*/
public boolean isRecoverableError() {
return isConnectorError()
|| equals(Status.CLIENT_ERROR_REQUEST_TIMEOUT)
|| equals(Status.SERVER_ERROR_GATEWAY_TIMEOUT)
|| equals(Status.SERVER_ERROR_SERVICE_UNAVAILABLE);
}
代码示例来源:origin: org.sonatype.nexus/nexus-test-harness-launcher
public void assertNotExists(String... ids)
throws IOException
{
StringBuilder result = new StringBuilder();
for (String id : ids) {
Response response = this.sendMessage(Method.GET, null, id);
if (!Status.CLIENT_ERROR_NOT_FOUND.equals(response.getStatus())) {
result.append("Privilege shouldn't exist '").append(id).append("': ");
result.append(response.getEntity().getText()).append('\n');
}
}
if (result.length() != 0) {
Assert.fail(result.toString());
}
}
代码示例来源:origin: org.sonatype.nexus/nexus-test-harness-launcher
protected boolean deleteFromRepository(String repository, String groupOrArtifactPath) throws IOException {
String serviceURI = String.format("service/local/repositories/%s/content/%s", repository, groupOrArtifactPath);
Status status = RequestFacade.doGetForStatus(serviceURI);
if (status.equals(Status.CLIENT_ERROR_NOT_FOUND)) {
log.debug("Not deleted because it didn't exist: " + serviceURI);
return true;
}
log.debug("deleting: " + serviceURI);
status = RequestFacade.doDeleteForStatus(serviceURI, null);
boolean deleted = status.isSuccess();
if (!deleted) {
log.debug("Failed to delete: " + serviceURI + " - Status: " + status);
}
// fake it because the artifact doesn't exist
// TODO: clean this up.
if (status.getCode() == 404) {
deleted = true;
}
return deleted;
}
代码示例来源:origin: uk.org.mygrid.remotetaverna/taverna-rest-client
private DataREST handleAddResponse(Response response) {
if (! response.getStatus().equals(Status.SUCCESS_CREATED)) {
logger.warn("Did not create baclava document");
return null;
}
if (response.getRedirectRef() == null) {
logger.error("Did not get redirect reference for data document");
return null;
}
invalidate();
return new DataREST(context, response.getRedirectRef());
}
代码示例来源:origin: ontopia/ontopia
@Override
protected void doError(Status status) {
if (status.equals(Status.CLIENT_ERROR_NOT_ACCEPTABLE) && (status.getThrowable() == null)) {
// we have an ontopia error for this
List<Preference<MediaType>> acceptedMediaTypes = getClientInfo().getAcceptedMediaTypes();
List<MediaType> accepted = new ArrayList<>(acceptedMediaTypes.size());
for (Preference<MediaType> mt : acceptedMediaTypes) {
accepted.add(mt.getMetadata());
}
super.doError(OntopiaRestErrors.UNSUPPORTED_MIME_TYPE.build(getClass().getName(), Arrays.toString(accepted.toArray())).getStatus());
} else {
super.doError(status);
}
}
代码示例来源:origin: uk.org.mygrid.remotetaverna/taverna-rest-client
public WorkflowREST add(String workflow) throws NotSuccessException {
Response response = context.post(getURIReference(), workflow, RESTContext.scuflType);
if (! response.getStatus().equals(Status.SUCCESS_CREATED)) {
logger.warn("Did not create workflow: " + workflow);
return null;
}
if (response.getRedirectRef() == null) {
logger.error("Did not get redirect reference for workflow " + workflow);
return null;
}
invalidate();
return new WorkflowREST(context, response.getRedirectRef());
}
代码示例来源:origin: net.smartcosmos/smartcosmos-java-client
@Override
public Object call(final Class<?> clazz, final String path) throws ServiceException
{
ClientResource service = createClient(path);
try
{
Representation result = service.delete();
if (service.getStatus().equals(Status.SUCCESS_NO_CONTENT))
{
LOGGER.info("Successfully deleted {}", path);
} else
{
JsonRepresentation jsonRepresentation = new JsonRepresentation(result);
JSONObject jsonResult = jsonRepresentation.getJsonObject();
LOGGER.error("Unexpected HTTP status code returned: {}", service.getStatus().getCode());
ResponseEntity response = JsonUtil.fromJson(jsonResult, ResponseEntity.class);
throw new ServiceException(response);
}
} catch (JSONException | IOException e)
{
LOGGER.error("Unexpected Exception", e);
throw new ServiceException(e);
}
return null;
}
代码示例来源:origin: net.smartcosmos/smartcosmos-java-client
@Override
public <T> String encodeMetadata(MetadataDataType metadataDataType, T instance) throws ServiceException
{
String encodedRawValue;
ClientResource service = createClient(MetadataEndpoints.encodeMetadata(metadataDataType));
try
{
Representation result = service.post(new StringRepresentation(instance.toString()));
JsonRepresentation jsonRepresentation = new JsonRepresentation(result);
JSONObject jsonResult = jsonRepresentation.getJsonObject();
if (service.getStatus().equals(Status.SUCCESS_OK))
{
encodedRawValue = jsonResult.getString(Field.RAW_VALUE_FIELD);
} else
{
LOGGER.error("Unexpected HTTP status code returned: {}", service.getStatus().getCode());
ResponseEntity response = JsonUtil.fromJson(jsonResult, ResponseEntity.class);
throw new ServiceException(response);
}
} catch (JSONException | IOException e)
{
LOGGER.error("Unexpected Exception", e);
throw new ServiceException(e);
}
return encodedRawValue;
}
代码示例来源:origin: org.restlet.jee/org.restlet.ext.jaxrs
/**
* Evaluates the preconditions of the current request against the given last
* modified date and / or the given entity tag. This method does not check,
* if the arguments are not null.
*
* @param lastModified
* @param entityTag
* @return
* @see Request#evaluateConditions(Tag, Date)
*/
private ResponseBuilder evaluatePreconditionsInternal(
final Date lastModified, final EntityTag entityTag) {
Status status = this.request.getConditions().getStatus(
this.request.getMethod(), true,
Converter.toRestletTag(entityTag), lastModified);
if (status == null)
return null;
if (status.equals(Status.REDIRECTION_NOT_MODIFIED)) {
final ResponseBuilder rb = Response.notModified();
rb.lastModified(lastModified);
rb.tag(entityTag);
return rb;
}
return Response.status(STATUS_PREC_FAILED);
}
代码示例来源:origin: org.restlet.jse/org.restlet.example
public static void main(String[] args) throws Exception {
// Prepare the request
ClientResource resource = new ClientResource("http://localhost:8111/");
// Add the client authentication to the call
ChallengeScheme scheme = ChallengeScheme.HTTP_BASIC;
ChallengeResponse authentication = new ChallengeResponse(scheme,
"scott", "tiger");
resource.setChallengeResponse(authentication);
// Send the HTTP GET request
resource.get();
if (resource.getStatus().isSuccess()) {
// Output the response entity on the JVM console
resource.getResponseEntity().write(System.out);
} else if (resource.getStatus()
.equals(Status.CLIENT_ERROR_UNAUTHORIZED)) {
// Unauthorized access
System.out
.println("Access authorized by the server, check your credentials");
} else {
// Unexpected status
System.out.println("An unexpected status was returned: "
+ resource.getStatus());
}
}
代码示例来源:origin: org.restlet.jee/org.restlet.ext.atom
/**
* Posts a member to the collection resulting in the creation of a new
* resource.
*
* @param member
* The member representation to post.
* @return The reference of the new resource.
* @throws Exception
*/
public Reference postMember(Representation member) throws Exception {
final Request request = new Request(Method.POST, getHref(), member);
final Response response = getWorkspace().getService()
.getClientDispatcher().handle(request);
if (response.getStatus().equals(Status.SUCCESS_CREATED)) {
return response.getLocationRef();
}
throw new Exception(
"Couldn't post the member representation. Status returned: "
+ response.getStatus());
}
代码示例来源:origin: org.restlet.android/org.restlet.ext.atom
/**
* Posts a member to the collection resulting in the creation of a new
* resource.
*
* @param member
* The member representation to post.
* @return The reference of the new resource.
* @throws Exception
*/
public Reference postMember(Representation member) throws Exception {
final Request request = new Request(Method.POST, getHref(), member);
final Response response = getWorkspace().getService()
.getClientDispatcher().handle(request);
if (response.getStatus().equals(Status.SUCCESS_CREATED)) {
return response.getLocationRef();
}
throw new Exception(
"Couldn't post the member representation. Status returned: "
+ response.getStatus());
}
代码示例来源:origin: org.restlet.jse/org.restlet.example
public static void main(String[] args) throws Exception {
ClientResource cr = new ClientResource("http://localhost:8182/path");
cr.addQueryParameter("q", "hello");
cr.get().write(System.out);
cr = new ClientResource("http://localhost:8182/path");
cr.addQueryParameter("q", "bye");
cr.get().write(System.out);
cr = new ClientResource("http://localhost:8182/path");
cr.addQueryParameter("q", "test");
try {
cr.get();
} catch (Exception e) {
if (Status.CLIENT_ERROR_NOT_FOUND.equals(cr.getStatus())) {
System.out.println("fine.");
} else {
System.out.println("Should be 404 not found response.");
}
}
}
}
代码示例来源:origin: org.restlet.jse/org.restlet.example
public static void main(String[] args) throws ResourceException,
IOException {
// Prepare the request
ClientResource cr = new ClientResource("http://localhost:8182/");
ChallengeRequest c1 = null;
// first try: unauthenticated request
try {
cr.get();
} catch (ResourceException re) {
if (Status.CLIENT_ERROR_UNAUTHORIZED.equals(cr.getStatus())) {
c1 = getDigestChallengeRequest(cr);
}
}
// second try: authenticated request
if (c1 != null) {
ChallengeResponse c2 = new ChallengeResponse(c1, cr.getResponse(),
"scott", "tiger".toCharArray());
cr.setChallengeResponse(c2);
cr.get().write(System.out);
}
}
代码示例来源:origin: net.smartcosmos/smartcosmos-java-client
@Override
public JSONObject decodeMetadata(MetadataDataType metadataDataType, JSONObject jsonObject) throws ServiceException
{
JSONObject jsonResult;
ClientResource service = createClient(MetadataEndpoints.decodeMetadata(metadataDataType));
try
{
Representation result = service.post(new JsonRepresentation(jsonObject));
JsonRepresentation jsonRepresentation = new JsonRepresentation(result);
jsonResult = jsonRepresentation.getJsonObject();
if (service.getStatus().equals(Status.SUCCESS_OK))
{
return jsonResult;
} else
{
LOGGER.error("Unexpected HTTP status code returned: {}", service.getStatus().getCode());
ResponseEntity response = JsonUtil.fromJson(jsonResult, ResponseEntity.class);
throw new ServiceException(response);
}
} catch (JSONException | IOException e)
{
LOGGER.error("Unexpected Exception", e);
throw new ServiceException(e);
}
}
代码示例来源:origin: org.restlet/org.restlet.ext.atom
/**
* Posts a member to the collection resulting in the creation of a new
* resource.
*
* @param member
* The member representation to post.
* @return The reference of the new resource.
* @throws Exception
*/
public Reference postMember(Representation member) throws Exception {
final Request request = new Request(Method.POST, getHref(), member);
final Response response = getWorkspace().getService()
.getClientDispatcher().handle(request);
if (response.getStatus().equals(Status.SUCCESS_CREATED)) {
return response.getLocationRef();
} else {
throw new Exception(
"Couldn't post the member representation. Status returned: "
+ response.getStatus().getDescription());
}
}
代码示例来源: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.jee/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/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());
}
}
内容来源于网络,如有侵权,请联系作者删除!