Index: branches/pssGrails3/grails-app/utils/com/lemanscorp/search/SearchUtils.groovy =================================================================== diff -u -r8884 -r8887 --- branches/pssGrails3/grails-app/utils/com/lemanscorp/search/SearchUtils.groovy (.../SearchUtils.groovy) (revision 8884) +++ branches/pssGrails3/grails-app/utils/com/lemanscorp/search/SearchUtils.groovy (.../SearchUtils.groovy) (revision 8887) @@ -1,74 +1,74 @@ package com.lemanscorp.search import grails.util.Holders -import org.springframework.stereotype.Component import org.apache.commons.io.IOUtils +import org.springframework.stereotype.Component @Component class SearchUtils { - def productCore = Holders.config.search.product.core - def partCore = Holders.config.search.part.core - /** - * Call Solr endpoint - * @param serverURL - * @param queryParams - * @return - */ - String callSolr(serverURL, queryParams){ + def productCore = Holders.config.search.product.core + def partCore = Holders.config.search.part.core + /** + * Call Solr endpoint + * @param serverURL + * @param queryParams + * @return + */ + String callSolr(serverURL, queryParams) { - HttpURLConnection connection - def result ='' + HttpURLConnection connection + def result = '' - try { - def core = (serverURL.contains("/${productCore}/")? "${productCore}":serverURL.contains("/${partCore}/")? "${partCore}" :'') - log.debug "completeUrl ${core}=>:"+serverURL +(queryParams? "?"+queryParams:"") + try { + def core = (serverURL.contains("/${productCore}/") ? "${productCore}" : serverURL.contains("/${partCore}/") ? "${partCore}" : '') + log.debug "completeUrl ${core}=>:" + serverURL + (queryParams ? '?' + queryParams : '') - def url = new URL(serverURL) + def url = new URL(serverURL) - connection = url.openConnection() - connection.setRequestMethod("POST") - connection.doOutput = true + connection = url.openConnection() + connection.setRequestMethod('POST') + connection.doOutput = true - def writer = new OutputStreamWriter(connection.outputStream) - if(queryParams!=null){ - writer.write(queryParams) - } - writer.flush() - writer.close() + def writer = new OutputStreamWriter(connection.outputStream) + if (queryParams != null) { + writer.write(queryParams) + } + writer.flush() + writer.close() - connection.connect() + connection.connect() - int code = connection.getResponseCode(); - if(code != 200){ - result = IOUtils.toString(connection.getErrorStream()) - throw new SearchException(new RuntimeException("Failed to call solr with these parameters: ${serverURL}?${queryParams}"), "Resposne from solr: ${result} " ) - } else { - result = connection.content.text - } + int code = connection.responseCode() + if (code != 200) { + result = IOUtils.toString(connection.errorStream()) + throw new SearchException(new RuntimeException("Failed to call solr with these parameters: ${serverURL}?${queryParams}"), + "Resposne from solr: ${result} ") + } else { + result = connection.content.text + } - } finally { - if(connection){ - connection.disconnect() - } - } - return result; - } + } finally { + if (connection) { + connection.disconnect() + } + } + result + } - public String getHostName() { - String hostName = "localhost" - try { - hostName = InetAddress.getLocalHost().getHostName(); - } catch (UnknownHostException e) { - log.error "Unknown Host :" + e - } - return hostName; - } + String getHostName() { + String hostName = 'localhost' + try { + hostName = InetAddress.localHost().hostName() + } catch (UnknownHostException e) { + log.error 'Unknown Host :' + e + } + hostName + } - String exceptionToString(e) { - StringWriter sw = new StringWriter() - e.printStackTrace(new PrintWriter(sw)) - String exceptionAsStrting = sw.toString() - } + String exceptionToString(e) { + StringWriter sw = new StringWriter() + e.printStackTrace(new PrintWriter(sw)) + } }