@Override public Map<ComplexResourceKey<JobExecutionQuery, EmptyRecord>, JobExecutionQueryResult> batchGet( Set<ComplexResourceKey<JobExecutionQuery, EmptyRecord>> keys) { Map<ComplexResourceKey<JobExecutionQuery, EmptyRecord>, JobExecutionQueryResult> results = Maps.newHashMap(); for (ComplexResourceKey<JobExecutionQuery, EmptyRecord> key : keys) { JobExecutionQueryResult result = get(key); if (result != null) { results.put(key, get(key)); } } ResourceContext rc = this.getContext(); rc.setResponseHeader("Access-Control-Allow-Origin", "*"); this.setContext(rc); return results; } }
@Override public JobExecutionQueryResult get(ComplexResourceKey<JobExecutionQuery, EmptyRecord> key) { JobExecutionQuery query = key.getKey(); JobExecutionInfoArray jobExecutionInfos = new JobExecutionInfoArray(); try { for (JobExecutionInfo jobExecutionInfo : this.jobHistoryStore.get(query)) { jobExecutionInfos.add(jobExecutionInfo); } } catch (Throwable t) { LOGGER .error(String.format("Failed to execute query [id = %s, type = %s]", query.getId(), query.getIdType().name()), t); return null; } JobExecutionQueryResult result = new JobExecutionQueryResult(); result.setJobExecutions(jobExecutionInfos); ResourceContext rc = this.getContext(); rc.setResponseHeader("Access-Control-Allow-Origin", "*"); this.setContext(rc); return result; }
@Override public Map<ComplexResourceKey<JobExecutionQuery, EmptyRecord>, JobExecutionQueryResult> batchGet( Set<ComplexResourceKey<JobExecutionQuery, EmptyRecord>> keys) { Map<ComplexResourceKey<JobExecutionQuery, EmptyRecord>, JobExecutionQueryResult> results = Maps.newHashMap(); for (ComplexResourceKey<JobExecutionQuery, EmptyRecord> key : keys) { JobExecutionQueryResult result = get(key); if (result != null) { results.put(key, get(key)); } } ResourceContext rc = this.getContext(); rc.setResponseHeader("Access-Control-Allow-Origin", "*"); this.setContext(rc); return results; } }
@Override public Map<ComplexResourceKey<JobExecutionQuery, EmptyRecord>, JobExecutionQueryResult> batchGet( Set<ComplexResourceKey<JobExecutionQuery, EmptyRecord>> keys) { Map<ComplexResourceKey<JobExecutionQuery, EmptyRecord>, JobExecutionQueryResult> results = Maps.newHashMap(); for (ComplexResourceKey<JobExecutionQuery, EmptyRecord> key : keys) { JobExecutionQueryResult result = get(key); if (result != null) { results.put(key, get(key)); } } ResourceContext rc = this.getContext(); rc.setResponseHeader("Access-Control-Allow-Origin", "*"); this.setContext(rc); return results; } }
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!")); }
@Override public JobExecutionQueryResult get(ComplexResourceKey<JobExecutionQuery, EmptyRecord> key) { JobExecutionQuery query = key.getKey(); JobExecutionInfoArray jobExecutionInfos = new JobExecutionInfoArray(); try { for (JobExecutionInfo jobExecutionInfo : this.jobHistoryStore.get(query)) { jobExecutionInfos.add(jobExecutionInfo); } } catch (Throwable t) { LOGGER .error(String.format("Failed to execute query [id = %s, type = %s]", query.getId(), query.getIdType().name()), t); return null; } JobExecutionQueryResult result = new JobExecutionQueryResult(); result.setJobExecutions(jobExecutionInfos); ResourceContext rc = this.getContext(); rc.setResponseHeader("Access-Control-Allow-Origin", "*"); this.setContext(rc); return result; }
@Override public JobExecutionQueryResult get(ComplexResourceKey<JobExecutionQuery, EmptyRecord> key) { JobExecutionQuery query = key.getKey(); JobExecutionInfoArray jobExecutionInfos = new JobExecutionInfoArray(); try { for (JobExecutionInfo jobExecutionInfo : this.jobHistoryStore.get(query)) { jobExecutionInfos.add(jobExecutionInfo); } } catch (Throwable t) { LOGGER .error(String.format("Failed to execute query [id = %s, type = %s]", query.getId(), query.getIdType().name()), t); return null; } JobExecutionQueryResult result = new JobExecutionQueryResult(); result.setJobExecutions(jobExecutionInfos); ResourceContext rc = this.getContext(); rc.setResponseHeader("Access-Control-Allow-Origin", "*"); this.setContext(rc); return result; }
@Override public void get(String key, @UnstructuredDataWriterParam UnstructuredDataWriter writer) { switch (key) { case "good": respondGoodUnstructuredData(writer); break; case "goodInline": getContext().setResponseHeader(HEADER_CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE); respondGoodUnstructuredData(writer); break; case "missingHeaders": respondBadUnstructuredData(writer); break; case "exception": throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR, "internal service exception"); default: throw new RestLiServiceException(HttpStatus.S_503_SERVICE_UNAVAILABLE, "unexpected unstructured data key, something wrong with the test."); } } }
@Override public void get(CompoundKey key, @UnstructuredDataWriterParam UnstructuredDataWriter writer) { switch (key.getPartAsString("src")) { case "good": respondGoodUnstructuredData(writer); break; case "goodInline": getContext().setResponseHeader(HEADER_CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE); respondGoodUnstructuredData(writer); break; case "missingHeaders": respondBadUnstructuredData(writer); break; case "exception": throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR, "internal service exception"); default: throw new RestLiServiceException(HttpStatus.S_503_SERVICE_UNAVAILABLE, "unexpected unstructured data key, something wrong with the test."); } } }
/** * Choose a writer based on the test key */ private Writer<ByteString> chooseGreetingWriter(String key) { switch (key) { case "good": case "goodNullContentType": return new SingletonWriter<>(ByteString.copy(UNSTRUCTURED_DATA_BYTES)); case "goodMultiWrites": return new ChunkedByteStringWriter(UNSTRUCTURED_DATA_BYTES, 2); case "goodInline": getContext().setResponseHeader(HEADER_CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE); return new SingletonWriter<>(ByteString.copy(UNSTRUCTURED_DATA_BYTES)); case "bad": return new BadWriter(); case "exception": throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR, "internal service exception"); default: throw new RestLiServiceException(HttpStatus.S_503_SERVICE_UNAVAILABLE, "unexpected unstructured data key, something wrong with the test."); } }
@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!")); }