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!")); }