diff --git a/htroot/gsa/searchresult.java b/htroot/gsa/searchresult.java index e88714076..c3740e6da 100644 --- a/htroot/gsa/searchresult.java +++ b/htroot/gsa/searchresult.java @@ -188,38 +188,41 @@ public class searchresult { // do the solr request SolrQueryRequest req = connector.request(post.toSolrParams(null)); SolrQueryResponse response = null; - Exception e = null; - try {response = connector.query(req);} catch (final SolrException ee) {e = ee;} - if (response != null) e = response.getException(); - if (e != null) { - ConcurrentLog.logException(e); - if (req != null) req.close(); - SolrRequestInfo.clearRequestInfo(); - return null; - } - - // set some context for the writer - /* - Map context = req.getContext(); - context.put("ip", header.get("CLIENTIP", "")); - context.put("client", "vsm_frontent"); - context.put("sort", sort.sort); - context.put("site", site == null ? "" : site); - context.put("access", access == null ? "p" : access[0]); - context.put("entqr", entqr == null ? "3" : entqr[0]); - */ - - // write the result directly to the output stream - Writer ow = new FastWriter(new OutputStreamWriter(out, UTF8.charset)); + Writer ow = null; try { - responseWriter.write(ow, req, response); - ow.flush(); + response = connector.query(req); + if (response != null) { + Exception e = response.getException(); + if (e != null) { + ConcurrentLog.logException(e); + } else { + + // set some context for the writer + /* + Map context = req.getContext(); + context.put("ip", header.get("CLIENTIP", "")); + context.put("client", "vsm_frontent"); + context.put("sort", sort.sort); + context.put("site", site == null ? "" : site); + context.put("access", access == null ? "p" : access[0]); + context.put("entqr", entqr == null ? "3" : entqr[0]); + */ + + // write the result directly to the output stream + ow = new FastWriter(new OutputStreamWriter(out, UTF8.charset)); + responseWriter.write(ow, req, response); + ow.flush(); + } + } + } catch (final SolrException e) { + ConcurrentLog.logException(e); } catch (final IOException e1) { } finally { req.close(); SolrRequestInfo.clearRequestInfo(); - try {ow.close();} catch (final IOException e1) {} + if (ow != null) try {ow.close();} catch (final IOException e1) {} } + if (response == null) return null; // log result Object rv = response.getValues().get("response"); diff --git a/htroot/solr/select.java b/htroot/solr/select.java index 69df3e110..042e6b134 100644 --- a/htroot/solr/select.java +++ b/htroot/solr/select.java @@ -218,38 +218,35 @@ public class select { // do the solr request, generate facets if we use a special YaCy format SolrParams params = post.toSolrParams(/*responseWriter instanceof JsonResponseWriter ? new YaCySchema[]{YaCySchema.host_s, YaCySchema.url_file_ext_s, YaCySchema.url_protocol_s} :*/ null); SolrQueryRequest req = connector.request(params); + Writer ow = null; SolrQueryResponse response = null; - Exception e = null; - try {response = connector.query(req);} catch (final SolrException ee) {e = ee;} - if (response != null) e = response.getException(); - if (e != null) { - ConcurrentLog.logException(e); - if (req != null) req.close(); + try { + response = connector.query(req); + if (response != null) { + Exception e = response.getException(); + if (e != null) { + ConcurrentLog.logException(e); + } else { + + // write the result directly to the output stream + if (responseWriter instanceof BinaryResponseWriter) { + ((BinaryResponseWriter) responseWriter).write(out, req, response); + } else { + ow = new FastWriter(new OutputStreamWriter(out, UTF8.charset)); + responseWriter.write(ow, req, response); + ow.flush(); + } + } + } + } catch (final SolrException e) { + ConcurrentLog.logException(e); + } catch (final IOException e1) { + } finally { + req.close(); SolrRequestInfo.clearRequestInfo(); - return null; - } - - // write the result directly to the output stream - if (responseWriter instanceof BinaryResponseWriter) { - try { - ((BinaryResponseWriter) responseWriter).write(out, req, response); - } catch (final IOException e1) { - } finally { - req.close(); - SolrRequestInfo.clearRequestInfo(); - } - } else { - Writer ow = new FastWriter(new OutputStreamWriter(out, UTF8.charset)); - try { - responseWriter.write(ow, req, response); - ow.flush(); - } catch (final IOException e1) { - } finally { - req.close(); - SolrRequestInfo.clearRequestInfo(); - try {ow.close();} catch (final IOException e1) {} - } + if (ow != null) try {ow.close();} catch (final IOException e1) {} } + if (response == null) return null; // log result Object rv = response.getValues().get("response"); diff --git a/source/net/yacy/cora/federate/solr/SolrServlet.java b/source/net/yacy/cora/federate/solr/SolrServlet.java index 05506615f..ebdc6db2a 100644 --- a/source/net/yacy/cora/federate/solr/SolrServlet.java +++ b/source/net/yacy/cora/federate/solr/SolrServlet.java @@ -113,7 +113,8 @@ public class SolrServlet implements Filter { if (reqMethod == null || (reqMethod != Method.GET && reqMethod != Method.HEAD)) { throw new ServletException("Unsupported method: " + hrequest.getMethod()); } - + + Writer out = null; try { SolrCore core = connector.getCore(); if (core == null) { @@ -146,7 +147,7 @@ public class SolrServlet implements Filter { } // write response body - Writer out = new FastWriter(new OutputStreamWriter(response.getOutputStream(), UTF8.charset)); + out = new FastWriter(new OutputStreamWriter(response.getOutputStream(), UTF8.charset)); //debug @SuppressWarnings("unchecked") @@ -171,16 +172,14 @@ public class SolrServlet implements Filter { responseWriter.write(out, req, rsp); out.flush(); - return; - } catch (final Throwable ex) { sendError(hresponse, ex); - return; } finally { if (req != null) { req.close(); } SolrRequestInfo.clearRequestInfo(); + if (out != null) try {out.close();} catch (final IOException e1) {} } } diff --git a/source/net/yacy/cora/federate/solr/connector/EmbeddedSolrConnector.java b/source/net/yacy/cora/federate/solr/connector/EmbeddedSolrConnector.java index bed9f798a..20c4d1030 100644 --- a/source/net/yacy/cora/federate/solr/connector/EmbeddedSolrConnector.java +++ b/source/net/yacy/cora/federate/solr/connector/EmbeddedSolrConnector.java @@ -269,14 +269,17 @@ public class EmbeddedSolrConnector extends SolrServerConnector implements SolrCo SolrQueryRequest req = new SolrQueryRequestBase(this.core, params){}; req.getContext().put("path", SELECT); req.getContext().put("webapp", CONTEXT); - for (String id: ids) { - params.setQuery("{!raw f=" + CollectionSchema.id.getSolrFieldName() + "}" + id); - SolrQueryResponse rsp = new SolrQueryResponse(); - this.requestHandler.handleRequest(req, rsp); - DocList response = ((ResultContext) rsp.getValues().get("response")).docs; - if (response.matches() > 0) idsr.add(id); + try { + for (String id: ids) { + params.setQuery("{!raw f=" + CollectionSchema.id.getSolrFieldName() + "}" + id); + SolrQueryResponse rsp = new SolrQueryResponse(); + this.requestHandler.handleRequest(req, rsp); + DocList response = ((ResultContext) rsp.getValues().get("response")).docs; + if (response.matches() > 0) idsr.add(id); + } + } finally { + req.close(); } - req.close(); return idsr; }