You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2016/04/29 11:51:59 UTC
camel git commit: CAMEL-9874: Camel Jetty consumer endpoint
incorrectly handles multipart/form-data
Repository: camel
Updated Branches:
refs/heads/camel-2.17.x f4964e3f0 -> 9d7824bda
CAMEL-9874: Camel Jetty consumer endpoint incorrectly handles multipart/form-data
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/9d7824bd
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/9d7824bd
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/9d7824bd
Branch: refs/heads/camel-2.17.x
Commit: 9d7824bda32ff3be174600e344ad0f2a183d7a6d
Parents: f4964e3
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Apr 29 11:51:51 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Apr 29 11:51:51 2016 +0200
----------------------------------------------------------------------
.../component/jetty8/AttachmentHttpBinding.java | 83 ++++++++++++++++++++
.../component/jetty8/JettyHttpEndpoint8.java | 22 ++++++
2 files changed, 105 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/9d7824bd/components/camel-jetty8/src/main/java/org/apache/camel/component/jetty8/AttachmentHttpBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty8/src/main/java/org/apache/camel/component/jetty8/AttachmentHttpBinding.java b/components/camel-jetty8/src/main/java/org/apache/camel/component/jetty8/AttachmentHttpBinding.java
new file mode 100644
index 0000000..2476097
--- /dev/null
+++ b/components/camel-jetty8/src/main/java/org/apache/camel/component/jetty8/AttachmentHttpBinding.java
@@ -0,0 +1,83 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jetty8;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Collection;
+import javax.activation.DataHandler;
+import javax.activation.DataSource;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.Part;
+
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.http.common.DefaultHttpBinding;
+import org.apache.camel.http.common.HttpMessage;
+import org.eclipse.jetty.util.MultiPartInputStream;
+
+final class AttachmentHttpBinding extends DefaultHttpBinding {
+
+ AttachmentHttpBinding() {
+ }
+
+ @Override
+ protected void populateAttachments(HttpServletRequest request, HttpMessage message) {
+ Object object = request.getAttribute("org.eclipse.jetty.servlet.MultiPartFile.multiPartInputStream");
+ if (object instanceof MultiPartInputStream) {
+ MultiPartInputStream parser = (MultiPartInputStream)object;
+ Collection<Part> parts;
+ try {
+ parts = parser.getParts();
+ for (Part part : parts) {
+ DataSource ds = new PartDataSource(part);
+ message.addAttachment(part.getName(), new DataHandler(ds));
+ }
+ } catch (Exception e) {
+ throw new RuntimeCamelException("Cannot populate attachments", e);
+ }
+ }
+ }
+
+ final class PartDataSource implements DataSource {
+ private final Part part;
+
+ PartDataSource(Part part) {
+ this.part = part;
+ }
+
+ @Override
+ public OutputStream getOutputStream() throws IOException {
+ return null;
+ }
+
+ @Override
+ public String getName() {
+ return part.getName();
+ }
+
+ @Override
+ public InputStream getInputStream() throws IOException {
+ return part.getInputStream();
+ }
+
+ @Override
+ public String getContentType() {
+ return part.getContentType();
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/9d7824bd/components/camel-jetty8/src/main/java/org/apache/camel/component/jetty8/JettyHttpEndpoint8.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty8/src/main/java/org/apache/camel/component/jetty8/JettyHttpEndpoint8.java b/components/camel-jetty8/src/main/java/org/apache/camel/component/jetty8/JettyHttpEndpoint8.java
index c6d766f..fe44d42 100644
--- a/components/camel-jetty8/src/main/java/org/apache/camel/component/jetty8/JettyHttpEndpoint8.java
+++ b/components/camel-jetty8/src/main/java/org/apache/camel/component/jetty8/JettyHttpEndpoint8.java
@@ -22,6 +22,7 @@ import java.net.URISyntaxException;
import org.apache.camel.component.jetty.JettyContentExchange;
import org.apache.camel.component.jetty.JettyHttpComponent;
import org.apache.camel.component.jetty.JettyHttpEndpoint;
+import org.apache.camel.http.common.HttpBinding;
import org.apache.camel.http.common.HttpConsumer;
import org.apache.camel.spi.UriEndpoint;
@@ -31,12 +32,33 @@ import org.apache.camel.spi.UriEndpoint;
@UriEndpoint(scheme = "jetty", extendsScheme = "http", title = "Jetty",
syntax = "jetty:httpUri", consumerClass = HttpConsumer.class, label = "http", lenientProperties = true)
public class JettyHttpEndpoint8 extends JettyHttpEndpoint {
+ private HttpBinding binding;
public JettyHttpEndpoint8(JettyHttpComponent component, String uri, URI httpURL) throws URISyntaxException {
super(component, uri, httpURL);
}
@Override
+ public HttpBinding getHttpBinding() {
+ // make sure we include jetty9 variant of the http binding
+ if (this.binding == null) {
+ this.binding = new AttachmentHttpBinding();
+ this.binding.setTransferException(isTransferException());
+ if (getComponent() != null) {
+ this.binding.setAllowJavaSerializedObject(getComponent().isAllowJavaSerializedObject());
+ }
+ this.binding.setHeaderFilterStrategy(getHeaderFilterStrategy());
+ }
+ return this.binding;
+ }
+
+ @Override
+ public void setHttpBinding(HttpBinding binding) {
+ super.setHttpBinding(binding);
+ this.binding = binding;
+ }
+
+ @Override
public JettyContentExchange createContentExchange() {
return new JettyContentExchange8();
}