I found a solution to the 400 I was getting. Because we are passing the whole thing through a proxy, it must be decoded, broken into parts and re-encoded. There is a much more efficient way to do this, but it was what I worked out for a very rough cut.
Code snippet below: String dataUrl = request.getParameter("dataUrl"); dataUrl = URLDecoder.decode(dataUrl, Charset.defaultCharset() .name()); String baseUrl = StringUtils.substringBefore(dataUrl, "?"); baseUrl += "?"; dataUrl = StringUtils.substringAfter(dataUrl, "?"); String[] queryParts = StringUtils.split(dataUrl, "&"); for (String currentPart : queryParts) { String[] parmParts = new String[] { StringUtils.substringBefore(currentPart, "=") + "=", StringUtils.substringAfter(currentPart, "=") }; baseUrl += StringUtils.endsWith(baseUrl, "?")? parmParts[0] : "&" + parmParts[0]; baseUrl += URLEncoder.encode(parmParts[1], Charset .defaultCharset().name()); } dataUrl = baseUrl; URL obj = new URL(dataUrl); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); // optional default is GET con.setRequestMethod("GET"); con.setDoOutput(true); con.connect(); int responseCode = con.getResponseCode(); /*--SNIP!--*/ -----Original Message----- From: Mark Horninger Sent: Thursday, July 30, 2015 8:54 AM To: java-user@lucene.apache.org Subject: Solr throws 400 from proxy but returns fine from browser. Hi, I am trying to work around a CORS issue on my app server side by standing up a proxy jsp in order to talk to Solr directly. It's really just a request forwarder at this point in time. The problem is that the same query I run through the proxy works fine through the browser, but when I run it in the proxy it always returns a 400. I've tried to do some initial research, but I am coming up empty. Can any one please shed some light on the situation? Some code snippets: JS XMLHTTPReq call: var queryStr = '(Line1:Tom OR Line2:Tom OR Line3:Tom)'; ... var dataUrl = 'http://[snip!]:8983/solr/[snip!]/query?&q=' + queryStr + '&fl=Field0, Field1+, Line2, Line3, Line4, Line5, Line6, Line7, Field8, Field9, Field10 ...'; var strURL = 'proxy.jsp?dataUrl=' + encodeURIComponent(dataUrl); var xmlHttpReq = false; if (window.XMLHttpRequest) { xmlHttpReq = new XMLHttpRequest(); } else if (window.ActiveXObject) { xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); } xmlHttpReq.open('GET', strURL, true); xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xmlHttpReq.onreadystatechange = function() { if (xmlHttpReq.readyState == 4) { var temp = xmlHttpReq.responseText; var refinedData = JSON.stringify(JSON.parse(temp).response.docs); And the proxy call: String dataUrl = request.getParameter("dataUrl"); dataUrl = URLDecoder.decode(dataUrl); URL obj = new URL(dataUrl); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); // optional default is GET con.setRequestMethod("GET"); con.setDoOutput(true); con.setRequestProperty("Accept", "application/json"); int responseCode = con.getResponseCode(); I'm not sure why exactly this call is failing with a 400. Any help that could be provided would be welcomed. Thanks in advance! -Mark [GrayHair] GHS Confidentiality Notice This e-mail message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution of this information is prohibited, and may be punishable by law. If this was sent to you in error, please notify the sender by reply e-mail and destroy all copies of the original message. GrayHair Software <http://www.grayhairSoftware.com> --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org For additional commands, e-mail: java-user-h...@lucene.apache.org