Author: boday
Date: Fri Mar 9 00:05:28 2012
New Revision: 1298660
URL: http://svn.apache.org/viewvc?rev=1298660&view=rev
Log:
CAMEL-5071 tweaked the solr message type detection logic to be more efficient
Modified:
camel/trunk/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrProducer.java
Modified:
camel/trunk/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrProducer.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrProducer.java?rev=1298660&r1=1298659&r2=1298660&view=diff
==============================================================================
---
camel/trunk/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrProducer.java
(original)
+++
camel/trunk/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrProducer.java
Fri Mar 9 00:05:28 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");
}
}