camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject camel git commit: CAMEL-9736 SolrComponent gets the wrong Content Type
Date Thu, 24 Mar 2016 14:56:57 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.17.x 58ee935ee -> 8cea456b5


CAMEL-9736 SolrComponent gets the wrong Content Type


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/8cea456b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/8cea456b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/8cea456b

Branch: refs/heads/camel-2.17.x
Commit: 8cea456b5a0f0739b1e5b3eff5795a1e022627cd
Parents: 58ee935
Author: Andrea Cosentino <ancosen@gmail.com>
Authored: Thu Mar 24 15:54:38 2016 +0100
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Thu Mar 24 15:56:32 2016 +0100

----------------------------------------------------------------------
 .../camel/component/solr/SolrProducer.java      | 108 +++++++++++--------
 1 file changed, 64 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/8cea456b/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrProducer.java
b/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrProducer.java
index 7d0f32b..0052b7d 100644
--- a/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrProducer.java
+++ b/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrProducer.java
@@ -26,6 +26,7 @@ import javax.activation.MimetypesFileTypeMap;
 import org.apache.camel.Exchange;
 import org.apache.camel.WrappedFile;
 import org.apache.camel.impl.DefaultProducer;
+import org.apache.camel.util.ObjectHelper;
 import org.apache.solr.client.solrj.SolrClient;
 import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest;
 import org.apache.solr.client.solrj.request.DirectXmlRequest;
