⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fetchhttp.html

📁 用JAVA编写的,在做实验的时候留下来的,本来想删的,但是传上来,大家分享吧
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<a name="516" href="#516">516</a>         <a name="517" href="#517">517</a>         curi.setContentDigest(SHA1, rec.getRecordedInput().getDigestValue());<a name="518" href="#518">518</a>         <strong>if</strong> (logger.isLoggable(Level.INFO)) {<a name="519" href="#519">519</a>             logger.info((curi.isPost()? <span class="string">"POST"</span>: <span class="string">"GET"</span>) + <span class="string">" "</span> +<a name="520" href="#520">520</a>                 curi.getUURI().toString() + <span class="string">" "</span> + method.getStatusCode() +<a name="521" href="#521">521</a>                 <span class="string">" "</span> + rec.getRecordedInput().getSize() + <span class="string">" "</span> +<a name="522" href="#522">522</a>                 curi.getContentType());<a name="523" href="#523">523</a>         }<a name="524" href="#524">524</a> <a name="525" href="#525">525</a>         <strong>if</strong> (curi.isSuccess() &amp;&amp; addedCredentials) {<a name="526" href="#526">526</a>             <em class="comment">// Promote the credentials from the CrawlURI to the CrawlServer</em><a name="527" href="#527">527</a>             <em class="comment">// so they are available for all subsequent CrawlURIs on this</em><a name="528" href="#528">528</a>             <em class="comment">// server.</em><a name="529" href="#529">529</a>             promoteCredentials(curi);<a name="530" href="#530">530</a>             <strong>if</strong> (logger.isLoggable(Level.FINE)) {<a name="531" href="#531">531</a>                 <em class="comment">// Print out the cookie.  Might help with the debugging.</em><a name="532" href="#532">532</a>                 Header setCookie = method.getResponseHeader(<span class="string">"set-cookie"</span>);<a name="533" href="#533">533</a>                 <strong>if</strong> (setCookie != <strong>null</strong>) {<a name="534" href="#534">534</a>                     logger.fine(setCookie.toString().trim());<a name="535" href="#535">535</a>                 }<a name="536" href="#536">536</a>             }<a name="537" href="#537">537</a>         } <strong>else</strong> <strong>if</strong> (method.getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {<a name="538" href="#538">538</a>             <em class="comment">// 401 is not 'success'.</em><a name="539" href="#539">539</a>             handle401(method, curi);<a name="540" href="#540">540</a>         }<a name="541" href="#541">541</a>         <a name="542" href="#542">542</a>         <strong>if</strong> (rec.getRecordedInput().isOpen()) {<a name="543" href="#543">543</a>             logger.severe(curi.toString() + <span class="string">" RIS still open. Should have"</span> +<a name="544" href="#544">544</a>                 <span class="string">" been closed by method release: "</span> +<a name="545" href="#545">545</a>                 Thread.currentThread().getName());<a name="546" href="#546">546</a>             <strong>try</strong> {<a name="547" href="#547">547</a>                 rec.getRecordedInput().close();<a name="548" href="#548">548</a>             } <strong>catch</strong> (IOException e) {<a name="549" href="#549">549</a>                 logger.log(Level.SEVERE,<span class="string">"second-chance RIS close failed"</span>,e);<a name="550" href="#550">550</a>             }<a name="551" href="#551">551</a>         }<a name="552" href="#552">552</a>     }<a name="553" href="#553">553</a>     <a name="554" href="#554">554</a>     <strong>protected</strong> <strong>void</strong> doAbort(<a href="../../../../org/archive/crawler/datamodel/CrawlURI.html">CrawlURI</a> curi, HttpMethod method,<a name="555" href="#555">555</a>             String annotation) {<a name="556" href="#556">556</a>         curi.addAnnotation(annotation);<a name="557" href="#557">557</a>         curi.getHttpRecorder().close();<a name="558" href="#558">558</a>         method.abort();<a name="559" href="#559">559</a>     }<a name="560" href="#560">560</a>     <a name="561" href="#561">561</a>     <strong>protected</strong> <strong>boolean</strong> checkMidfetchAbort(<a href="../../../../org/archive/crawler/datamodel/CrawlURI.html">CrawlURI</a> curi,<a name="562" href="#562">562</a>             <a href="../../../../org/archive/httpclient/HttpRecorderMethod.html">HttpRecorderMethod</a> method, <a href="../../../../org/apache/commons/httpclient/HttpConnection.html">HttpConnection</a> conn) {<a name="563" href="#563">563</a>         <strong>if</strong> (curi.isPrerequisite() || filtersAccept(midfetchfilters, curi)) {<a name="564" href="#564">564</a>             <strong>return</strong> false;<a name="565" href="#565">565</a>         }<a name="566" href="#566">566</a>         method.markContentBegin(conn);<a name="567" href="#567">567</a>         <strong>return</strong> <strong>true</strong>;<a name="568" href="#568">568</a>     }<a name="569" href="#569">569</a>     <a name="570" href="#570">570</a>     <em>/**<em>*</em></em><a name="571" href="#571">571</a> <em>     * This method populates &lt;code>curi&lt;/code> with response status and</em><a name="572" href="#572">572</a> <em>     * content type.</em><a name="573" href="#573">573</a> <em>     * @param curi CrawlURI to populate.</em><a name="574" href="#574">574</a> <em>     * @param method Method to get response status and headers from.</em><a name="575" href="#575">575</a> <em>     */</em><a name="576" href="#576">576</a>     <strong>protected</strong> <strong>void</strong> addResponseContent (HttpMethod method, CrawlURI curi) {<a name="577" href="#577">577</a>         curi.setFetchStatus(method.getStatusCode());<a name="578" href="#578">578</a>         Header ct = method.getResponseHeader(<span class="string">"content-type"</span>);<a name="579" href="#579">579</a>         curi.setContentType((ct == <strong>null</strong>)? <strong>null</strong>: ct.getValue());<a name="580" href="#580">580</a>         <em class="comment">// Save method into curi too.  Midfetch filters may want to leverage</em><a name="581" href="#581">581</a>         <em class="comment">// info in here.</em><a name="582" href="#582">582</a>         curi.putObject(A_HTTP_TRANSACTION, method);<a name="583" href="#583">583</a>     }<a name="584" href="#584">584</a> <a name="585" href="#585">585</a>     <em>/**<em>*</em></em><a name="586" href="#586">586</a> <em>     * Set the character encoding based on the result headers or default.</em><a name="587" href="#587">587</a> <em>     *</em><a name="588" href="#588">588</a> <em>     * The HttpClient returns its own default encoding ("ISO-8859-1") if one</em><a name="589" href="#589">589</a> <em>     * isn't specified in the Content-Type response header. We give the user</em><a name="590" href="#590">590</a> <em>     * the option of overriding this, so we need to detect the case where the</em><a name="591" href="#591">591</a> <em>     * default is returned.</em><a name="592" href="#592">592</a> <em>     *</em><a name="593" href="#593">593</a> <em>     * Now, it may well be the case that the default returned by HttpClient</em><a name="594" href="#594">594</a> <em>     * and the default defined by the user are the same.</em><a name="595" href="#595">595</a> <em>     * </em><a name="596" href="#596">596</a> <em>     * @param rec Recorder for this request.</em><a name="597" href="#597">597</a> <em>     * @param method Method used for the request.</em><a name="598" href="#598">598</a> <em>     */</em><a name="599" href="#599">599</a>     <strong>private</strong> <strong>void</strong> setCharacterEncoding(<strong>final</strong> <a href="../../../../org/archive/util/HttpRecorder.html">HttpRecorder</a> rec,<a name="600" href="#600">600</a>         <strong>final</strong> HttpMethod method) {<a name="601" href="#601">601</a>         String encoding = <strong>null</strong>;<a name="602" href="#602">602</a> <a name="603" href="#603">603</a>         <strong>try</strong> {<a name="604" href="#604">604</a>             encoding = ((HttpMethodBase) method).getResponseCharSet();<a name="605" href="#605">605</a>             <strong>if</strong> (encoding == <strong>null</strong> ||<a name="606" href="#606">606</a>                     encoding.equals(DEFAULT_CONTENT_CHARSET)) {<a name="607" href="#607">607</a>                 encoding = (String) getAttribute(ATTR_DEFAULT_ENCODING);<a name="608" href="#608">608</a>             }<a name="609" href="#609">609</a>         } <strong>catch</strong> (Exception e) {<a name="610" href="#610">610</a>             logger.warning(<span class="string">"Failed get default encoding: "</span> +<a name="611" href="#611">611</a>                 e.getLocalizedMessage());<a name="612" href="#612">612</a>         }<a name="613" href="#613">613</a>         rec.setCharacterEncoding(encoding);<a name="614" href="#614">614</a>     }<a name="615" href="#615">615</a> <a name="616" href="#616">616</a>     <em>/**<em>*</em></em><a name="617" href="#617">617</a> <em>     * Cleanup after a failed method execute.</em><a name="618" href="#618">618</a> <em>     * @param curi CrawlURI we failed on.</em><a name="619" href="#619">619</a> <em>     * @param method Method we failed on.</em><a name="620" href="#620">620</a> <em>     * @param exception Exception we failed with.</em><a name="621" href="#621">621</a> <em>     */</em><a name="622" href="#622">622</a>     <strong>private</strong> <strong>void</strong> failedExecuteCleanup(<strong>final</strong> HttpMethod method,<a name="623" href="#623">623</a>             <strong>final</strong> <a href="../../../../org/archive/crawler/datamodel/CrawlURI.html">CrawlURI</a> curi, <strong>final</strong> Exception exception) {<a name="624" href="#624">624</a>         cleanup(curi, exception, <span class="string">"executeMethod"</span>, S_CONNECT_FAILED);<a name="625" href="#625">625</a>         method.releaseConnection();<a name="626" href="#626">626</a>     }<a name="627" href="#627">627</a>     <a name="628" href="#628">628</a>     <em>/**<em>*</em></em><a name="629" href="#629">629</a> <em>     * Cleanup after a failed method execute.</em><a name="630" href="#630">630</a> <em>     * @param curi CrawlURI we failed on.</em><a name="631" href="#631">631</a> <em>     * @param exception Exception we failed with.</em><a name="632" href="#632">632</a> <em>     * @param message Message to log with failure.</em><a name="633" href="#633">633</a> <em>     * @param status Status to set on the fetch.</em><a name="634" href="#634">634</a> <em>     */</em><a name="635" href="#635">635</a>     <strong>private</strong> <strong>void</strong> cleanup(<strong>final</strong> <a href="../../../../org/archive/crawler/datamodel/CrawlURI.html">CrawlURI</a> curi, <strong>final</strong> Exception exception,<a name="636" href="#636">636</a>             <strong>final</strong> String message, <strong>final</strong> <strong>int</strong> status) {<a name="637" href="#637">637</a>         curi.addLocalizedError(<strong>this</strong>.getName(), exception, message);<a name="638" href="#638">638</a>         curi.setFetchStatus(status);<a name="639" href="#639">639</a>         curi.getHttpRecorder().close();<a name="640" href="#640">640</a>     }<a name="641" href="#641">641</a> <a name="642" href="#642">642</a>     <em>/**<em>*</em></em><a name="643" href="#643">643</a> <em>     * Can this processor fetch the given CrawlURI. May set a fetch</em><a name="644" href="#644">644</a> <em>     * status if this processor would

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -