Refine search
private String getUsecaseName( Request request ) { if( request.getMethod().equals( org.restlet.data.Method.DELETE ) ) { return "delete"; } else { return request.getResourceRef().getLastSegment(); } }
/** * Returns the name. * * @return The name. */ @Override public String toString() { return getName(); } }
/** * Displays a synthesis of the request like an HTTP request line. * * @return A synthesis of the request like an HTTP request line. */ public String toString() { return ((getMethod() == null) ? "" : getMethod().toString()) + " " + ((getResourceRef() == null) ? "" : getResourceRef() .toString()) + " " + ((getProtocol() == null) ? "" : (getProtocol().getName() + ((getProtocol() .getVersion() == null) ? "" : "/" + getProtocol().getVersion()))); }
MDC.put( "url", request.getResourceRef().toString() ); Reference ref = request.getResourceRef(); List<String> segments = ref.getScheme() .equals( "riap" ) ? ref.getRelativeRef( new Reference( "riap://application/" ) ) .getSegments() : ref.getRelativeRef().getSegments(); if( request.getMethod().equals( Method.DELETE ) ) else if( request.getMethod().equals( Method.PUT ) ) .withMetaInfo( request.getMethod().isSafe() ? CacheOptions.ALWAYS : CacheOptions.NEVER ) .newUsecase(); UnitOfWork uow = uowf.newUnitOfWork( usecase ); resource.handle( request, response ); if( response.getEntity() != null ) if( response.getEntity().getModificationDate() == null ) if( response.getEntity().getCharacterSet() == null ) response.getEntity().setCharacterSet( CharacterSet.UTF_8 );
private void handleQuery( String segment ) Request request = Request.getCurrent(); Response response = Response.getCurrent(); response.setStatus( Status.REDIRECTION_FOUND ); response .setLocationRef( new Reference( request .getResourceRef() .toString() + "/" ).toString() ); return; .getMethod() .isSafe() && queryMethod.getParameterTypes().length != 0 && request .getResourceRef() .getQuery() == null ) || ( !request .getMethod() .isSafe() && queryMethod.getParameterTypes().length != 0 && !( request .getEntity() .isAvailable() || request .getResourceRef() .getQuery() != null || queryMethod
String clientAddress = request.getClientInfo().getUpstreamAddress(); sb.append((clientAddress == null) ? "-" : clientAddress); sb.append('\t'); String serverAddress = response.getServerInfo().getAddress(); sb.append((serverAddress == null) ? "-" : serverAddress); sb.append('\t'); .getMethod().getName(); sb.append((methodName == null) ? "-" : methodName); : request.getResourceRef().getPath(); sb.append((resourcePath == null) ? "-" : resourcePath); : request.getResourceRef().getQuery(); sb.append((resourceQuery == null) ? "-" : resourceQuery); .toString(response.getStatus().getCode())); || Status.REDIRECTION_NOT_MODIFIED.equals(response.getStatus()) || Status.SUCCESS_NO_CONTENT.equals(response.getStatus()) || Method.HEAD.equals(request.getMethod())) { sb.append('0'); } else { sb.append((response.getEntity().getSize() == -1) ? "-" : Long .toString(response.getEntity().getSize())); .toString());
/** * 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(); } }
@Override public Object resolve(String variableName) { Object result = (this.response != null) ? this.response.getAttributes().get(variableName) : null; if (result != null) { return result; result = (this.request != null) ? this.request.getAttributes().get(variableName) : null; if (result != null) { return result; ChallengeResponse cr = this.request.getChallengeResponse(); Representation entity = this.request.getEntity(); return getModificationDateAsString(entity); case "emt": return (entity != null && entity.getMediaType() != null) ? entity.getMediaType().getName() : null; return (this.request.getMethod() != null) ? this.request.getMethod().getName() : null; Representation entity = this.response.getEntity(); Status status = this.response.getStatus(); return (status != null) ? Integer.toString(status.getCode()) : null; case "SIA": return serverInfo.getAddress();
@Override public void handle(Request request, Response response) { try { if (Protocol.FTP.equals(request.getProtocol())) { if (Method.GET.equals(request.getMethod())) { Reference ftpRef = request.getResourceRef(); String userInfo = null; ftpRef.setUserInfo(userInfo); URL url = ftpRef.toUrl(); URLConnection connection = url.openConnection(); .setAllowUserInteraction(isAllowUserInteraction()); connection.setUseCaches(isUseCaches()); response.setEntity(new InputRepresentation(connection .getInputStream())); Entity.updateMetadata(request.getResourceRef().getPath(), response.getEntity(), true, getMetadataService()); } else { getLogger() response.setStatus(Status.CONNECTOR_ERROR_INTERNAL, e.getMessage());
MetadataService metadataService = getMetadataService(); if (request.getMethod().equals(Method.GET) || request.getMethod().equals(Method.HEAD)) { String path = request.getResourceRef().getPath(); URL url = null; Date modificationDate = null; url = bundle.getResource(Reference.decode(path)); } else { getLogger() url.openStream(), metadataService.getDefaultMediaType()); output.setLocationRef(request.getResourceRef()); output.setModificationDate(modificationDate); output.setExpirationDate(null); } else if (timeToLive > 0) { output.setExpirationDate(new Date(System response.setEntity(output); response.setStatus(Status.SUCCESS_OK); } catch (IOException ioe) { getLogger().log(Level.WARNING, "Unable to open the representation's input stream", ioe); response.setStatus(Status.SERVER_ERROR_INTERNAL);
this.relativePart = getReference().getRemainingPart(false, false); this.originalRef = getOriginalRef(); if (this.originalRef != null) { Reference originalBaseRef = new Reference(this.originalRef); originalBaseRef.setPath(getReference().getBaseRef().getPath()); this.originalRef.setBaseRef(originalBaseRef); this.relativePart = this.originalRef.getRemainingPart(false, false); if (contextResponse.getEntity() != null) { if (MediaType.TEXT_URI_LIST.equals(contextResponse.getEntity().getMediaType())) { this.directoryTarget = true; this.fileTarget = false; this.directoryContent = tryToConvertAsReferenceList(contextResponse.getEntity()); if (!getReference().getPath().endsWith("/")) { if (!fileTarget || fileContent == null || !getRequest().getMethod().isSafe()) { if ((contextResponse.getEntity() != null) && MediaType.TEXT_URI_LIST.equals(contextResponse.getEntity().getMediaType())) { this.directoryContent = tryToConvertAsReferenceList(contextResponse.getEntity());
if (response.getServerInfo().isAcceptingRanges()) { addHeader(HEADER_ACCEPT_RANGES, RANGE_BYTES_UNIT, headers); if (response.getAge() > 0) { addHeader(HEADER_AGE, Integer.toString(response.getAge()), headers); if (CLIENT_ERROR_METHOD_NOT_ALLOWED.equals(response.getStatus()) || OPTIONS.equals(response.getRequest().getMethod())) { addHeader(HEADER_ALLOW, MethodWriter.write(response.getAllowedMethods()), headers); if (response.getLocationRef() != null) { addHeader(HEADER_LOCATION, response.getLocationRef().getTargetRef().toString(), headers); if (!((response.getRequest().getClientInfo().getAgent() != null) && response .getRequest().getClientInfo().getAgent().contains("MSIE"))) { addHeader(HEADER_VARY, DimensionWriter.write(response.getDimensions()), headers);
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();
@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);
/** * Creates a low-level HTTP client call from a high-level uniform call. * * @param request * The high-level request. * @return A low-level HTTP client call. */ @Override public ClientCall create(Request request) { ClientCall result = null; try { result = new HttpMethodCall(this, request.getMethod().toString(), ReferenceUtils.update(request.getResourceRef(), request) .toString(), request.isEntityAvailable()); } catch (IOException ioe) { getLogger().log(Level.WARNING, "Unable to create the HTTP client call", ioe); } return result; }
@Override protected int beforeHandle(Request request, Response response) { Cookie cookie = request.getCookies().getFirst("Credentials"); if (cookie != null) { // Extract the challenge response from the cookie String[] credentials = cookie.getValue().split("="); if (credentials.length == 2) { String identifier = credentials[0]; String secret = credentials[1]; request.setChallengeResponse(new ChallengeResponse( ChallengeScheme.HTTP_COOKIE, identifier, secret)); } } else if (Method.POST.equals(request.getMethod()) && request.getResourceRef().getQueryAsForm().getFirst("login") != null) { // Intercepting a login form Form credentials = new Form(request.getEntity()); String identifier = credentials.getFirstValue("identifier"); String secret = credentials.getFirstValue("secret"); request.setChallengeResponse(new ChallengeResponse( ChallengeScheme.HTTP_COOKIE, identifier, secret)); // Continue call processing to return the target representation if // authentication is successful or a new login page request.setMethod(Method.GET); } return super.beforeHandle(request, response); }
private boolean shouldShowCommandForm( Method interactionMethod ) { // Show form on GET/HEAD if( Request.getCurrent().getMethod().isSafe() ) { return true; } if( interactionMethod.getParameterTypes().length > 0 ) { return !( interactionMethod.getParameterTypes()[ 0 ].equals( Response.class ) || Request.getCurrent() .getEntity() .isAvailable() || Request.getCurrent().getEntityAsText() != null || Request.getCurrent() .getResourceRef() .getQuery() != null ); } return false; }
if (!Method.GET.equals(method) && !Method.HEAD.equals(method)) { return null; this.fileContent.setLocationRef(getRequest().getOriginalRef()); } else { this.fileContent.setLocationRef(getReference()); && (getReference().getBaseRef() != null)) { for (Reference ref : getVariantsReferences()) { Response contextResponse = getRepresentation(ref.toString()); if (contextResponse.getStatus().isSuccess() && (contextResponse.getEntity() != null)) { filePath = ref.toString(false, false).substring(rootLength); Representation rep = contextResponse.getEntity(); rep.setLocationRef(baseReference + filePath); } else { rep.setLocationRef(baseReference + "/" + filePath);
TunnelService tunnelService = getTunnelService(); boolean queryModified = false; Reference resourceRef = request.getResourceRef(); if (resourceRef.hasQuery()) { Form query = resourceRef.getQueryAsForm(CharacterSet.UTF_8); Method method = request.getMethod(); if (tunnelService.isMethodTunnel()) { String methodName = query.getFirstValue(tunnelService .getMethodParameter()); Method tunnelledMethod = Method.valueOf(methodName); && (Method.POST.equals(method) || Method.OPTIONS .equals(tunnelledMethod))) { request.setMethod(tunnelledMethod); query.removeFirst(tunnelService.getMethodParameter()); queryModified = true; request.getResourceRef().setQuery(query.getQueryString(CharacterSet.UTF_8));
String origin = request.getHeaders().getFirstValue("Origin", true); Set<Method> allowedMethods = new HashSet<>(response.getAllowedMethods()); response.getAllowedMethods().clear(); boolean isPreflightRequest = Method.OPTIONS.equals(request.getMethod()); if (Status.SUCCESS_OK.equals(response.getStatus()) || Status.SUCCESS_NO_CONTENT.equals(response.getStatus()) || Status.CLIENT_ERROR_METHOD_NOT_ALLOWED.equals(response .getStatus())) { response.setStatus(Status.SUCCESS_OK); Method requestedMethod = request.getAccessControlRequestMethod(); if (requestedMethod == null) {