2009-09-17 48 views
2

我張貼下面給Solr的服務器錯誤:的Solr - 發帖時的「添加」到服務器

<add> 
    <doc> 
     <field name="uniqueid">5453543</field> 
     <field name="modifieddate">2008-12-03T15:49:00Z</field> 
     <field name="title">My Record</field> 
     <field name="description">Descirption 
     Details 
</field> 
     <field name="startdate">2009-01-21T15:26:05.680Z</field> 
     <field name="enddate">2009-01-21T15:26:05.697Z</field> 
     <field name="Telephone_number">11111 111 111(text phone)</field> 
     <field name="Telephone_number">11111 111 111</field> 
     <field name="Mobile_number">1111111111</field> 
    </doc> 
</add> 

我使用SolrNet這裏給的文件是從代碼中的提取物(S是上面的XML):

public string Post(string relativeUrl, string s) 
{ 
    var u = new UriBuilder(serverURL); 
    u.Path += relativeUrl; 
    var request = httpWebRequestFactory.Create(u.Uri); 
    request.Method = HttpWebRequestMethod.POST; 
    request.KeepAlive = false; 
    if (Timeout > 0) 
     request.Timeout = Timeout; 
    request.ContentType = "text/xml; charset=utf-8"; 
    request.ContentLength = s.Length; 
    request.ProtocolVersion = HttpVersion.Version10; 
    try 
    { 
     using (var postParams = request.GetRequestStream()) 
     { 
      postParams.Write(xmlEncoding.GetBytes(s), 0, s.Length); 
      using (var response = request.GetResponse()) 
      { 
       using (var rStream = response.GetResponseStream()) 
       { 
        string r = xmlEncoding.GetString(ReadFully(rStream)); 
        //Console.WriteLine(r); 
        return r; 
       } 
      } 
     } 
    } 
    catch (WebException e) 
    { 
     throw new SolrConnectionException(e); 
    } 
} 

當它到達request.GetResponse失敗與此錯誤:

base {System.InvalidOperationException} = {"The remote server returned an error: (500) Internal Server Error."}

當我看到在阿帕奇它提供了以下原因,日誌服務器上:

Unexpected end of input block in end

下面是完整的堆棧跟蹤:

Sep 17, 2009 10:13:53 AM org.apache.solr.common.SolrException log SEVERE: com.ctc.wstx.exc.WstxEOFException: Unexpected end of input block in end tag at [row,col {unknown-source}]: [26,1266] at com.ctc.wstx.sr.StreamScanner.throwUnexpectedEOB(StreamScanner.java:700) at com.ctc.wstx.sr.StreamScanner.loadMoreFromCurrent(StreamScanner.java:1054) at com.ctc.wstx.sr.StreamScanner.getNextCharFromCurrent(StreamScanner.java:811) at com.ctc.wstx.sr.BasicStreamReader.readEndElem(BasicStreamReader.java:3211) at com.ctc.wstx.sr.BasicStreamReader.nextFromTree(BasicStreamReader.java:2832) at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1019) at org.apache.solr.handler.XmlUpdateRequestHandler.processUpdate(XmlUpdateRequestHandler.java:148) at org.apache.solr.handler.XmlUpdateRequestHandler.handleRequestBody(XmlUpdateRequestHandler.java:123) at org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:131) at org.apache.solr.core.SolrCore.execute(SolrCore.java:1204) at org.apache.solr.servlet.SolrDispatchFilter.execute(SolrDispatchFilter.java:303) at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:232) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859) at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:574) at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1527) at java.lang.Thread.run(Thread.java:619)

請注意Solr的服務器以下系統上運行:

的Microsoft Windows Server 2003 R2 的Apache Tomcat 6

最後這裏是我的曲注意:

我發送的Xml看起來對我有用..有沒有人有一個想法,爲什麼Solr拋出這個異常?

感謝

戴夫

編輯答案如下:

public string Post(string relativeUrl, string s) 
{ 
    var u = new UriBuilder(serverURL); 
    u.Path += relativeUrl; 
    var request = httpWebRequestFactory.Create(u.Uri); 
    request.Method = HttpWebRequestMethod.POST; 
    request.KeepAlive = false; 
    if (Timeout > 0) 
     request.Timeout = Timeout; 
    request.ContentType = "text/xml; charset=utf-8"; 
    request.ProtocolVersion = HttpVersion.Version10; 
    try 
    { 
     // Set the Content length after the size of the byte array has been calculated. 
     byte[] data = xmlEncoding.GetBytes(s); 
     request.ContentLength = s.Length; 
     using (var postParams = request.GetRequestStream()) 
     { 
      postParams.Write(data, 0, data.Length); 
      using (var response = request.GetResponse()) 
      { 
       using (var rStream = response.GetResponseStream()) 
       { 
        string r = xmlEncoding.GetString(ReadFully(rStream)); 
        //Console.WriteLine(r); 
        return r; 
       } 
      } 
     } 
    } 
    catch (WebException e) 
    { 
     throw new SolrConnectionException(e); 
    } 
} 
+0

望着SolrNet的最新版本..此修復程序已經在那裏:) – CraftyFella

+1

呼,我認爲錯誤回來了:-) –

+0

我認爲我們使用的版本是一個很好的11個月大..所以我必須繞過去更新到最新版本。對不起,嚇到你:) – CraftyFella

回答

1

我沒有太多熟悉.NET或Solr的或Solr中的淨出口。但是,這是我的猜測。

postParams.Write(xmlEncoding.GetBytes(s), 0, s.Length); 

有兩種可能的錯誤。

  1. 當您從String獲取字節時,應指定編碼。可能是這種情況,默認編碼與UTF8不同,您在內容類型頭中設置了UTF8作爲響應。
  2. Write()中的第三個參數可能是指您從GetBytes()獲取的字節數組的長度。字節數組的長度可能比字符串的長度長。
+0

嗨..謝謝你的猜測..編碼是UTF8 ... 它在類的頂部是這樣聲明的: private Encoding xmlEncoding = Encoding.UTF8; – CraftyFella

+0

嘿..你的第二點是砰的一聲,我在POST上做了一個「Fiddler2」,它錯過了XML的最後兩位數,所以變成了 CraftyFella

+0

你的男人..一旦糾正了長度問題..我有另一個問題..事實證明,默認的Solr安裝不接受非ASCII字符作爲請求的一部分.. http:// wiki。 apache.org/solr/SolrTomcat#head-20147ee4d9dd5ca83ed264898280ab60457847c4 所以我會嘗試和整理出來..我會確保我回饋到Solr.Net項目,所以沒有其他人得到這個問題。 – CraftyFella