Java tutorial
/* * (c) Copyright 2010 Marcus Thiesen (marcus@thiesen.org) * * This file is part of jiffs. * * jiffs is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * jiffs is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with jiffs. If not, see <http://www.gnu.org/licenses/>. * */ package org.thiesen.jiffs.jobs.fullpage; import java.io.IOException; import java.net.URI; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.BasicResponseHandler; import org.apache.http.impl.client.DefaultHttpClient; import org.thiesen.jiffs.data.db.dao.StoryDAO; import org.thiesen.jiffs.data.db.dbo.StoryDBO; public class PageLoader implements Runnable { private StoryDAO _storyDAO; private StoryDBO _story; public PageLoader(StoryDAO storyDAO, StoryDBO story) { _storyDAO = storyDAO; _story = story; } @Override public void run() { final URI link = _story.getLink(); final HttpGet get = new HttpGet(link); final HttpClient client = new DefaultHttpClient(); try { final String page = client.execute(get, new BasicResponseHandler()); _story.setFullPage(page); _storyDAO.update(_story); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { client.getConnectionManager().shutdown(); } } }