lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mansour Al Akeel <mansour.alak...@gmail.com>
Subject Re: Sending http post to solr indexing
Date Mon, 21 May 2012 02:48:54 GMT
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 <jack@basetechnology.com>wrote:

> See some examples here:
> http://wiki.apache.org/solr/**UpdateJSON<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<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.
>>
>>
>>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message