Return-Path: X-Original-To: apmail-lucene-solr-user-archive@minotaur.apache.org Delivered-To: apmail-lucene-solr-user-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id DFD26959B for ; Mon, 21 May 2012 02:49:25 +0000 (UTC) Received: (qmail 29410 invoked by uid 500); 21 May 2012 02:49:22 -0000 Delivered-To: apmail-lucene-solr-user-archive@lucene.apache.org Received: (qmail 29270 invoked by uid 500); 21 May 2012 02:49:22 -0000 Mailing-List: contact solr-user-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: solr-user@lucene.apache.org Delivered-To: mailing list solr-user@lucene.apache.org Received: (qmail 29239 invoked by uid 99); 21 May 2012 02:49:21 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 21 May 2012 02:49:21 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of mansour.alakeel@gmail.com designates 209.85.217.176 as permitted sender) Received: from [209.85.217.176] (HELO mail-lb0-f176.google.com) (209.85.217.176) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 21 May 2012 02:49:16 +0000 Received: by lboj14 with SMTP id j14so4479803lbo.35 for ; Sun, 20 May 2012 19:48:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=bVeGGs46noQs4EAIs6A/cCNB95ZPW1IMHaq4XkhbNgY=; b=SKPGepaAOEL7/OPWIysXjZxAL+s60hfID1Z/ebkz6WgIrDxoZOlgjk7yroY0BWmc0t NZSNi88Yn7YCi3QOsKJthGtScWhpyHlAXS0/H6UVXDrZy+OYalQ6N8I2+dHgs+vDbflS 8rAdnQ5CfDZ+oEkGwrL8oLHuN9IXN+zsK6lqKOu7nVtO4/wOKK7W9Ljz+YJxFt6XJnf5 U5Ut9bHVUDWvIqNwSjBCjiYIQobHSNpGujWpuh/745/oAW6jaS6qgvjba7pfg0vPrbCw /cZuadflVsRWY4rEYtYmiJ6tNH4sHgmZ9MjP/3aWIKDZOkkZtHuHk2C7bb8z2reYEGPh knyQ== MIME-Version: 1.0 Received: by 10.152.122.116 with SMTP id lr20mr18073313lab.42.1337568534969; Sun, 20 May 2012 19:48:54 -0700 (PDT) Received: by 10.112.63.147 with HTTP; Sun, 20 May 2012 19:48:54 -0700 (PDT) In-Reply-To: References: Date: Sun, 20 May 2012 22:48:54 -0400 Message-ID: Subject: Re: Sending http post to solr indexing From: Mansour Al Akeel To: solr-user@lucene.apache.org Content-Type: multipart/alternative; boundary=f46d042ef72963bba004c082f152 X-Virus-Checked: Checked by ClamAV on apache.org --f46d042ef72963bba004c082f152 Content-Type: text/plain; charset=ISO-8859-1 I just updated my code. There no error , and getting back 200, but when I perform a search in solr/admin, I get no results. Here's my code: @Override public void index(ProductData product) { HttpClient httpclient = new DefaultHttpClient(); HttpPost post = new HttpPost(url); post.setHeader("Content-type", "application/json"); HttpParams params = new BasicHttpParams(); params.setParameter("commit", "true"); post.setParams(params); String d = "[{ \"id\" : \"1234\", \"name\" : \"My Product\" } ]"; try { StringEntity entity = new StringEntity(d); entity.setContentEncoding("UTF-8"); post.setEntity(entity); HttpResponse response = httpclient.execute(post); System.out.println(response); System.out.print(post.getParams().getParameter("commit")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } And this is output: HTTP/1.1 200 OK [Server: Apache-Coyote/1.1, Content-Type: application/xml;charset=UTF-8, Transfer-Encoding: chunked, Date: Mon, 21 May 2012 02:43:57 GMT] true On the server side, it's showing: May 21, 2012 2:43:57 AM org.apache.solr.core.SolrCore execute INFO: [] webapp=/solr path=/update/json params={} status=0 QTime=0 I am not sure if this is because I am using HttpComponents the wrong way, or I am doing something wrong with JSON string, or missing a parameter. As far as I know, I need to add (commit=true) to the request param. But it doesn't look like this is being received on the server. Thank you. On Sun, May 20, 2012 at 10:22 PM, Jack Krupansky wrote: > See some examples here: > http://wiki.apache.org/solr/**UpdateJSON > > I think in your case you just need the JSON array squares brackets around > the doument or list of documents. > > And also "update/json" in the URL. > > -- Jack Krupansky > > -----Original Message----- From: Mansour Al Akeel > Sent: Sunday, May 20, 2012 8:35 PM > To: solr-user@lucene.apache.org > Subject: Re: Sending http post to solr indexing > > > Sorry, > forgot to include the url and the error message: > private static String url = "http://localhost:8080/solr/**update > "; > > The error I am getting on the server is: > SEVERE: org.apache.solr.common.**SolrException: Unexpected character '{' > (code 123) in prolog; expected '<' > at [row,col {unknown-source}]: [1,1] > at org.apache.solr.handler.**XMLLoader.load(XMLLoader.java:**81) > at > org.apache.solr.handler.**ContentStreamHandlerBase.**handleRequestBody(** > ContentStreamHandlerBase.java:**58) > at > org.apache.solr.handler.**RequestHandlerBase.**handleRequest(** > RequestHandlerBase.java:129) > at org.apache.solr.core.SolrCore.**execute(SolrCore.java:1376) > at > org.apache.solr.servlet.**SolrDispatchFilter.execute(** > SolrDispatchFilter.java:365) > at > org.apache.solr.servlet.**SolrDispatchFilter.doFilter(** > SolrDispatchFilter.java:260) > at > org.apache.catalina.core.**ApplicationFilterChain.**internalDoFilter(** > ApplicationFilterChain.java:**243) > at > org.apache.catalina.core.**ApplicationFilterChain.**doFilter(** > ApplicationFilterChain.java:**210) > at > org.apache.solr.servlets.**SecurityFilter.doFilter(** > SecurityFilter.java:78) > at > org.apache.catalina.core.**ApplicationFilterChain.**internalDoFilter(** > ApplicationFilterChain.java:**243) > at > org.apache.catalina.core.**ApplicationFilterChain.**doFilter(** > ApplicationFilterChain.java:**210) > at > org.apache.catalina.core.**StandardWrapperValve.invoke(** > StandardWrapperValve.java:224) > at > org.apache.catalina.core.**StandardContextValve.invoke(** > StandardContextValve.java:169) > at > org.apache.catalina.**authenticator.**AuthenticatorBase.invoke(** > AuthenticatorBase.java:472) > at > org.apache.catalina.core.**StandardHostValve.invoke(** > StandardHostValve.java:168) > at > org.apache.catalina.valves.**ErrorReportValve.invoke(** > ErrorReportValve.java:98) > at > org.apache.catalina.valves.**AccessLogValve.invoke(** > AccessLogValve.java:928) > at > org.apache.catalina.core.**StandardEngineValve.invoke(** > StandardEngineValve.java:118) > at > org.apache.catalina.connector.**CoyoteAdapter.service(** > CoyoteAdapter.java:407) > at > org.apache.coyote.http11.**AbstractHttp11Processor.**process(** > AbstractHttp11Processor.java:**987) > at > org.apache.coyote.**AbstractProtocol$**AbstractConnectionHandler.** > process(AbstractProtocol.java:**539) > at > org.apache.tomcat.util.net.**JIoEndpoint$SocketProcessor.** > run(JIoEndpoint.java:298) > at > java.util.concurrent.**ThreadPoolExecutor.runWorker(** > ThreadPoolExecutor.java:1110) > at > java.util.concurrent.**ThreadPoolExecutor$Worker.run(** > ThreadPoolExecutor.java:603) > at java.lang.Thread.run(Thread.**java:722) > Caused by: com.ctc.wstx.exc.**WstxUnexpectedCharException: Unexpected > character '{' (code 123) in prolog; expected '<' > at [row,col {unknown-source}]: [1,1] > at > com.ctc.wstx.sr.StreamScanner.**throwUnexpectedChar(** > StreamScanner.java:648) > at > com.ctc.wstx.sr.**BasicStreamReader.**nextFromProlog(** > BasicStreamReader.java:2047) > at > com.ctc.wstx.sr.**BasicStreamReader.next(**BasicStreamReader.java:1069) > at > org.apache.solr.handler.**XMLLoader.processUpdate(**XMLLoader.java:104) > at org.apache.solr.handler.**XMLLoader.load(XMLLoader.java:**79) > ... 24 more > > May 21, 2012 12:32:13 AM org.apache.solr.core.SolrCore execute > INFO: [] webapp=/solr path=/update params={} status=400 QTime=1 > > > > On Sun, May 20, 2012 at 8:34 PM, Mansour Al Akeel < > mansour.alakeel@gmail.com > >> wrote: >> > > I am trying to post some json objects to solr over http. Here's my code: >> >> public void index(ProductData product) { >> >> HttpClient httpclient = new DefaultHttpClient(); >> HttpPost httppost = new HttpPost(url); >> httppost.setHeader("Content-**type", "application/json"); >> httppost.getParams().**setParameter("commit", "true"); >> >> try { >> StringEntity entity; >> entity = new StringEntity(product.toString(**)); >> httppost.setEntity(entity); >> HttpResponse response = httpclient.execute(httppost); >> System.out.println(product.**toString()); >> System.out.println(response.**toString()); >> } catch (UnsupportedEncodingException e) { >> e.printStackTrace(); >> } catch (ParseException e) { >> e.printStackTrace(); >> } catch (IOException e) { >> e.printStackTrace(); >> } >> } >> >> >> I am getting error 400 bad request. The output showing JSON string (edited >> a bit), and the response: >> >> { "timeStamp" : 1337560074593 , "title1" : "Sony Handycam HDR-XR260V 160 >> GB Camcorder" , "price" : 116.5 , "condition" : "New" , "brand" : "Sony" , >> "model" : "HDR-XR260V" , "mpn" : "HDR-XR260V"} >> HTTP/1.1 400 Bad Request [Server: Apache-Coyote/1.1, Content-Type: >> text/html;charset=utf-8, Content-Length: 1271, Date: Mon, 21 May 2012 >> 00:27:56 GMT, Connection: close] >> >> >> Is there something I am missing or doing wrong ?? >> >> Thank you. >> >> >> > --f46d042ef72963bba004c082f152--