[GitHub] nifi pull request #272: NIFI-1620 Allow empty Content-Type in InvokeHTTP pro...

2016-06-18 Thread asfgit
Github user asfgit closed the pull request at:

https://github.com/apache/nifi/pull/272


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] nifi pull request #272: NIFI-1620 Allow empty Content-Type in InvokeHTTP pro...

2016-06-15 Thread taftster
Github user taftster commented on a diff in the pull request:

https://github.com/apache/nifi/pull/272#discussion_r67284145
  
--- Diff: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/InvokeHTTP.java
 ---
@@ -761,24 +771,38 @@ private Request configureRequest(final ProcessContext 
context, final ProcessSess
 }
 
 private RequestBody getRequestBodyToSend(final ProcessSession session, 
final ProcessContext context, final FlowFile requestFlowFile) {
-return new RequestBody() {
-@Override
-public MediaType contentType() {
-String contentType = 
context.getProperty(PROP_CONTENT_TYPE).evaluateAttributeExpressions(requestFlowFile).getValue();
-contentType = StringUtils.isBlank(contentType) ? 
DEFAULT_CONTENT_TYPE : contentType;
-return MediaType.parse(contentType);
-}
+if(context.getProperty(PROP_SEND_BODY).asBoolean()) {
+return new RequestBody() {
+@Override
+public MediaType contentType() {
+String contentType = 
context.getProperty(PROP_CONTENT_TYPE).evaluateAttributeExpressions(requestFlowFile).getValue();
+contentType = StringUtils.isBlank(contentType) ? 
DEFAULT_CONTENT_TYPE : contentType;
+return MediaType.parse(contentType);
+}
 
-@Override
-public void writeTo(BufferedSink sink) throws IOException {
-session.exportTo(requestFlowFile, sink.outputStream());
-}
+@Override
+public void writeTo(BufferedSink sink) throws IOException {
+session.exportTo(requestFlowFile, sink.outputStream());
+}
 
-@Override
-public long contentLength(){
-return useChunked ? -1 : requestFlowFile.getSize();
-}
-};
+@Override
+public long contentLength(){
+return useChunked ? -1 : requestFlowFile.getSize();
+}
+};
+} else {
+return new RequestBody() {
+@Override
+public void writeTo(BufferedSink sink) throws IOException {
+sink.writeUtf8("");
+}
+
+@Override
+public MediaType contentType() {
+return MediaType.parse("");
+}
+};
--- End diff --

For this 'else' clause, it would probably be better to use a RequstBody 
static factory.  Something like:
`return RequestBody.create(null, new byte[0]);`

I'm not sure the proper way to specific an empty MediaType, though. I think 
reading the MediaType javadoc, my hunch is that MediaType.parse("") should 
return null (since empty string is an invalid type).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] nifi pull request #272: NIFI-1620 Allow empty Content-Type in InvokeHTTP pro...

2016-06-15 Thread taftster
Github user taftster commented on a diff in the pull request:

https://github.com/apache/nifi/pull/272#discussion_r67283832
  
--- Diff: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/InvokeHTTP.java
 ---
@@ -215,14 +215,23 @@
 .build();
 
 public static final PropertyDescriptor PROP_CONTENT_TYPE = new 
PropertyDescriptor.Builder()
-.name("Content-Type")
-.description("The Content-Type to specify for when content is 
being transmitted through a PUT or POST. "
-+ "In the case of an empty value after evaluating an 
expression language expression, Content-Type defaults to " + 
DEFAULT_CONTENT_TYPE)
-.required(true)
-.expressionLanguageSupported(true)
-.defaultValue("${" + CoreAttributes.MIME_TYPE.key() + "}")
-.addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
-.build();
+.name("Content-Type")
+.description("The Content-Type to specify for when content is 
being transmitted through a PUT or POST. "
++ "In the case of an empty value after evaluating an 
expression language expression, Content-Type defaults to " + 
DEFAULT_CONTENT_TYPE)
+.required(true)
+.expressionLanguageSupported(true)
+.defaultValue("${" + CoreAttributes.MIME_TYPE.key() + "}")
+
.addValidator(StandardValidators.createAttributeExpressionLanguageValidator(AttributeExpression.ResultType.STRING))
+.build();
+
--- End diff --

The changes on lines 218-226 are just whitespace changes.  Can this be 
reverted back to the original?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---