@@ -41,13 +42,14 @@ public class SolrProducer extends DefaultProducer {
     private SolrClient concSolrServer;
     private SolrClient cloudSolrServer;
 
-    public SolrProducer(SolrEndpoint endpoint, SolrClient solrServer, SolrClient concSolrServer,
SolrClient cloudSolrServer) {
+    public SolrProducer(SolrEndpoint endpoint, SolrClient solrServer, SolrClient concSolrServer,
+            SolrClient cloudSolrServer) {
         super(endpoint);
         this.httpServer = solrServer;
         this.concSolrServer = concSolrServer;
         this.cloudSolrServer = cloudSolrServer;
     }
-    
+
     private SolrClient getBestSolrServer(String operation) {
         if (this.cloudSolrServer != null) {
             return this.cloudSolrServer;
@@ -66,7 +68,7 @@ public class SolrProducer extends DefaultProducer {
         if (operation == null) {
             throw new IllegalArgumentException(SolrConstants.OPERATION + " header is missing");
         }
-        
+
         SolrClient serverToUse = getBestSolrServer(operation);
 
         if (operation.equalsIgnoreCase(SolrConstants.OPERATION_INSERT)) {
@@ -88,7 +90,8 @@ public class SolrProducer extends DefaultProducer {
         } else if (operation.equalsIgnoreCase(SolrConstants.OPERATION_OPTIMIZE)) {
             serverToUse.optimize();
         } else {
-            throw new IllegalArgumentException(SolrConstants.OPERATION + " header value '"
+ operation + "' is not supported");
+            throw new IllegalArgumentException(
+                    SolrConstants.OPERATION + " header value '" + operation + "' is not supported");
         }
     }
 
@@ -96,12 +99,11 @@ public class SolrProducer extends DefaultProducer {
         Object body = exchange.getIn().getBody();
         boolean invalid = false;
         if (body instanceof WrappedFile) {
-            body = ((WrappedFile<?>)body).getFile();
+            body = ((WrappedFile<?>) body).getFile();
         }
 
-        if (body instanceof File) {
-            MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
-            String mimeType = mimeTypesMap.getContentType((File)body);
+        if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Exchange.CONTENT_TYPE, String.class)))
{
+            String mimeType = exchange.getIn().getHeader(Exchange.CONTENT_TYPE, String.class);
             ContentStreamUpdateRequest updateRequest = new ContentStreamUpdateRequest(getRequestHandler());
             updateRequest.addFile((File) body, mimeType);
 
@@ -113,68 +115,86 @@ public class SolrProducer extends DefaultProducer {
             }
 
             updateRequest.process(solrServer);
+        } else {
 
-        } else if (body instanceof SolrInputDocument) {
+            if (body instanceof File) {
+                MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
+                String mimeType = mimeTypesMap.getContentType((File) body);
+                ContentStreamUpdateRequest updateRequest = new ContentStreamUpdateRequest(getRequestHandler());
+                updateRequest.addFile((File) body, mimeType);
 
-            UpdateRequest updateRequest = new UpdateRequest(getRequestHandler());
-            updateRequest.add((SolrInputDocument) body);
+                for (Map.Entry<String, Object> entry : exchange.getIn().getHeaders().entrySet())
{
+                    if (entry.getKey().startsWith(SolrConstants.PARAM)) {
+                        String paramName = entry.getKey().substring(SolrConstants.PARAM.length());
+                        updateRequest.setParam(paramName, entry.getValue().toString());
+                    }
+                }
 
-            updateRequest.process(solrServer);
+                updateRequest.process(solrServer);
 
-        } else if (body instanceof List<?>) {
-            List<?> list = (List<?>) body;
+            } else if (body instanceof SolrInputDocument) {
 
-            if (list.size() > 0 && list.get(0) instanceof SolrInputDocument) {
                 UpdateRequest updateRequest = new UpdateRequest(getRequestHandler());
-                updateRequest.add((List<SolrInputDocument>) list);
+                updateRequest.add((SolrInputDocument) body);
 
                 updateRequest.process(solrServer);
-            } else {
-                invalid = true;
-            }
 
-        } else {
+            } else if (body instanceof List<?>) {
+                List<?> list = (List<?>) body;
 
-            boolean hasSolrHeaders = false;
-            for (Map.Entry<String, Object> entry : exchange.getIn().getHeaders().entrySet())
{
-                if (entry.getKey().startsWith(SolrConstants.FIELD)) {
-                    hasSolrHeaders = true;
-                    break;
-                }
-            }
+                if (list.size() > 0 && list.get(0) instanceof SolrInputDocument)
{
+                    UpdateRequest updateRequest = new UpdateRequest(getRequestHandler());
+                    updateRequest.add((List<SolrInputDocument>) list);
 
-            if (hasSolrHeaders) {
+                    updateRequest.process(solrServer);
+                } else {
+                    invalid = true;
+                }
 
-                UpdateRequest updateRequest = new UpdateRequest(getRequestHandler());
+            } else {
 
-                SolrInputDocument doc = new SolrInputDocument();
+                boolean hasSolrHeaders = false;
                 for (Map.Entry<String, Object> entry : exchange.getIn().getHeaders().entrySet())
{
                     if (entry.getKey().startsWith(SolrConstants.FIELD)) {
-                        String fieldName = entry.getKey().substring(SolrConstants.FIELD.length());
-                        doc.setField(fieldName, entry.getValue());
+                        hasSolrHeaders = true;
+                        break;
                     }
                 }
-                updateRequest.add(doc);
-                updateRequest.process(solrServer);
 
-            } else if (body instanceof String) {
+                if (hasSolrHeaders) {
 
-                String bodyAsString = (String) body;
+                    UpdateRequest updateRequest = new UpdateRequest(getRequestHandler());
 
-                if (!bodyAsString.startsWith("<add")) {
-                    bodyAsString = "<add>" + bodyAsString + "</add>";
-                }
+                    SolrInputDocument doc = new SolrInputDocument();
+                    for (Map.Entry<String, Object> entry : exchange.getIn().getHeaders().entrySet())
{
+                        if (entry.getKey().startsWith(SolrConstants.FIELD)) {
+                            String fieldName = entry.getKey().substring(SolrConstants.FIELD.length());
+                            doc.setField(fieldName, entry.getValue());
+                        }
+                    }
+                    updateRequest.add(doc);
+                    updateRequest.process(solrServer);
 
-                DirectXmlRequest xmlRequest = new DirectXmlRequest(getRequestHandler(), bodyAsString);
+                } else if (body instanceof String) {
 
-                solrServer.request(xmlRequest);
-            } else {
-                invalid = true;
+                    String bodyAsString = (String) body;
+
+                    if (!bodyAsString.startsWith("<add")) {
+                        bodyAsString = "<add>" + bodyAsString + "</add>";
+                    }
+
+                    DirectXmlRequest xmlRequest = new DirectXmlRequest(getRequestHandler(),
bodyAsString);
+
+                    solrServer.request(xmlRequest);
+                } else {
+                    invalid = true;
+                }
             }
         }
 
         if (invalid) {
-            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "unable to find
data in Exchange to update Solr");
+            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
+                    "unable to find data in Exchange to update Solr");
         }
     }
 


Mime
View raw message