camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bo...@apache.org
Subject svn commit: r1298664 - in /camel/branches/camel-2.9.x/components/camel-solr: pom.xml src/main/java/org/apache/camel/component/solr/SolrProducer.java
Date Fri, 09 Mar 2012 00:15:22 GMT
Author: boday
Date: Fri Mar  9 00:15:22 2012
New Revision: 1298664

URL: http://svn.apache.org/viewvc?rev=1298664&view=rev
Log:
CAMEL-5071 revised the solr msg detection logic to be more efficient and changed camel-spring-test
dependency to camel-test

Modified:
    camel/branches/camel-2.9.x/components/camel-solr/pom.xml
    camel/branches/camel-2.9.x/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrProducer.java

Modified: camel/branches/camel-2.9.x/components/camel-solr/pom.xml
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-solr/pom.xml?rev=1298664&r1=1298663&r2=1298664&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-solr/pom.xml (original)
+++ camel/branches/camel-2.9.x/components/camel-solr/pom.xml Fri Mar  9 00:15:22 2012
@@ -64,7 +64,7 @@
 
     <dependency>
       <groupId>org.apache.camel</groupId>
-      <artifactId>camel-test-spring</artifactId>
+      <artifactId>camel-test</artifactId>
       <scope>test</scope>
     </dependency>
 

Modified: camel/branches/camel-2.9.x/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrProducer.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrProducer.java?rev=1298664&r1=1298663&r2=1298664&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrProducer.java
(original)
+++ camel/branches/camel-2.9.x/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrProducer.java
Fri Mar  9 00:15:22 2012
@@ -74,12 +74,6 @@ public class SolrProducer extends Defaul
 
         Object body = exchange.getIn().getBody();
 
-        boolean hasSolrHeaders = false;
-        Map<String, Object> headers = exchange.getIn().getHeaders();
-        if (headers != null && headers.containsKey(SolrConstants.FIELD + "id")) {
-            hasSolrHeaders = true;
-        }
-
         if (body instanceof File) {
 
             ContentStreamUpdateRequest updateRequest = new ContentStreamUpdateRequest(getRequestHandler());
@@ -109,43 +103,54 @@ public class SolrProducer extends Defaul
                 updateRequest.process(solrServer);
             }
 
-        } else if (hasSolrHeaders) {
-
-            UpdateRequest updateRequest = new UpdateRequest(getRequestHandler());
+        } else {
 
-            SolrInputDocument doc = new SolrInputDocument();
+            boolean hasSolrHeaders = false;
+            Map<String, Object> headers = exchange.getIn().getHeaders();
             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);
 
-            if (isStreaming) {
-                updateRequest.process(streamingSolrServer);
-            } else {
-                updateRequest.process(solrServer);
-            }
+            if (hasSolrHeaders) {
 
-        } else if (body instanceof String) {
+                UpdateRequest updateRequest = new UpdateRequest(getRequestHandler());
 
-            String bodyAsString = (String) body;
+                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);
 
-            if (!bodyAsString.startsWith("<add")) {
-                bodyAsString = "<add>" + bodyAsString + "</add>";
-            }
+                if (isStreaming) {
+                    updateRequest.process(streamingSolrServer);
+                } else {
+                    updateRequest.process(solrServer);
+                }
 
-            DirectXmlRequest xmlRequest = new DirectXmlRequest(getRequestHandler(), bodyAsString);
+            } else if (body instanceof String) {
 
-            if (isStreaming) {
-                streamingSolrServer.request(xmlRequest);
+                String bodyAsString = (String) body;
+
+                if (!bodyAsString.startsWith("<add")) {
+                    bodyAsString = "<add>" + bodyAsString + "</add>";
+                }
+
+                DirectXmlRequest xmlRequest = new DirectXmlRequest(getRequestHandler(), bodyAsString);
+
+                if (isStreaming) {
+                    streamingSolrServer.request(xmlRequest);
+                } else {
+                    solrServer.request(xmlRequest);
+                }
             } else {
-                solrServer.request(xmlRequest);
+                throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "unable to find
data in Exchange to update Solr");
             }
-
-        } else {
-            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "unable to find
data in Exchange to update Solr");
         }
     }
 



Mime
View raw message