private Properties getHeaders() { Properties headerProperties = new Properties(); for (Map.Entry<String, String> entry : getContext().getRequestHeaders().entrySet()) { if (ALLOWED_METADATA.contains(entry.getKey())) { headerProperties.put(entry.getKey(), entry.getValue()); } } return headerProperties; } }
private Properties getHeaders() { Properties headerProperties = new Properties(); for (Map.Entry<String, String> entry : getContext().getRequestHeaders().entrySet()) { if (ALLOWED_METADATA.contains(entry.getKey())) { headerProperties.put(entry.getKey(), entry.getValue()); } } return headerProperties; } }
public static String getRealClientIpAddr(final ResourceContext context) { // If some upstream device added an X-Forwarded-For header // use it for the client ip // This will support scenarios where load balancers or gateways // front the Azkaban web server and a changing Ip address invalidates // the session final Map<String, String> headers = context.getRequestHeaders(); final WebUtils utils = new WebUtils(); return utils.getRealClientIpAddr(headers, (String) context.getRawRequestContext().getLocalAttr("REMOTE_ADDR")); } }
@Override public CreateResponse create(Greeting greeting) { Map<String, String> requestHeaders = getContext().getRequestHeaders(); if (!requestHeaders.get(TEST1_HEADER).equals(TEST1_VALUE) || !requestHeaders.get(TEST2_HEADER).equals(TEST2_VALUE)) { throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR, "Request headers are not modified from filter."); } return new CreateResponse(1234L); } }
public void create(Greeting entity, @CallbackParam Callback<CreateResponse> callback, @RestLiAttachmentsParam RestLiAttachmentReader attachmentReader) { if (attachmentReader != null) { final String headerValue = getContext().getRequestHeaders().get("createHeader"); getContext().setResponseHeader("createHeader", headerValue); attachmentReader.registerAttachmentReaderCallback(new GreetingBlobReaderCallback(callback)); return; } callback.onError(new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST, "You must supply some attachments!")); }
private void respondWithResponseAttachment(final Callback<UpdateResponse> callback) { if (getContext().responseAttachmentsSupported()) { //Echo the bytes back from the header final String headerValue = getContext().getRequestHeaders().get("getHeader"); final GreetingWriter greetingWriter = new GreetingWriter(ByteString.copy(headerValue.getBytes())); final RestLiResponseAttachments streamingAttachments = new RestLiResponseAttachments.Builder().appendSingleAttachment(greetingWriter).build(); getContext().setResponseAttachments(streamingAttachments); callback.onSuccess(new UpdateResponse(HttpStatus.S_200_OK)); } callback.onError(new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST, "You must be able to receive attachments!")); }
@Override public void get(Long key, @CallbackParam Callback<Greeting> callback) { if (getContext().responseAttachmentsSupported()) { final GreetingWriter greetingWriter = new GreetingWriter(ByteString.copy(greetingBytes)); final RestLiResponseAttachments streamingAttachments = new RestLiResponseAttachments.Builder().appendSingleAttachment(greetingWriter).build(); getContext().setResponseAttachments(streamingAttachments); final String headerValue = getContext().getRequestHeaders().get("getHeader"); getContext().setResponseHeader("getHeader", headerValue); callback.onSuccess(new Greeting().setMessage("Your greeting has an attachment since you were kind and " + "decided you wanted to read it!").setId(key)); } callback.onError(new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST, "You must be able to receive attachments!")); }
String bestEncoding = pickBestEncoding(resourceContext.getRequestHeaders().get(RestConstants.HEADER_ACCEPT), Collections.emptySet());