[cxf] 01/03: CXF-8669: Multipart annotation not working 3.4.6 onwards (#1078)

2023-03-04 Thread reta
This is an automated email from the ASF dual-hosted git repository.

reta pushed a commit to branch 3.4.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit 62fc36d08e0d26b4bef16ce656b848832ac1cf09
Author: Andriy Redko 
AuthorDate: Sat Mar 4 11:49:19 2023 -0500

CXF-8669: Multipart annotation not working 3.4.6 onwards (#1078)

(cherry picked from commit 5b32eaf34f5a233d0ad8c69d82b30b4ba10eecb6)
(cherry picked from commit aaf798079d1504dcd64d0685e84a011c4410adb3)
(cherry picked from commit 8ddf1331bab97b07bc40cd1486fbf0196b33688f)
---
 .../cxf/attachment/AttachmentDataSource.java   |   6 +-
 .../cxf/attachment/AttachmentDeserializer.java |   2 +-
 .../org/apache/cxf/attachment/AttachmentUtil.java  |  23 -
 .../java/org/apache/cxf/message/MessageUtils.java  |  12 +++
 .../cxf/attachment/AttachmentDeserializerTest.java | 101 +
 .../apache/cxf/jaxrs/ext/MessageContextImpl.java   |   3 +-
 .../security/wss4j/AttachmentCallbackHandler.java  |  13 ++-
 7 files changed, 151 insertions(+), 9 deletions(-)

diff --git 
a/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java 
b/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java
index ae9ca10ec2..a50a8ac4f7 100644
--- a/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java
+++ b/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java
@@ -32,7 +32,6 @@ import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.message.Message;
 
 public class AttachmentDataSource implements DataSource {
-
 private String ct;
 private CachedOutputStream cache;
 private InputStream ins;
@@ -78,9 +77,10 @@ public class AttachmentDataSource implements DataSource {
 
 public String getContentType() {
 if (StringUtils.isEmpty(ct)) {
-ct = "application/octet-stream";
+return "application/octet-stream";
+} else {
+return ct;
 }
-return ct;
 }
 
 public InputStream getInputStream() {
diff --git 
a/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java 
b/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
index 0f7f6b890f..53a77c505d 100644
--- a/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
+++ b/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
@@ -325,7 +325,7 @@ public class AttachmentDeserializer {
   this);
 createCount++;
 
-return AttachmentUtil.createAttachment(partStream, headers);
+return AttachmentUtil.createAttachment(partStream, headers, message);
 }
 
 public boolean isLazyLoading() {
diff --git a/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java 
b/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
index 942c3a9833..802ef87e9c 100644
--- a/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
+++ b/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
@@ -66,6 +66,10 @@ import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageUtils;
 
 public final class AttachmentUtil {
+// The default values for {@link AttachmentDataSource} content type in 
case when
+// "Content-Type" header is not present.
+public static final String ATTACHMENT_CONTENT_TYPE = 
"org.apache.cxf.attachment.content-type"; 
+
 // The xop:include "href" attribute 
(https://www.w3.org/TR/xop10/#xop_href) may include 
 // arbitrary URL which we should never follow (unless explicitly allowed).
 public static final String ATTACHMENT_XOP_FOLLOW_URLS_PROPERTY = 
"org.apache.cxf.attachment.xop.follow.urls";
@@ -388,14 +392,27 @@ public final class AttachmentUtil {
 static String getHeader(Map> headers, String h, 
String delim) {
 return getHeaderValue(headers.get(h), delim);
 }
-public static Attachment createAttachment(InputStream stream, Map> headers)
-throws IOException {
+
+/**
+ * @deprecated use createAttachment(InputStream stream, Map> headers, Message message)
+ */
+public static Attachment createAttachment(InputStream stream, Map> headers) 
+throws IOException {
+return createAttachment(stream, headers, null /* no Message */);
+}
+
+public static Attachment createAttachment(InputStream stream, Map> headers, Message message)
+throws IOException {
 
 String id = cleanContentId(getHeader(headers, "Content-ID"));
 
 AttachmentImpl att = new AttachmentImpl(id);
 
-final String ct = getHeader(headers, "Content-Type");
+String ct = getHeader(headers, "Content-Type");
+if (StringUtils.isEmpty(ct)) {
+ct = MessageUtils.getContextualString(message, 
ATTACHMENT_CONTENT_TYPE, "application/octet-stream");
+}
+
 String cd = getHeader(headers, "Content-Disposition");
 String fileName 

[cxf] 01/03: CXF-8669: Multipart annotation not working 3.4.6 onwards (#1078)

2023-03-04 Thread reta
This is an automated email from the ASF dual-hosted git repository.

reta pushed a commit to branch 3.5.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit 8ddf1331bab97b07bc40cd1486fbf0196b33688f
Author: Andriy Redko 
AuthorDate: Sat Mar 4 11:49:19 2023 -0500

CXF-8669: Multipart annotation not working 3.4.6 onwards (#1078)

(cherry picked from commit 5b32eaf34f5a233d0ad8c69d82b30b4ba10eecb6)
(cherry picked from commit aaf798079d1504dcd64d0685e84a011c4410adb3)
---
 .../cxf/attachment/AttachmentDataSource.java   |   6 +-
 .../cxf/attachment/AttachmentDeserializer.java |   2 +-
 .../org/apache/cxf/attachment/AttachmentUtil.java  |  23 -
 .../java/org/apache/cxf/message/MessageUtils.java  |  12 +++
 .../cxf/attachment/AttachmentDeserializerTest.java | 101 +
 .../apache/cxf/jaxrs/ext/MessageContextImpl.java   |   3 +-
 .../security/wss4j/AttachmentCallbackHandler.java  |  13 ++-
 7 files changed, 151 insertions(+), 9 deletions(-)

diff --git 
a/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java 
b/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java
index a10c6821bc..7d7939b055 100644
--- a/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java
+++ b/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java
@@ -32,7 +32,6 @@ import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.message.Message;
 
 public class AttachmentDataSource implements DataSource {
-
 private String ct;
 private CachedOutputStream cache;
 private InputStream ins;
@@ -78,9 +77,10 @@ public class AttachmentDataSource implements DataSource {
 
 public String getContentType() {
 if (StringUtils.isEmpty(ct)) {
-ct = "application/octet-stream";
+return "application/octet-stream";
+} else {
+return ct;
 }
-return ct;
 }
 
 public InputStream getInputStream() {
diff --git 
a/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java 
b/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
index 55a1dcc63b..4b2ddea4e9 100644
--- a/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
+++ b/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
@@ -324,7 +324,7 @@ public class AttachmentDeserializer {
   this);
 createCount++;
 
-return AttachmentUtil.createAttachment(partStream, headers);
+return AttachmentUtil.createAttachment(partStream, headers, message);
 }
 
 public boolean isLazyLoading() {
diff --git a/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java 
b/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
index 7ff0734645..e0eaf88213 100644
--- a/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
+++ b/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
@@ -66,6 +66,10 @@ import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageUtils;
 
 public final class AttachmentUtil {
+// The default values for {@link AttachmentDataSource} content type in 
case when
+// "Content-Type" header is not present.
+public static final String ATTACHMENT_CONTENT_TYPE = 
"org.apache.cxf.attachment.content-type"; 
+
 // The xop:include "href" attribute 
(https://www.w3.org/TR/xop10/#xop_href) may include 
 // arbitrary URL which we should never follow (unless explicitly allowed).
 public static final String ATTACHMENT_XOP_FOLLOW_URLS_PROPERTY = 
"org.apache.cxf.attachment.xop.follow.urls";
@@ -394,14 +398,27 @@ public final class AttachmentUtil {
 static String getHeader(Map> headers, String h, 
String delim) {
 return getHeaderValue(headers.get(h), delim);
 }
-public static Attachment createAttachment(InputStream stream, Map> headers)
-throws IOException {
+
+/**
+ * @deprecated use createAttachment(InputStream stream, Map> headers, Message message)
+ */
+public static Attachment createAttachment(InputStream stream, Map> headers) 
+throws IOException {
+return createAttachment(stream, headers, null /* no Message */);
+}
+
+public static Attachment createAttachment(InputStream stream, Map> headers, Message message)
+throws IOException {
 
 String id = cleanContentId(getHeader(headers, "Content-ID"));
 
 AttachmentImpl att = new AttachmentImpl(id);
 
-final String ct = getHeader(headers, "Content-Type");
+String ct = getHeader(headers, "Content-Type");
+if (StringUtils.isEmpty(ct)) {
+ct = MessageUtils.getContextualString(message, 
ATTACHMENT_CONTENT_TYPE, "application/octet-stream");
+}
+
 String cd = getHeader(headers, "Content-Disposition");
 String fileName = getContentDispositionFileName(cd);
 
diff --git