List of usage examples for org.apache.commons.httpclient.util DateUtil formatDate
public static String formatDate(Date paramDate)
From source file:com.basho.riak.client.request.RequestMeta.java
public RequestMeta setIfModifiedSince(Date lastmod) { return setHeader(Constants.HDR_IF_MODIFIED_SINCE, DateUtil.formatDate(lastmod)); }
From source file:name.persistent.behaviours.RemoteGraphSupport.java
@Override public boolean reload(String origin) throws Exception { String url = getResource().stringValue(); BasicHttpRequest req = new BasicHttpRequest("GET", url); String type = getPurlContentType(); if (type == null) { req.setHeader("Accept", "application/rdf+xml"); } else {/*from w w w . java 2s . c om*/ req.setHeader("Accept", type); } String etag = getPurlEtag(); if (etag != null) { req.setHeader("If-None-Match", etag); } XMLGregorianCalendar modified = getPurlLastModified(); if (modified != null) { Date date = modified.toGregorianCalendar().getTime(); req.setHeader("If-Modified-Since", DateUtil.formatDate(date)); } HttpResponse resp = requestRDF(req, 20); int code = resp.getStatusLine().getStatusCode(); if (code == 304) { DatatypeFactory df = DatatypeFactory.newInstance(); GregorianCalendar gc = new GregorianCalendar(); setPurlLastValidated(df.newXMLGregorianCalendar(gc)); setPurlCacheControl(getHeader(resp, "Cache-Control")); } if (code == 304 || code == 404) { HttpEntity entity = resp.getEntity(); if (entity != null) { entity.consumeContent(); } return true; } return importResponse(resp, origin); }
From source file:com.basho.riak.client.request.RequestMeta.java
public RequestMeta setIfUnmodifiedSince(Date lastmod) { return setHeader(Constants.HDR_IF_UNMODIFIED_SINCE, DateUtil.formatDate(lastmod)); }
From source file:de.fuberlin.wiwiss.marbles.loading.CacheController.java
/** * Adds retrieved URL data to the cache//from www .j a v a 2s . co m * @param url The URL that was retrieved * @param data The retrieved data * @param method Used to obtain metadata */ public synchronized void addURLData(String url, Graph data, HttpMethod method) { RepositoryConnection dataConn = null; InferencerConnection inferencerConn = null; RepositoryConnection metaDataConn = null; try { dataConn = dataRepository.getConnection(); inferencerConn = (InferencerConnection) dataRepository.getSail().getConnection(); metaDataConn = metaDataRepository.getConnection(); URI urlDataContext = dataRepository.getValueFactory().createURI(url); URI urlInferencerContext = dataRepository.getValueFactory().createURI(url); URI urlMetadata = metaDataRepository.getValueFactory().createURI(url); /* Remove cached data and previous metadata */ inferencerConn.removeInferredStatement((Resource) null, null, null, urlInferencerContext); /* * Because inferencerConn now holds the transaction lock on the store, * we need to commit changes first or we'll run into a deadlock when removing statements * using dataConn. They could be removed using dataConn; but the problem * would remain for the adding of statements. */ inferencerConn.commit(); dataConn.remove((Resource) null, null, null, urlDataContext); metaDataConn.remove(urlMetadata, null, null, contextCacheDataURI); /* Add retrieved data */ if (data != null) dataConn.add(data); /* Add metadata */ if (method != null) { for (String headerField : cachedHeaderFields) { Header header; if (null != (header = method.getResponseHeader(headerField))) { metaDataConn.add(urlMetadata, metaDataRepository.getValueFactory().createURI(Constants.nsHTTP, headerField), metaDataRepository.getValueFactory().createLiteral(header.getValue()), contextCacheDataURI); } } /* Add status code */ if (null != method .getStatusLine()) /* or we'll run into a NullPointerException when calling getStatusCode() */ metaDataConn.add(urlMetadata, metaDataRepository.getValueFactory().createURI(Constants.nsHTTP, "responseCode"), metaDataRepository.getValueFactory().createLiteral(method.getStatusCode()), contextCacheDataURI); } /* We'll make use of the date header to specify when the document was retrieved */ metaDataConn.add(urlMetadata, metaDataRepository.getValueFactory().createURI(Constants.nsHTTP, "date"), metaDataRepository.getValueFactory().createLiteral(DateUtil.formatDate(new Date())), contextCacheDataURI); /* Commit */ // inferencerConn.commit(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (RepositoryException e) { e.printStackTrace(); } catch (SailException e) { e.printStackTrace(); } finally { if (dataConn != null) try { dataConn.close(); } catch (RepositoryException e) { e.printStackTrace(); } if (inferencerConn != null) try { inferencerConn.close(); } catch (SailException e) { e.printStackTrace(); } if (metaDataConn != null) try { metaDataConn.close(); } catch (RepositoryException e) { e.printStackTrace(); } } }
From source file:jp.co.opentone.bsol.linkbinder.view.logo.ProjectLogoManagerTest.java
/** * projectId:????ifModifiedSince:???/* w w w. j a v a 2 s . c o m*/ */ @Test public void testIsModified3() { String projectId = "not_exist_project"; MockSystemConfig.CONFIG_PROJECT_LOGO_DEFAULT = "test-default.png"; String testFile = MockSystemConfig.CONFIG_PROJECT_LOGO_DIR + "/" + MockSystemConfig.CONFIG_PROJECT_LOGO_DEFAULT; File f = new File(testFile); if (!f.exists()) { fail("?[" + testFile + "] ????????"); return; } String ifModifiedSince = DateUtil.formatDate(new Date(f.lastModified())); assertFalse(projectLogoManager.isModified(projectId, ifModifiedSince)); }
From source file:jp.co.opentone.bsol.linkbinder.view.logo.ProjectLogoManagerTest.java
/** * projectId:????ifModifiedSince: + 1// w w w. j av a2 s . c o m */ @Test public void testIsModified4() { String projectId = "not_exist_project"; MockSystemConfig.CONFIG_PROJECT_LOGO_DEFAULT = "test-default.png"; String testFile = MockSystemConfig.CONFIG_PROJECT_LOGO_DIR + "/" + MockSystemConfig.CONFIG_PROJECT_LOGO_DEFAULT; File f = new File(testFile); if (!f.exists()) { fail("?[" + testFile + "] ????????"); return; } String ifModifiedSince = DateUtil.formatDate(new Date(f.lastModified() + 1000)); assertTrue(projectLogoManager.isModified(projectId, ifModifiedSince)); }
From source file:jp.co.opentone.bsol.linkbinder.view.logo.ProjectLogoManagerTest.java
/** * projectId:????ifModifiedSince: - 1/*from w ww .j a v a2s . co m*/ */ @Test public void testIsModified5() { String projectId = "not_exist_project"; MockSystemConfig.CONFIG_PROJECT_LOGO_DEFAULT = "test-default.png"; String testFile = MockSystemConfig.CONFIG_PROJECT_LOGO_DIR + "/" + MockSystemConfig.CONFIG_PROJECT_LOGO_DEFAULT; File f = new File(testFile); if (!f.exists()) { fail("?[" + testFile + "] ????????"); return; } String ifModifiedSince = DateUtil.formatDate(new Date(f.lastModified() - 1000)); assertTrue(projectLogoManager.isModified(projectId, ifModifiedSince)); }
From source file:com.boundlessgeo.geoserver.api.controllers.MapController.java
JSONObj map(JSONObj obj, LayerGroupInfo map, String wsName) { obj.put("name", map.getName()).put("workspace", wsName).put("title", map.getTitle()).put("abstract", map.getAbstract());/*from ww w .jav a 2 s .c o m*/ ReferencedEnvelope bounds = map.getBounds(); IO.proj(obj.putObject("proj"), bounds.getCoordinateReferenceSystem(), null); IO.bounds(obj.putObject("bbox"), bounds); if (!obj.has("modified")) { String path = Paths.path("workspaces", wsName, "layergroups", String.format("%s.xml", map.getName())); Resource r = geoServer.getCatalog().getResourceLoader().get(path); if (r.getType() == Type.RESOURCE) { long modified = r.lastmodified(); String time = DateUtil.formatDate(new Date(modified)); obj.put("modified", time); } } obj.put("layer_count", map.getLayers().size()); return obj; }
From source file:hudson.plugins.doclinks.artifacts.ArtifactsDocLinksDocumentHudsonTest.java
public void testLastModifiedSince() throws Exception { WebClient wc = getWebClient();/*from ww w . jav a 2s . com*/ FreeStyleProject p = createFreeStyleProject(); p.getBuildersList().clear(); p.getPublishersList().clear(); p.getPublishersList().add(new ArtifactArchiver("artifact1.zip", null, false)); p.getPublishersList().add(new ArtifactsDocLinksPublisher( Arrays.asList(new ArtifactsDocLinksConfig("Test", "artifact1.zip", null, null)))); p.save(); updateTransientActions(p); // Opening configure with TestZipBuilder causes 500. p.getBuildersList().add(new CleanupBuilder()); p.getBuildersList().add(new TestZipBuilder("artifact1.zip")); ArtifactsDocLinksProjectAction projectAction = p.getAction(ArtifactsDocLinksProjectAction.class); FreeStyleBuild build = p.scheduleBuild2(0).get(BUILD_TIMEOUT, TimeUnit.SECONDS); ArtifactsDocLinksAction action = build.getAction(ArtifactsDocLinksAction.class); ArtifactsDocLinksDocument doc = action.getArtifactsDocLinksDocumentList().get(0); Page page = wc.getPage(new URL(wc.getContextPath() + p.getUrl() + String.format("%s/%s", projectAction.getUrlName(), doc.getUrl()))); assertEquals(200, page.getWebResponse().getStatusCode()); Date lastModified = DateUtil.parseDate(page.getWebResponse().getResponseHeaderValue("Last-Modified")); assertNotNull(lastModified); wc.addRequestHeader("If-Modified-Since", DateUtil.formatDate(lastModified)); page = wc.getPage(new URL(wc.getContextPath() + p.getUrl() + String.format("%s/%s", projectAction.getUrlName(), doc.getUrl()))); assertEquals(304, page.getWebResponse().getStatusCode()); page = wc.getPage(new URL(wc.getContextPath() + p.getUrl() + String.format("%s/%s", projectAction.getUrlName(), doc.getUrl()))); assertEquals(304, page.getWebResponse().getStatusCode()); Thread.sleep(1000); build = p.scheduleBuild2(0).get(BUILD_TIMEOUT, TimeUnit.SECONDS); action = build.getAction(ArtifactsDocLinksAction.class); doc = action.getArtifactsDocLinksDocumentList().get(0); page = wc.getPage(new URL(wc.getContextPath() + p.getUrl() + String.format("%s/%s", projectAction.getUrlName(), doc.getUrl()))); assertEquals(200, page.getWebResponse().getStatusCode()); }
From source file:jp.co.opentone.bsol.linkbinder.view.logo.ProjectLogoManagerTest.java
/** * projectId:??ifModifiedSince:???//from w ww . j a va2 s .com */ @Test public void testIsModified6() { String projectId = "test-project"; String testFile = MockSystemConfig.CONFIG_PROJECT_LOGO_DIR + "/" + projectId + ".png"; File f = new File(testFile); if (!f.exists()) { fail("?[" + testFile + "] ????????"); return; } MockSystemConfig.CONFIG_PROJECT_LOGO_DEFAULT = "test-default.png"; String testFile2 = MockSystemConfig.CONFIG_PROJECT_LOGO_DIR + "/" + MockSystemConfig.CONFIG_PROJECT_LOGO_DEFAULT; File f2 = new File(testFile2); if (!f2.exists()) { fail("?[" + testFile2 + "] ????????"); return; } String ifModifiedSince = DateUtil.formatDate(new Date(f.lastModified())); assertFalse(projectLogoManager.isModified(projectId, ifModifiedSince)); }