[
https://issues.apache.org/jira/browse/CAMEL-9736?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15208334#comment-15208334
]
Mansour Al Akeel commented on CAMEL-9736:
-----------------------------------------
Claus,
You are right. It can be done in either Exchange.CONTENT_TYPE or
Exchange.FILE_CONTENT_TYPE
The reason I proposed it, is because there are other cases where it is working
properly. The only issue I faced is when file is in the body.
Therefore, it made sense "to me" to use FILE_CONTENT_TYPE for only that case !
What if the body is SolrInputDocument, List of Files, or List of
SolrInputDocument ?
I guess setting the request content-type (Exchange.CONTENT_TYPE), would be
great.
95 private void insert(Exchange exchange, SolrClient solrServer) throws
Exception {
96 Object body = exchange.getIn().getBody();
97 boolean invalid = false;
98 if (body instanceof WrappedFile) {
99 body = ((WrappedFile<?>)body).getFile();
100 }
101
102 if (body instanceof File) {
103 MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
104 String mimeType = mimeTypesMap.getContentType((File)body);
105 ContentStreamUpdateRequest updateRequest = new
ContentStreamUpdateRequest(getRequestHandler());
106 updateRequest.addFile((File) body, mimeType);
107
108 for (Map.Entry<String, Object> entry :
exchange.getIn().getHeaders().entrySet()) {
109 if (entry.getKey().startsWith(SolrConstants.PARAM)) {
110 String paramName =
entry.getKey().substring(SolrConstants.PARAM.length());
111 updateRequest.setParam(paramName,
entry.getValue().toString());
112 }
113 }
114
115 updateRequest.process(solrServer);
116
117 } else if (body instanceof SolrInputDocument) {
118
119 UpdateRequest updateRequest = new
UpdateRequest(getRequestHandler());
120 updateRequest.add((SolrInputDocument) body);
121
122 updateRequest.process(solrServer);
123
124 } else if (body instanceof List<?>) {
125 List<?> list = (List<?>) body;
126
127 if (list.size() > 0 && list.get(0) instanceof
SolrInputDocument) {
128 UpdateRequest updateRequest = new
UpdateRequest(getRequestHandler());
129 updateRequest.add((List<SolrInputDocument>) list);
130
131 updateRequest.process(solrServer);
132 } else {
133 invalid = true;
134 }
135
136 } else {
137
138 boolean hasSolrHeaders = false;
139 for (Map.Entry<String, Object> entry :
exchange.getIn().getHeaders().entrySet()) {
140 if (entry.getKey().startsWith(SolrConstants.FIELD)) {
141 hasSolrHeaders = true;
142 break;
143 }
144 }
145
146 if (hasSolrHeaders) {
147
148 UpdateRequest updateRequest = new
UpdateRequest(getRequestHandler());
149
150 SolrInputDocument doc = new SolrInputDocument();
151 for (Map.Entry<String, Object> entry :
exchange.getIn().getHeaders().entrySet()) {
152 if (entry.getKey().startsWith(SolrConstants.FIELD)) {
153 String fieldName =
entry.getKey().substring(SolrConstants.FIELD.length());
154 doc.setField(fieldName, entry.getValue());
155 }
:
> SolrComponent gets the wrong Content Type
> -----------------------------------------
>
> Key: CAMEL-9736
> URL: https://issues.apache.org/jira/browse/CAMEL-9736
> Project: Camel
> Issue Type: Improvement
> Components: camel-solr
> Affects Versions: 2.16.2
> Environment: Linux
> Reporter: Mansour Al Akeel
> Assignee: Andrea Cosentino
> Priority: Minor
> Labels: content-type, indexing, solr
> Fix For: 2.18.0, 2.17.1
>
>
> Currently, there is no way to specify the content type. It's extracted
> automatically from the File in the body of the Message. This results in error
> when indexing a document. Setting Exchange.CONTENT_TYPE or
> Exchange.FILE_CONTENT_TYPE does not help.
> For example, neither of these would work, as the component ignores the header
> and reads the file type in SolrProducer:
> if (body instanceof File) {
> MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
> String mimeType = mimeTypesMap.getContentType((File)body);
> ContentStreamUpdateRequest updateRequest = new
> ContentStreamUpdateRequest(getRequestHandler());
> updateRequest.addFile((File) body, mimeType);
> A simple solution could be to check if the Exchange.FILE_CONTENT_TYPE is set,
> before trying to extract if from mimeTypesMap.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)