Refine search
@Override public Representation getRepresentation(Status status, Request request, Response response) { StringWriter st = new StringWriter(); PrintWriter pw = new PrintWriter(st); if(status.getCode()==404){ pw.append("<h1>Page not found</h1>\n"); pw.append("The page you are looking for does not exist. "+ "You may be able to recover by going " + "<a href='javascript:history.back();void(0);'>back</a>.\n"); } else{ pw.append("<h1>An error occurred</h1>\n"); pw.append( "You may be able to recover and try something " + "else by going " + "<a href='javascript:history.back();void(0);'>back</a>.\n"); if(status.getThrowable()!=null) { pw.append("<h2>Cause: "+ status.getThrowable().toString()+"</h2>\n"); pw.append("<pre>"); status.getThrowable().printStackTrace(pw); pw.append("</pre>"); } } pw.flush(); return new StringRepresentation(st.toString(),MediaType.TEXT_HTML); }
LocationRequest locationRequest = LocationRequest.create() .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); PendingResult<Status> result = LocationServices.FusedLocationApi .requestLocationUpdates( googleApiClient, // your connected GoogleApiClient locationRequest, // a request to receive a new location locationListener); // the listener which will receive updated locations // Callback is asynchronous. Use await() on a background thread or listen for // the ResultCallback result.setResultCallback(new ResultCallback<Status>() { void onResult(Status status) { if (status.isSuccess()) { // Successfully registered } else if (status.hasResolution()) { // Google provides a way to fix the issue status.startResolutionForResult( activity, // your current activity used to receive the result RESULT_CODE); // the result code you'll look for in your // onActivityResult method to retry registering } else { // No recovery. Weep softly or inform the user. Log.e(TAG, "Registering failed: " + status.getStatusMessage()); } } });
@Override public void onResult(Status status) { if (status.isSuccess()) { } else if (status.hasResolution()) { Log.e(TAG, "Registering failed: " + status.getStatusMessage());
/** * 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(); } }
/** * 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); }
@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())) { Range requestedRange = request.getRanges().get(0); if ((!response.getEntity().hasKnownSize()) && ((requestedRange.getIndex() == Range.INDEX_LAST || requestedRange.getSize() == Range.SIZE_MAX) if (response.getEntity().hasKnownSize() && requestedRange.getSize() > response.getEntity().getAvailableSize()) { requestedRange.setSize(Range.SIZE_MAX);
ClientCall httpCall) { response.setStatus(status); response.getServerInfo().setAddress(httpCall.getServerAddress()); response.getServerInfo().setPort(httpCall.getServerPort()); 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);
private HandlerCommand invokeCommand( Reference ref, Method method, Object requestObject, ResponseHandler responseHandler, ResponseHandler processingErrorHandler ) Request request = new Request( method, ref ); User user = request.getClientInfo().getUser(); if ( user != null) request.setChallengeResponse( new ChallengeResponse( ChallengeScheme.HTTP_BASIC, user.getName(), user.getSecret() ) ); Response response = new Response( request ); contextResourceFactory.getClient().handle( request, response ); if( response.getStatus().isSuccess() ) if (response.getStatus().equals(Status.CLIENT_ERROR_UNPROCESSABLE_ENTITY) && processingErrorHandler != null) response.getEntity().exhaust();
private Status createFile(Request request, File file) { // This is simple PUT of the full entity try { if (request.isEntityAvailable()) { Files.copy(request.getEntity().getStream(), file.toPath()); return SUCCESS_CREATED; } if (file.createNewFile()) { return SUCCESS_NO_CONTENT; } } catch (IOException ioe) { getLogger().log(WARNING, "Unable to create the new file", ioe); return new Status(SERVER_ERROR_INTERNAL, ioe); } String message = "Unable to create the new file"; getLogger().warning(message); return new Status(SERVER_ERROR_INTERNAL, message); }
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();
/** * 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()); }
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() ); } }
@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; }
if (throwableAnnotationInfo != null) { int statusCode = throwableAnnotationInfo.getStatus() .getCode(); Response response = new Response(); response.setCode(statusCode); response.setName(Status.valueOf(statusCode) .getReasonPhrase()); response.setMessage("Status " + statusCode);
/** * Constructor. The default status code is {@link Status#SUCCESS_OK}. */ public Response() { setCode(Status.SUCCESS_OK.getCode()); setMessage(Status.SUCCESS_OK.getDescription()); }
/** * 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()); }
/** * Indicates if the application and all its resources can be described using * WADL. * * @param remainingPart * The URI remaining part. * @param request * The request to handle. * @param response * The response to update. */ protected boolean canDescribe(String remainingPart, Request request, Response response) { return isAutoDescribing() && Method.OPTIONS.equals(request.getMethod()) && (response.getStatus().isClientError() || !response .isEntityAvailable()) && ("/".equals(remainingPart) || "".equals(remainingPart)); }
/** * Unit test for virtual hosts. * * @throws Exception */ public void testVirtualHost() throws Exception { // Instantiate our Restlet component MailServerComponent component = new MailServerComponent(); // Prepare a mock HTTP call Request request = new Request(); request.setMethod(Method.GET); request.setResourceRef("http://www.rmep.org/accounts/"); request.setHostRef("http://www.rmep.org"); Response response = new Response(request); response.getServerInfo().setAddress("1.2.3.10"); response.getServerInfo().setPort(80); component.handle(request, response); // Test if response was successful assertTrue(response.getStatus().isSuccess()); }