that's also a nice idea.

in the end i solved by passing to my ContentHandler a
ByteArrayInputStream(method.getResponseBody()). this should copy the
content and avoid concurrency. Thanks for the feedback.


Ken Krugler wrote:
> Hi Claudio,
>
> On Jan 25, 2010, at 8:41am, Claudio Martella wrote:
>
>> Hello list,
>>
>> I'm writing a webcrawler and using apache tika to extract text out of
>> certain mime-types.
>>
>> what i'm actually doing right now is:
>>
>>    while(toVisit.size()){
>>
>>                [... SOME CODE HANDLING LISTS AND HTTPCLIENT ...]
>>
>>
>>                client.executeMethod(method);
>>                // just i.e. returns "text/html" or "application/pdf"
>>                String mime = getContentType(method);
>>
>>                // extract text where possible and send it to the index
>>                if(supportedContentType.contains(mime))
>>                    pool.execute(new MyContentHandler(new
>> CrawledResult(method.getResponseBodyAsStream(), workingURL, null,
>> mime)));
>>                else {
>>                    String htmlBody = method.getResponseBodyAsString();
>>                }
>>
>>
>>                [... SOME CODE TO EXTRACT LINKS OUT OF htmlBody AND
>> POPULATE toVisit SET ...]
>>
>>                method.releaseConnection();
>>    }
>>
>> My problem is that before my Threads can access the content of the
>> Stream, the crawler is calling the releaseConnection() which leads to an
>> IO Exception.
>>
>> I'd like to avoid passing the whole HttpMethod and delegating its
>> management to my other Classes which should just know about IO Streams.
>> Do you have any idea on how i could handle this concurrency problem?
>> Maybe some cloning?
>
> If you really want to avoid passing explicit HttpClient classes to
> your thread, then the best option I can think of is to define an
> IHttpFetcher interface that masks the underlying implementation, and
> implement this interface with a specific HttpClient version.
>
> This is similar to what I did for Bixo. See
> http://github.com/bixo/bixo/blob/master/src/main/java/bixo/fetcher/http/SimpleHttpFetcher.java
>
>
> -- Ken
>
> --------------------------------------------
> <http://ken-blog.krugler.org>
> +1 530-265-2225
>
>
>
>
>
>
> --------------------------------------------
> Ken Krugler
> +1 530-210-6378
> http://bixolabs.com
> e l a s t i c   w e b   m i n i n g
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>


-- 
Claudio Martella
Digital Technologies
Unit Research & Development - Analyst

TIS innovation park
Via Siemens 19 | Siemensstr. 19
39100 Bolzano | 39100 Bozen
Tel. +39 0471 068 123
Fax  +39 0471 068 129
[email protected] http://www.tis.bz.it

Short information regarding use of personal data. According to Section 13 of 
Italian Legislative Decree no. 196 of 30 June 2003, we inform you that we 
process your personal data in order to fulfil contractual and fiscal 
obligations and also to send you information regarding our services and events. 
Your personal data are processed with and without electronic means and by 
respecting data subjects' rights, fundamental freedoms and dignity, 
particularly with regard to confidentiality, personal identity and the right to 
personal data protection. At any time and without formalities you can write an 
e-mail to [email protected] in order to object the processing of your personal 
data for the purpose of sending advertising materials and also to exercise the 
right to access personal data and other rights referred to in Section 7 of 
Decree 196/2003. The data controller is TIS Techno Innovation Alto Adige, 
Siemens Street n. 19, Bolzano. You can find the complete information on the web 
site www.tis.bz.it.



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to