Permalink
Browse files

Checking in rest.li streaming

RB=599196
G=si-dev
R=gogenc
A=gogenc
  • Loading branch information...
1 parent ee9afbc commit 873bd97c0c68b5cceb16da8ef40d007a470fa953 @kvidhani kvidhani committed Apr 6, 2016
Showing with 9,728 additions and 1,866 deletions.
  1. +1 −1 multipart-mime/src/main/java/com/linkedin/multipart/MultiPartMIMEChainReaderCallback.java
  2. +2 −2 multipart-mime/src/main/java/com/linkedin/multipart/MultiPartMIMEChainReaderWriter.java
  3. +2 −2 multipart-mime/src/main/java/com/linkedin/multipart/MultiPartMIMEDataSourceIterator.java
  4. +1 −1 multipart-mime/src/main/java/com/linkedin/multipart/MultiPartMIMEDataSourceIteratorCallback.java
  5. +51 −51 multipart-mime/src/main/java/com/linkedin/multipart/MultiPartMIMEReader.java
  6. +3 −3 multipart-mime/src/main/java/com/linkedin/multipart/MultiPartMIMEReaderCallback.java
  7. +52 −9 multipart-mime/src/main/java/com/linkedin/multipart/MultiPartMIMEStreamRequestFactory.java
  8. +48 −7 multipart-mime/src/main/java/com/linkedin/multipart/MultiPartMIMEStreamResponseFactory.java
  9. +2 −2 multipart-mime/src/main/java/com/linkedin/multipart/MultiPartMIMEUtils.java
  10. +73 −7 multipart-mime/src/main/java/com/linkedin/multipart/MultiPartMIMEWriter.java
  11. +2 −2 multipart-mime/src/main/java/com/linkedin/multipart/SinglePartMIMEChainReaderCallback.java
  12. +2 −2 multipart-mime/src/main/java/com/linkedin/multipart/SinglePartMIMEReaderCallback.java
  13. +1 −1 multipart-mime/src/main/java/com/linkedin/multipart/exceptions/MultiPartIllegalFormatException.java
  14. +1 −1 multipart-mime/src/test/java/com/linkedin/multipart/TestMIMEChainingAlternate.java
  15. +2 −2 multipart-mime/src/test/java/com/linkedin/multipart/TestMIMEChainingReader.java
  16. +1 −1 multipart-mime/src/test/java/com/linkedin/multipart/TestMIMEChainingSinglePart.java
  17. +1 −1 multipart-mime/src/test/java/com/linkedin/multipart/TestMIMEInputStream.java
  18. +5 −5 multipart-mime/src/test/java/com/linkedin/multipart/TestMIMEReader.java
  19. +22 −22 multipart-mime/src/test/java/com/linkedin/multipart/TestMIMEReaderClientCallbackExceptions.java
  20. +76 −76 ...mime/src/test/java/com/linkedin/multipart/{TestMIMEReaderAbandon.java → TestMIMEReaderDrain.java}
  21. +3 −3 multipart-mime/src/test/java/com/linkedin/multipart/TestMIMEReaderExceptions.java
  22. +2 −2 multipart-mime/src/test/java/com/linkedin/multipart/TestMIMEReaderR2Error.java
  23. +12 −12 multipart-mime/src/test/java/com/linkedin/multipart/TestMIMEReaderStateTransitions.java
  24. +107 −4 multipart-mime/src/test/java/com/linkedin/multipart/TestMIMEWriter.java
  25. +3 −3 multipart-mime/src/test/java/com/linkedin/multipart/TestMIMEWriterAbandonDataSources.java
  26. +2 −2 multipart-mime/src/test/java/com/linkedin/multipart/integ/TestMIMEChainingMultipleSources.java
  27. +3 −3 multipart-mime/src/test/java/com/linkedin/multipart/integ/TestMIMEIntegrationReader.java
  28. +96 −95 ...din/multipart/integ/{TestMIMEIntegrationReaderAbandon.java → TestMIMEIntegrationReaderDrain.java}
  29. +3 −3 multipart-mime/src/test/java/com/linkedin/multipart/integ/TestMIMEIntegrationReaderWriter.java
  30. +26 −14 multipart-mime/src/test/java/com/linkedin/multipart/utils/MIMETestUtils.java
  31. +18 −1 restli-client-testutils/src/main/java/com/linkedin/restli/client/testutils/MockResponseBuilder.java
  32. +2 −0 restli-client/build.gradle
  33. +6 −7 restli-client/src/main/java/com/linkedin/restli/client/AbstractRequestBuilder.java
  34. +5 −2 restli-client/src/main/java/com/linkedin/restli/client/ActionRequest.java
  35. +30 −2 restli-client/src/main/java/com/linkedin/restli/client/ActionRequestBuilder.java
  36. +5 −3 restli-client/src/main/java/com/linkedin/restli/client/BatchCreateIdEntityRequest.java
  37. +28 −1 restli-client/src/main/java/com/linkedin/restli/client/BatchCreateIdEntityRequestBuilder.java
  38. +4 −2 restli-client/src/main/java/com/linkedin/restli/client/BatchCreateIdRequest.java
  39. +28 −1 restli-client/src/main/java/com/linkedin/restli/client/BatchCreateIdRequestBuilder.java
  40. +4 −2 restli-client/src/main/java/com/linkedin/restli/client/BatchCreateRequest.java
  41. +28 −1 restli-client/src/main/java/com/linkedin/restli/client/BatchCreateRequestBuilder.java
  42. +3 −1 restli-client/src/main/java/com/linkedin/restli/client/BatchDeleteRequest.java
  43. +0 −1 restli-client/src/main/java/com/linkedin/restli/client/BatchDeleteRequestBuilder.java
  44. +2 −1 restli-client/src/main/java/com/linkedin/restli/client/BatchGetEntityRequest.java
  45. +1 −2 restli-client/src/main/java/com/linkedin/restli/client/BatchGetEntityRequestBuilder.java
  46. +12 −1 restli-client/src/main/java/com/linkedin/restli/client/BatchGetKVRequest.java
  47. +2 −1 restli-client/src/main/java/com/linkedin/restli/client/BatchGetRequest.java
  48. +4 −2 restli-client/src/main/java/com/linkedin/restli/client/BatchPartialUpdateRequest.java
  49. +31 −2 restli-client/src/main/java/com/linkedin/restli/client/BatchPartialUpdateRequestBuilder.java
  50. +13 −11 restli-client/src/main/java/com/linkedin/restli/client/BatchRequest.java
  51. +4 −3 restli-client/src/main/java/com/linkedin/restli/client/BatchUpdateRequest.java
  52. +29 −3 restli-client/src/main/java/com/linkedin/restli/client/BatchUpdateRequestBuilder.java
  53. +6 −2 restli-client/src/main/java/com/linkedin/restli/client/CreateIdEntityRequest.java
  54. +33 −1 restli-client/src/main/java/com/linkedin/restli/client/CreateIdEntityRequestBuilder.java
  55. +4 −2 restli-client/src/main/java/com/linkedin/restli/client/CreateIdRequest.java
  56. +31 −1 restli-client/src/main/java/com/linkedin/restli/client/CreateIdRequestBuilder.java
  57. +5 −5 restli-client/src/main/java/com/linkedin/restli/client/CreateRequest.java
  58. +31 −1 restli-client/src/main/java/com/linkedin/restli/client/CreateRequestBuilder.java
  59. +2 −1 restli-client/src/main/java/com/linkedin/restli/client/DeleteRequest.java
  60. +2 −2 restli-client/src/main/java/com/linkedin/restli/client/FindRequest.java
  61. +2 −1 restli-client/src/main/java/com/linkedin/restli/client/GetAllRequest.java
  62. +2 −2 restli-client/src/main/java/com/linkedin/restli/client/GetRequest.java
  63. +2 −2 restli-client/src/main/java/com/linkedin/restli/client/OptionsRequest.java
  64. +7 −7 restli-client/src/main/java/com/linkedin/restli/client/PartialUpdateRequest.java
  65. +31 −3 restli-client/src/main/java/com/linkedin/restli/client/PartialUpdateRequestBuilder.java
  66. +45 −26 restli-client/src/main/java/com/linkedin/restli/client/Request.java
  67. +13 −0 restli-client/src/main/java/com/linkedin/restli/client/Response.java
  68. +319 −66 restli-client/src/main/java/com/linkedin/restli/client/RestClient.java
  69. +96 −0 restli-client/src/main/java/com/linkedin/restli/client/RestLiStreamCallbackAdapter.java
  70. +30 −11 restli-client/src/main/java/com/linkedin/restli/client/RestliRequestOptions.java
  71. +10 −2 restli-client/src/main/java/com/linkedin/restli/client/RestliRequestOptionsBuilder.java
  72. +0 −1 restli-client/src/main/java/com/linkedin/restli/client/SingleEntityRequestBuilder.java
  73. +7 −7 restli-client/src/main/java/com/linkedin/restli/client/UpdateRequest.java
  74. +31 −1 restli-client/src/main/java/com/linkedin/restli/client/UpdateRequestBuilder.java
  75. +17 −1 restli-client/src/main/java/com/linkedin/restli/client/base/ActionRequestBuilderBase.java
  76. +16 −0 ...i-client/src/main/java/com/linkedin/restli/client/base/BatchCreateIdEntityRequestBuilderBase.java
  77. +17 −1 restli-client/src/main/java/com/linkedin/restli/client/base/BatchCreateIdRequestBuilderBase.java
  78. +18 −1 restli-client/src/main/java/com/linkedin/restli/client/base/BatchCreateRequestBuilderBase.java
  79. +18 −2 ...li-client/src/main/java/com/linkedin/restli/client/base/BatchPartialUpdateRequestBuilderBase.java
  80. +17 −2 restli-client/src/main/java/com/linkedin/restli/client/base/BatchUpdateRequestBuilderBase.java
  81. +19 −1 restli-client/src/main/java/com/linkedin/restli/client/base/CreateIdEntityRequestBuilderBase.java
  82. +16 −0 restli-client/src/main/java/com/linkedin/restli/client/base/CreateIdRequestBuilderBase.java
  83. +18 −1 restli-client/src/main/java/com/linkedin/restli/client/base/CreateRequestBuilderBase.java
  84. +17 −1 restli-client/src/main/java/com/linkedin/restli/client/base/PartialUpdateRequestBuilderBase.java
  85. +16 −1 restli-client/src/main/java/com/linkedin/restli/client/base/UpdateRequestBuilderBase.java
  86. +1 −10 restli-client/src/main/java/com/linkedin/restli/client/util/RestliBuilderUtils.java
  87. +19 −0 restli-client/src/main/java/com/linkedin/restli/internal/client/ResponseImpl.java
  88. +220 −10 restli-client/src/main/java/com/linkedin/restli/internal/client/RestResponseDecoder.java
  89. +1 −1 restli-client/src/test/java/com/linkedin/restli/client/BatchGetRequestBuilderTest.java
  90. +246 −55 restli-client/src/test/java/com/linkedin/restli/client/TestClientBuilders.java
  91. +8 −12 restli-client/src/test/java/com/linkedin/restli/client/TestRequest.java
  92. +1,045 −515 restli-client/src/test/java/com/linkedin/restli/client/TestRestClientRequestBuilder.java
  93. +4 −0 restli-common/build.gradle
  94. +2 −0 restli-common/src/main/java/com/linkedin/restli/common/RestConstants.java
  95. +38 −0 ...common/src/main/java/com/linkedin/restli/common/attachments/RestLiAttachmentDataSourceWriter.java
  96. +406 −0 restli-common/src/main/java/com/linkedin/restli/common/attachments/RestLiAttachmentReader.java
  97. +54 −0 ...i-common/src/main/java/com/linkedin/restli/common/attachments/RestLiAttachmentReaderCallback.java
  98. +38 −0 ...-common/src/main/java/com/linkedin/restli/common/attachments/RestLiAttachmentReaderException.java
  99. +40 −0 restli-common/src/main/java/com/linkedin/restli/common/attachments/RestLiDataSourceIterator.java
  100. +55 −0 ...common/src/main/java/com/linkedin/restli/common/attachments/RestLiDataSourceIteratorCallback.java
  101. +60 −0 ...on/src/main/java/com/linkedin/restli/common/attachments/SingleRestLiAttachmentReaderCallback.java
  102. +208 −0 restli-common/src/main/java/com/linkedin/restli/internal/common/AttachmentUtils.java
  103. +137 −0 restli-common/src/test/java/com/linkedin/restli/common/attachments/TestRestLiAttachmentReader.java
  104. +229 −0 restli-common/src/test/java/com/linkedin/restli/internal/common/TestAttachmentUtils.java
  105. +5 −3 restli-docgen/src/main/java/com/linkedin/restli/docgen/DefaultDocumentationRequestHandler.java
  106. +33 −0 ...t-api/src/main/idl/com.linkedin.restli.examples.greetings.client.streamingGreetings.restspec.json
  107. +57 −0 .../src/main/snapshot/com.linkedin.restli.examples.greetings.client.streamingGreetings.snapshot.json
  108. +50 −4 restli-int-test-server/src/main/java/com/linkedin/restli/examples/RestLiIntTestServer.java
  109. +234 −0 ...t-test-server/src/main/java/com/linkedin/restli/examples/greetings/server/StreamingGreetings.java
  110. +1 −0 restli-int-test-server/src/test/java/com/linkedin/restli/docgen/TestResourceSchemaCollection.java
  111. +12 −0 restli-int-test/src/main/java/com/linkedin/restli/test/util/RootBuilderWrapper.java
  112. +14 −1 restli-int-test/src/test/java/com/linkedin/restli/examples/RestLiIntegrationTest.java
  113. +1 −0 restli-int-test/src/test/java/com/linkedin/restli/examples/TestComplexKeysResource.java
  114. +7 −5 restli-int-test/src/test/java/com/linkedin/restli/examples/TestCompressionServer.java
  115. +9 −8 restli-int-test/src/test/java/com/linkedin/restli/examples/TestRequestCompression.java
  116. +8 −7 restli-int-test/src/test/java/com/linkedin/restli/examples/TestResponseCompression.java
  117. +371 −0 restli-int-test/src/test/java/com/linkedin/restli/examples/TestStreamingGreetings.java
  118. +147 −0 ...estutils/src/test/java/com/linkedin/restli/internal/testutils/RestLiTestAttachmentDataSource.java
  119. +85 −0 .../src/test/java/com/linkedin/restli/internal/testutils/RestLiTestAttachmentDataSourceIterator.java
  120. +3 −1 restli-server-extras/build.gradle
  121. +73 −26 restli-server-extras/src/main/java/com/linkedin/restli/server/ParseqTraceDebugRequestHandler.java
  122. +266 −80 ...li-server-extras/src/test/java/com/linkedin/restli/server/TestParseqTraceDebugRequestHandler.java
  123. +2 −0 restli-server/build.gradle
  124. +49 −5 restli-server/src/main/java/com/linkedin/restli/internal/server/ResourceContextImpl.java
  125. +28 −16 restli-server/src/main/java/com/linkedin/restli/internal/server/RestLiCallback.java
  126. +80 −34 restli-server/src/main/java/com/linkedin/restli/internal/server/RestLiMethodInvoker.java
  127. +3 −3 restli-server/src/main/java/com/linkedin/restli/internal/server/RestLiResponseHandler.java
  128. +19 −2 restli-server/src/main/java/com/linkedin/restli/internal/server/RestLiRouter.java
  129. +14 −3 restli-server/src/main/java/com/linkedin/restli/internal/server/ServerResourceContext.java
  130. +11 −2 ...li-server/src/main/java/com/linkedin/restli/internal/server/filter/RestLiResponseFilterChain.java
  131. +6 −1 ...r/src/main/java/com/linkedin/restli/internal/server/filter/RestLiResponseFilterChainCallback.java
  132. +19 −3 ...i-server/src/main/java/com/linkedin/restli/internal/server/methods/arguments/ArgumentBuilder.java
  133. +2 −1 restli-server/src/main/java/com/linkedin/restli/internal/server/model/Parameter.java
  134. +56 −10 restli-server/src/main/java/com/linkedin/restli/internal/server/model/RestLiAnnotationReader.java
  135. +21 −1 restli-server/src/main/java/com/linkedin/restli/internal/server/util/MIMEParse.java
  136. +15 −14 restli-server/src/main/java/com/linkedin/restli/internal/server/util/RestUtils.java
  137. +33 −6 restli-server/src/main/java/com/linkedin/restli/server/BaseRestServer.java
  138. +12 −3 restli-server/src/main/java/com/linkedin/restli/server/RequestExecutionCallback.java
  139. +44 −17 restli-server/src/main/java/com/linkedin/restli/server/ResourceContext.java
  140. +22 −4 restli-server/src/main/java/com/linkedin/restli/server/RestLiDebugRequestHandler.java
  141. +6 −4 restli-server/src/main/java/com/linkedin/restli/server/RestLiDocumentationRequestHandler.java
  142. +114 −0 restli-server/src/main/java/com/linkedin/restli/server/RestLiResponseAttachments.java
  143. +550 −24 restli-server/src/main/java/com/linkedin/restli/server/RestLiServer.java
  144. +54 −0 restli-server/src/main/java/com/linkedin/restli/server/annotations/RestLiAttachmentsParam.java
  145. +2 −2 restli-server/src/main/java/com/linkedin/restli/server/multiplexer/MultiplexedRequestHandler.java
  146. +3 −2 ...li-server/src/main/java/com/linkedin/restli/server/multiplexer/MultiplexedRequestHandlerImpl.java
  147. +80 −49 restli-server/src/test/java/com/linkedin/restli/internal/server/TestRestLiCallback.java
  148. +21 −10 ...erver/src/test/java/com/linkedin/restli/internal/server/filter/TestRestLiResponseFilterChain.java
  149. +53 −19 ...t/java/com/linkedin/restli/internal/server/methods/arguments/RestLiArgumentBuilderTestHelper.java
  150. +11 −8 ...rc/test/java/com/linkedin/restli/internal/server/methods/arguments/TestActionArgumentBuilder.java
  151. +121 −20 ...rver/src/test/java/com/linkedin/restli/internal/server/methods/arguments/TestArgumentBuilder.java
  152. +5 −3 ...st/java/com/linkedin/restli/internal/server/methods/arguments/TestBatchCreateArgumentBuilder.java
  153. +5 −3 ...st/java/com/linkedin/restli/internal/server/methods/arguments/TestBatchDeleteArgumentBuilder.java
  154. +5 −3 .../test/java/com/linkedin/restli/internal/server/methods/arguments/TestBatchGetArgumentBuilder.java
  155. +7 −4 ...est/java/com/linkedin/restli/internal/server/methods/arguments/TestBatchPatchArgumentBuilder.java
  156. +8 −5 ...st/java/com/linkedin/restli/internal/server/methods/arguments/TestBatchUpdateArgumentBuilder.java
  157. +38 −11 ...est/java/com/linkedin/restli/internal/server/methods/arguments/TestCollectionArgumentBuilder.java
  158. +4 −2 ...rc/test/java/com/linkedin/restli/internal/server/methods/arguments/TestCreateArgumentBuilder.java
  159. +9 −6 ...r/src/test/java/com/linkedin/restli/internal/server/methods/arguments/TestGetArgumentBuilder.java
  160. +5 −4 ...src/test/java/com/linkedin/restli/internal/server/methods/arguments/TestPatchArgumentBuilder.java
  161. +4 −3 ...rc/test/java/com/linkedin/restli/internal/server/methods/arguments/TestUpdateArgumentBuilder.java
  162. +3 −2 ...test/java/com/linkedin/restli/internal/server/methods/response/TestCollectionResponseBuilder.java
  163. +163 −25 ...erver/src/test/java/com/linkedin/restli/internal/server/model/TestRestLiParameterAnnotations.java
  164. +52 −4 restli-server/src/test/java/com/linkedin/restli/internal/server/util/TestMIMEParse.java
  165. +23 −8 restli-server/src/test/java/com/linkedin/restli/internal/server/util/TestRestUtils.java
  166. +64 −0 restli-server/src/test/java/com/linkedin/restli/server/TestRestLiResponseAttachments.java
  167. +1,233 −164 restli-server/src/test/java/com/linkedin/restli/server/TestRestLiServer.java
  168. +44 −4 restli-server/src/test/java/com/linkedin/restli/server/test/TestResourceContext.java
  169. +472 −30 restli-server/src/test/java/com/linkedin/restli/server/test/TestRestLiMethodInvocation.java
  170. +1 −1 restli-server/src/test/java/com/linkedin/restli/server/test/TestRestLiResourceModels.java
  171. +122 −20 restli-server/src/test/java/com/linkedin/restli/server/test/TestRestLiRouting.java
  172. +19 −7 restli-server/src/test/java/com/linkedin/restli/server/twitter/AsyncStatusCollectionResource.java
  173. +14 −5 restli-server/src/test/java/com/linkedin/restli/server/twitter/PromiseStatusCollectionResource.java
  174. +16 −6 restli-server/src/test/java/com/linkedin/restli/server/twitter/StatusCollectionResource.java
  175. +12 −1 restli-server/src/test/java/com/linkedin/restli/server/twitter/TaskStatusCollectionResource.java
@@ -93,7 +93,7 @@ public void onFinished()
}
@Override
- public void onAbandoned()
+ public void onAbandonComplete()
{
//This can happen if the MultiPartMIMEDataSourceIterator this callback was registered with was used as a data source and it was
//told to abandon and the abandon finished.
@@ -57,7 +57,7 @@ public void onWritePossible()
_multiPartMIMEChainReaderCallback =
new MultiPartMIMEChainReaderCallback(_writeHandle, _normalEncapsulationBoundary);
//Since this is not a MultiPartMIMEDataSourceWriter we can't use the regular mechanism for reading data.
- //Instead of create a new callback that will use to write to the writeHandle using the SinglePartMIMEReader.
+ //Instead, create a new callback that will be used to write to the writeHandle using the SinglePartMIMEReader.
_multiPartMIMEDataSourceIterator.registerDataSourceReaderCallback(_multiPartMIMEChainReaderCallback);
//Note that by registering here, this will eventually lead to onNewDataSource() which will then requestPartData()
@@ -85,6 +85,6 @@ public void onAbort(Throwable e)
//Regardless of how it was called we need to completely drain and drop all bytes to the ground. We can't
//leave these bytes in the MultiPartMIMEDataSourceIterator untouched.
- _multiPartMIMEDataSourceIterator.abortAllDataSources();
+ _multiPartMIMEDataSourceIterator.abandonAllDataSources();
}
}
@@ -26,10 +26,10 @@
public interface MultiPartMIMEDataSourceIterator
{
/**
- * Invoked when all the potential data sources that this MultiPartMIMEDataSourceIterator represents need to be aborted
+ * Invoked when all the potential data sources that this MultiPartMIMEDataSourceIterator represents need to be abandoned
* since they will not give given a chance to produce data.
*/
- public void abortAllDataSources();
+ public void abandonAllDataSources();
/**
* Invoked as the first step to walk through all potential data sources represented by this MultiPartMIMEDataSourceIterator.
@@ -44,7 +44,7 @@
* Invoked when all data sources represented by this {@link com.linkedin.multipart.MultiPartMIMEDataSourceIterator}
* have finished being abandoned.
*/
- public void onAbandoned();
+ public void onAbandonComplete();
/**
* Invoked when there was a problem producing the next data source.
Oops, something went wrong.
@@ -40,10 +40,10 @@
public void onFinished();
/**
- * Invoked as a result of calling {@link com.linkedin.multipart.MultiPartMIMEReader#abandonAllParts()}. This will be invoked
- * at some time in the future when all the parts from this multipart mime envelope are abandoned.
+ * Invoked as a result of calling {@link com.linkedin.multipart.MultiPartMIMEReader#drainAllParts()}. This will be invoked
+ * at some time in the future when all the parts from this multipart mime envelope are completely drained.
*/
- public void onAbandoned();
+ public void onDrainComplete();
/**
* Invoked when there was an error reading from the multipart envelope.
@@ -22,11 +22,12 @@
import java.net.URI;
import java.util.Collections;
+import java.util.List;
import java.util.Map;
/**
- * A wrapper to enforce creating a proper multipart mime{@link com.linkedin.r2.message.stream.StreamRequest}
+ * A wrapper to enforce creating a proper multipart mime{@link com.linkedin.r2.message.stream.StreamRequest}.
*
* @author Karim Vidhani
*/
@@ -35,6 +36,8 @@
/**
* Create a {@link com.linkedin.r2.message.stream.StreamRequest} using the specified parameters. This API should be used
* if the user does not have a need to define a {@link com.linkedin.r2.message.stream.StreamRequestBuilder} in advance.
+ * The result of this method will generate a StreamRequest using the specified URI, an HTTP method of
+ * {@link com.linkedin.r2.message.rest.RestMethod#POST}, a single header representing the generated Content-Type and no cookies.
*
* @param uri the target URI to be used.
* @param mimeSubType the mime subtype of the multipart to be used. For example, 'mixed' would result in a Content-Type of
@@ -46,19 +49,24 @@
public static StreamRequest generateMultiPartMIMEStreamRequest(final URI uri, final String mimeSubType,
final MultiPartMIMEWriter writer)
{
- return generateMultiPartMIMEStreamRequest(mimeSubType, writer, Collections.<String, String>emptyMap(), new StreamRequestBuilder(uri));
+ return generateMultiPartMIMEStreamRequest(mimeSubType, writer, Collections.<String, String>emptyMap(),
+ new StreamRequestBuilder(uri).setMethod("POST"));
}
/**
* Create a {@link com.linkedin.r2.message.stream.StreamRequest} using the specified parameters. This API should be used
* if the user does not have a need to define a {@link com.linkedin.r2.message.stream.StreamRequestBuilder} in advance.
+ * The result of this method will generate a StreamRequest using the specified URI, an HTTP method of
+ * {@link com.linkedin.r2.message.rest.RestMethod#POST}, a single header representing the generated Content-Type and no cookies.
*
* @param uri the target URI to be used.
* @param mimeSubType the mime subtype of the multipart to be used. For example, 'mixed' would result in a Content-Type of
* 'multipart/mixed'. It is generally good practice to use subtypes described in RFC 1341, although
* this API does not enforce this.
* @param writer the {@link com.linkedin.multipart.MultiPartMIMEWriter} to use for the payload of the request.
- * @param contentTypeParameters any additional parameters needed when constructing the Content-Type header.
+ * @param contentTypeParameters any additional parameters (i.e "charset") needed when constructing the Content-Type header. These
+ * parameters are added after the following prefix: "multipart/<mimeSubType>; boundary=<boundary>;".
+ * For more details please refer to RFC 822.
* @return the newly created {@link com.linkedin.r2.message.stream.StreamRequest}.
*/
public static StreamRequest generateMultiPartMIMEStreamRequest(final URI uri, final String mimeSubType,
@@ -70,26 +78,61 @@ public static StreamRequest generateMultiPartMIMEStreamRequest(final URI uri, fi
/**
* Create a {@link com.linkedin.r2.message.stream.StreamRequest} using the specified parameters. This API should be used
+ * if the user has a need to specify custom HTTP method, headers or cookies in advance. The exception to this rule is
+ * the Content-Type header which this API will override.
+ *
+ * @param uri the target URI to be used.
+ * @param mimeSubType the mime subtype of the multipart to be used. For example, 'mixed' would result in a Content-Type of
+ * 'multipart/mixed'. It is generally good practice to use subtypes described in RFC 1341, although
+ * this API does not enforce this.
+ * @param writer the {@link com.linkedin.multipart.MultiPartMIMEWriter} to use for the payload of the request.
+ * @param contentTypeParameters any additional parameters (i.e "charset") needed when constructing the Content-Type header. These
+ * parameters are added after the following prefix: "multipart/<mimeSubType>; boundary=<boundary>;".
+ * For more details please refer to RFC 822.
+ * @param method the HTTP method to use for the request. Details can be found at {@link com.linkedin.r2.message.rest.RestMethod}.
+ * @param headers a {@link java.util.Map} specifying the headers to be a part of the final
+ * {@link com.linkedin.r2.message.stream.StreamRequest}.
+ * @param cookies a {@link java.util.List} of cookies to be placed in the request.
+ * @return the newly created {@link com.linkedin.r2.message.stream.StreamRequest}.
+ */
+ public static StreamRequest generateMultiPartMIMEStreamRequest(final URI uri, final String mimeSubType,
+ final MultiPartMIMEWriter writer,
+ final Map<String, String> contentTypeParameters,
+ final String method,
+ final Map<String, String> headers,
+ final List<String> cookies)
+ {
+ return generateMultiPartMIMEStreamRequest(mimeSubType, writer, contentTypeParameters,
+ new StreamRequestBuilder(uri).setHeaders(headers).setMethod(method).setCookies(cookies));
+ }
+
+ /**
+ * Private utility implementation.
+ *
+ * Create a {@link com.linkedin.r2.message.stream.StreamRequest} using the specified parameters. This API should be used
* if the user has a need to define a {@link com.linkedin.r2.message.stream.StreamRequestBuilder} in advance. For example
* if the user wants to add specific headers or modify the StreamRequest before it is built, then this API should be used.
+ * The exception to this rule is the Content-Type header which this API will override.
*
* @param mimeSubType the mime subtype of the multipart to be used. For example, 'mixed' would result in a Content-Type of
* 'multipart/mixed'. It is generally good practice to use subtypes described in RFC 1341, although
* this API does not enforce this.
* @param writer the {@link com.linkedin.multipart.MultiPartMIMEWriter} to use for the payload of the request.
- * @param contentTypeParameters any additional parameters needed when constructing the Content-Type header.
+ * @param contentTypeParameters any additional parameters (i.e "charset") needed when constructing the Content-Type header. These
+ * parameters are added after the following prefix: "multipart/<mimeSubType>; boundary=<boundary>;".
+ * For more details please refer to RFC 822.
* @param streamRequestBuilder the {@link com.linkedin.r2.message.stream.StreamRequestBuilder} to begin with in order to
* construct the final {@link com.linkedin.r2.message.stream.StreamRequest}.
* @return the newly created {@link com.linkedin.r2.message.stream.StreamRequest}.
*/
- public static StreamRequest generateMultiPartMIMEStreamRequest(final String mimeSubType,
- final MultiPartMIMEWriter writer,
- final Map<String, String> contentTypeParameters,
- final StreamRequestBuilder streamRequestBuilder)
+ private static StreamRequest generateMultiPartMIMEStreamRequest(final String mimeSubType,
+ final MultiPartMIMEWriter writer,
+ final Map<String, String> contentTypeParameters,
+ final StreamRequestBuilder streamRequestBuilder)
{
final String contentTypeHeader =
MultiPartMIMEUtils.buildMIMEContentTypeHeader(mimeSubType.trim(), writer.getBoundary(), contentTypeParameters);
- streamRequestBuilder.addHeaderValue(MultiPartMIMEUtils.CONTENT_TYPE_HEADER, contentTypeHeader);
+ streamRequestBuilder.setHeader(MultiPartMIMEUtils.CONTENT_TYPE_HEADER, contentTypeHeader);
return streamRequestBuilder.build(writer.getEntityStream());
}
@@ -21,11 +21,12 @@
import com.linkedin.r2.message.stream.StreamResponseBuilder;
import java.util.Collections;
+import java.util.List;
import java.util.Map;
/**
- * A wrapper to enforce creating a proper multipart mime {@link com.linkedin.r2.message.stream.StreamResponse}
+ * A wrapper to enforce creating a proper multipart mime {@link com.linkedin.r2.message.stream.StreamResponse}.
*
* @author Karim Vidhani
*/
@@ -34,6 +35,8 @@
/**
* Create a {@link com.linkedin.r2.message.stream.StreamResponse} using the specified parameters. This API should be used
* if the user does not have a need to define a {@link com.linkedin.r2.message.stream.StreamResponseBuilder} in advance.
+ * The result of this method will generate a StreamResponse with a status of {@link com.linkedin.r2.message.rest.RestStatus#OK},
+ * a single header representing the generated Content-Type and no cookies.
*
* @param mimeSubType the mime subtype of the multipart to be used. For example, 'mixed' would result in a Content-Type of
* 'multipart/mixed'. It is generally good practice to use subtypes described in RFC 1341, although
@@ -49,12 +52,16 @@ public static StreamResponse generateMultiPartMIMEStreamResponse(final String mi
/**
* Create a {@link com.linkedin.r2.message.stream.StreamResponse} using the specified parameters. This API should be used
* if the user does not have a need to define a {@link com.linkedin.r2.message.stream.StreamResponseBuilder} in advance.
+ * The result of this method will generate a StreamResponse with a status of {@link com.linkedin.r2.message.rest.RestStatus#OK},
+ * a single header representing the generated Content-Type and no cookies.
*
* @param mimeSubType the mime subtype of the multipart to be used. For example, 'mixed' would result in a Content-Type of
* 'multipart/mixed'. It is generally good practice to use subtypes described in RFC 1341, although
* this API does not enforce this.
* @param writer the {@link com.linkedin.multipart.MultiPartMIMEWriter} to use for the payload of the response.
- * @param contentTypeParameters any additional parameters needed when constructing the Content-Type header.
+ * @param contentTypeParameters any additional parameters (i.e "charset") needed when constructing the Content-Type header. These
+ * parameters are added after the following prefix: "multipart/<mimeSubType>; boundary=<boundary>;".
+ * For more details please refer to RFC 822.
* @return the newly created {@link com.linkedin.r2.message.stream.StreamResponse}.
*/
public static StreamResponse generateMultiPartMIMEStreamResponse(final String mimeSubType, final MultiPartMIMEWriter writer,
@@ -65,25 +72,59 @@ public static StreamResponse generateMultiPartMIMEStreamResponse(final String mi
/**
* Create a {@link com.linkedin.r2.message.stream.StreamResponse} using the specified parameters. This API should be used
+ * if the user has a need to specify custom headers, status or cookies in advance. The exception to this rule is the
+ * Content-Type header which this API will override.
+ *
+ * @param mimeSubType the mime subtype of the multipart to be used. For example, 'mixed' would result in a Content-Type of
+ * 'multipart/mixed'. It is generally good practice to use subtypes described in RFC 1341, although
+ * this API does not enforce this.
+ * @param writer the {@link com.linkedin.multipart.MultiPartMIMEWriter} to use for the payload of the response.
+ * @param contentTypeParameters any additional parameters (i.e "charset") needed when constructing the Content-Type header. These
+ * parameters are added after the following prefix: "multipart/<mimeSubType>; boundary=<boundary>;".
+ * For more details please refer to RFC 822.
+ * @param headers a {@link java.util.Map} specifying the headers to be a part of the final
+ * {@link com.linkedin.r2.message.stream.StreamResponse}.
+ * @param status an integer representing the status for the response.
+ * @param cookies a {@link java.util.List} of cookies to be placed in the response.
+ * @return the newly created {@link com.linkedin.r2.message.stream.StreamResponse}.
+ */
+ public static StreamResponse generateMultiPartMIMEStreamResponse(final String mimeSubType,
+ final MultiPartMIMEWriter writer,
+ final Map<String, String> contentTypeParameters,
+ final Map<String, String> headers,
+ final int status,
+ final List<String> cookies)
+ {
+ return generateMultiPartMIMEStreamResponse(mimeSubType, writer, contentTypeParameters,
+ new StreamResponseBuilder().setHeaders(headers).setStatus(status).setCookies(cookies));
+ }
+
+ /**
+ * Private utility implementation.
+ *
+ * Create a {@link com.linkedin.r2.message.stream.StreamResponse} using the specified parameters. This API should be used
* if the user has a need to define a {@link com.linkedin.r2.message.stream.StreamResponseBuilder} in advance. For example
* if the user wants to add specific headers or modify the StreamResponse before it is built, then this API should be used.
+ * The exception to this rule is the Content-Type header which this API will override.
*
* @param mimeSubType the mime subtype of the multipart to be used. For example, 'mixed' would result in a Content-Type of
* 'multipart/mixed'. It is generally good practice to use subtypes described in RFC 1341, although
* this API does not enforce this.
* @param writer the {@link com.linkedin.multipart.MultiPartMIMEWriter} to use for the payload of the response.
- * @param contentTypeParameters any additional parameters needed when constructing the Content-Type header.
+ * @param contentTypeParameters any additional parameters (i.e "charset") needed when constructing the Content-Type header. These
+ * parameters are added after the following prefix: "multipart/<mimeSubType>; boundary=<boundary>;".
+ * For more details please refer to RFC 822.
* @param streamResponseBuilder the {@link com.linkedin.r2.message.stream.StreamResponseBuilder} to begin with in order to
* construct the final {@link com.linkedin.r2.message.stream.StreamResponse}.
* @return the newly created {@link com.linkedin.r2.message.stream.StreamResponse}.
*/
- public static StreamResponse generateMultiPartMIMEStreamResponse(final String mimeSubType, final MultiPartMIMEWriter writer,
- final Map<String, String> contentTypeParameters,
- final StreamResponseBuilder streamResponseBuilder)
+ private static StreamResponse generateMultiPartMIMEStreamResponse(final String mimeSubType, final MultiPartMIMEWriter writer,
+ final Map<String, String> contentTypeParameters,
+ final StreamResponseBuilder streamResponseBuilder)
{
final String contentTypeHeader =
MultiPartMIMEUtils.buildMIMEContentTypeHeader(mimeSubType.trim(), writer.getBoundary(), contentTypeParameters);
- streamResponseBuilder.addHeaderValue(MultiPartMIMEUtils.CONTENT_TYPE_HEADER, contentTypeHeader);
+ streamResponseBuilder.setHeader(MultiPartMIMEUtils.CONTENT_TYPE_HEADER, contentTypeHeader);
return streamResponseBuilder.build(writer.getEntityStream());
}
Oops, something went wrong.

0 comments on commit 873bd97

Please sign in to comment.