Is there some way to get modified date of this file?
I want to check the data every day and download it only if has changed, I tried with HttpURLConnection and con.getHeaderFields() but no results:
{null=[HTTP/1.1 200 OK], Access-Control-Allow-Origin=[*], Age=[158], Cache-Control=[max-age=7200], Connection=[close], Content-Length=[235409], Content-Type=[text/plain], Date=[Wed, 19 Dec 2012 10:00:52 GMT], Expires=[Wed, 19 Dec 2012 11:58:13 GMT], Server=[Apache/2], X-Android-Received-Millis=[1355911252001], X-Android-Sent-Millis=[1355911251975]}
Is there a better way of getting an md5 hash and compare it with a local file?
Nope, there is no general way to get the modified date of a URL. Computing the MD5 hash of the HTTP response body and comparing that against the local file is the best way.
Related
I'm trying to select a record from particular view in Airtable using the Java library
So far i have set break points to check if everything is initialised and it seems be okay. My api key is correct and the Airtable instance is setup correctly.
Airtable airtable = new Airtable().configure(AIRTABLE_API_KEY);
Base basebase = airtable.base("my-airtable-base");
This is my error:
Nov 12, 2020 5:53:08 PM org.apache.http.client.protocol.ResponseProcessCookies processCookies
WARNING: Invalid cookie header: "Set-Cookie: brw=brwkel6HWNoWVEl49; path=/; expires=Fri, 12 Nov 2021 17:53:08 GMT; domain=.airtable.com; samesite=none; secure; httponly". Invalid 'expires' attribute: Fri, 12 Nov 2021 17:53:08 GMT
Exception in thread "main" com.sybit.airtable.exception.AirtableException: {"error":"NOT_FOUND"} (UNDEFINED_ERROR) [Http code 404]
at com.sybit.airtable.exception.HttpResponseExceptionHandler.onResponse(HttpResponseExceptionHandler.java:29)
at com.sybit.airtable.Table.select(Table.java:206)
at com.sybit.airtable.Table.select(Table.java:327)
at com.hived.AirtableInstance.selectTableView(AirtableInstance.java:43)
at com.hived.Main.main(Main.java:25)
This is the function that is causing the error:
public void selectTableView() throws AirtableException, HttpResponseException {
List<Bus> stops = base.table("Bus").select("Stops");
}
I was expecting it to pass all stops from the bus table into the stops list.
I'm not sure what I'm doing wrong, so any help would be much appreciated.
Turns out you need to do a few things.
Add log4j to your project
Add slf4j-simple to your project
Once those dependencies are added. You should now see there is no warning anymore.
Now to remove the error. It turns out instead of referencing the base name, you need to call the base id instead.
base = airtable.base("applJilugnJCtDRdh");
Thats it! Hope this helps anyone else.
When i am trying to fetch the comments the i am getting this error message.
article_url = "http://de.richarddawkins.net/articles/atheist-stephen-hawking-negiert-existenz-eines-gottes-die-wissenschaft-biete-eine-uberzeugendere-erklarung-des-universums"
HTTParty.get("https://graph.facebook.com/comments?id=#{article_url}")
#<HTTParty::Response:0xb4fa49c parsed_response={"error"=>{"message"=>"An access token is required to request this resource.", "type"=>"OAuthException", "code"=>104, "fbtrace_id"=>"Asfda7D+/qM"}}, #response=#<Net::HTTPBadRequest 400 Bad Request readbody=true>, #headers={"www-authenticate"=>["OAuth \"Facebook Platform\" \"invalid_token\" \"An access token is required to request this resource.\""], "access-control-allow-origin"=>["*"], "pragma"=>["no-cache"], "cache-control"=>["no-store"], "facebook-api-version"=>["v2.2"], "expires"=>["Sat, 01 Jan 2000 00:00:00 GMT"], "content-type"=>["application/json; charset=UTF-8"], "x-fb-trace-id"=>["Asfda7D+/qM"], "x-fb-rev"=>["2778708"], "vary"=>["Accept-Encoding"], "x-fb-debug"=>["pSZo8HXiIaM0tu9f0ss+swqnhShjgCQYpm3GN8GQS+olRNjmwTfiHPPE/8xZJRxu787j7JlwCHW9kwuayjcgeA=="], "date"=>["Mon, 16 Jan 2017 06:23:43 GMT"], "connection"=>["close"], "content-length"=>["139"]}>
Please help me to solve this problem.
I think you need to just add ACCESS_TOKEN into your query string.
Ex.
HTTParty.get("https://graph.facebook.com/comments?id=#{article_url}&access_token=#{ACCESS_TOKEN}")
Hope it's work
I'm building a web service in java, deploying it under Jboss-as-7.1.1.Final, based on org.apache.cxf.
I need to expose a web method that takes in input a date field that can reach many centuries in the past.
At the moment I'm using java.util.Date.
So, my web method is
public UpdatePersonResponse updatePerson(UpdatePersonRequest request) {
...
}
the request bean UpdatePersonRequest has:
...
private Date birthday;
...
In the soap request that I'm testing I put:
<!--Optional:-->
<birthday>1452-04-15</birthday>
The apache cxf logs show:
16:07:36,568 INFO [org.apache.cxf.interceptor.LoggingInInterceptor] ... Inbound Message
[...]
<birthday>1452-04-15</birthday>
(this is correct)
A custom log I added into the set method of the request bean shows:
16:07:36,843 DEBUG com.xxx.xxx.service.request.UpdatePersonRequest ... called setBirthday with argument [06/04/52 0.00]
(this is wrong)
Then the request bean is valorized as follows:
UpdatePersonRequest [... birthday=Thu Apr 06 00:00:00 CET 1452, ...]
(this is wrong)
So I obtain 1452 April 06, and not 1452 April 15.
I tried with different dates, for example,
soap:
<birthday>1452-04-30</birthday>
custom log:
21:11:51,607 DEBUG [com.xxx.xxx.service.request.UpdatePersonRequest] ... called setBirthday with argument [21/04/52 0.00]
(wrong)
The bean is:
UpdatePersonRequest [... birthday=Fri Apr 21 00:00:00 CET 1452 ...]
(again wrong)
I obtain April 21 and not April 30.
I tried with several dates and noticed that the issue occurs for dates prior then 15 Oct 1582. For more recent dates all works fine and the request bean is correctly valorized.
Is there some java.util.Date limitation that I'm not considering?
Should I use another java Type to represent these kind of dates, and what?
Thank you very much.
EDIT
The effect is that the date I entered into the soap request is converted in Julian date and then the Date I persist on the database will be this converted date.
But I'd like to write on DB the exact date I enter in the request and not a corrected one, in other words I want the caller to deal with the right date system to use, and not any conversion be made automatically by the system.
How can I obtain this?
You are encountering the switch from the Julian to the Gregorian calendar. This is a historical event, not a feature of Java. Googling "Gregorian calendar" will tell you more.
I'm downloading a JAR file, and would like to utilize If-Modified-Since so I don't get the whole file if I don't need it, but for some reason my vanilla Apache (afaik) isn't returning the 304 correctly.
This is from wireshark:
GET /whatever.jar HTTP/1.1
If-Modified-Since: Sat, 04 Jan 2014 21:46:26 GMT
User-Agent: Jakarta Commons-HttpClient/3.1
Host: example.com
HTTP/1.1 200 OK
Date: Sat, 04 Jan 2014 20:32:31 GMT
Server: Apache/2.2.4 (Unix) mod_ssl/2.2.4 OpenSSL/0.9.8e DAV/2 mod_jk/1.2.26 PHP/5.3.6 SVN/1.4.4
Last-Modified: Sat, 04 Jan 2014 19:13:14 GMT
ETag: "b6c037-1ddad9f-d17a6680"
Accept-Ranges: bytes
Content-Length: 31305119
Vary: User-Agent
Content-Type: text/plain
... [bunch of bytes] ...
There aren't other headers I need to specify, is there? Am I missing a module that Apache needs in order to read this header correctly?
Any other thoughts or suggestions?
Here is my Java code, for reference:
File jarFile = new File(filePath);
GetMethod get = new GetMethod(downloadUrl);
Date lastModified = new Date(jarFile.lastModified());
get.setRequestHeader("If-Modified-Since", DateUtil.formatDate(lastModified));
HttpClient client = new HttpClient();
int code = client.executeMethod(get);
UPDATE: Solution
The If-Modified-Date needed to exactly match the server, and I achieved this by explicitly setting the lastModifiedDate on the downloaded file:
String serverModified = get.getResponseHeader("Last-Modified").getValue();
jarFile.setLastModified(DateUtil.parseDate(serverModified).getTime());
After doing this, subsequent calls would not download the file.
In order to use the "If-Modified-Since" header, you must send an identical header value as the "Last-Modified" header, that is Sat, 04 Jan 2014 19:13:14 GMT != Sat, 04 Jan 2014 21:46:26 GMT. Apache cannot guarantee the file wasn't modified and given a past time on purpose (perhaps through a version control roll-back).
If you want, you may check the "Last-Modified" header on the client side, by using a HeadMethod first to avoid "getting" the resource if it hasn't been modified. Then you would use a "GetMethod" if it has been modified.
See RFC2616 - Section 9, "HTTP/1.1: Method Definitions" for more.
I'm trying to use javamail to download a mailbox of 1000 messages of hotmail.
The problem is after an hour or so, I get a Pop Session timeout exception, and I can't fetch messages anymore.
C: TOP 3210 0
S: +OK 1444 byte(s)
X-Message-Delivery: Vj0zLjQuMDt1cz0wO2k9MDtsPTA7YT0x
X-Message-Status: n:0
X-SID-PRA: Super Wall <apps+ocdlfcez#facebookmail.com>
X-SID-Result: Pass
X-Message-Info: R00BdL5giqoqgO8FeGWl8Lch6n3is6BT1wNitKPj0Jb+fghk1p9MsC+MFGyB2nflerotq/xZ5r8LiguM+3GjEOSj3umkoXeU
Received: from mx-out.facebook.com ([204.15.20.140]) by bay0-mc7-f15.bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.2668);
Tue, 8 Apr 2008 15:14:55 -0700
Received: from api.facebook.com (intlb01-mip1.sctm.tfbnw.net [10.1.240.6])
by mx-out.facebook.com [email018.sctm.facebook.com] (8.13.6/8.13.6) with ESMTP id m38MEtOg030239
for <xgameprogrammer#hotmail.com>; Tue, 8 Apr 2008 15:14:55 -0700
X-Facebook: from zuckmail ([168.143.164.188])
by api.facebook.com with HTTP (ZuckMail);
Date: Tue, 8 Apr 2008 15:14:55 -0700
To: Ahmed Saleh <xgameprogrammer#hotmail.com>
From: Super Wall <apps+ocdlfcez#facebookmail.com>
Reply-to: Facebook <apps+ocdlfcez#facebookmail.com>
Subject: You just received a new photo from Lejla Boric
Message-ID: <03df95f3306af0a88432e7fcca22f7ac#api.facebook.com>
X-Priority: 3
X-Mailer: ZuckMail [version 1.00]
X-Facebook-Notify: platform_email
Errors-To: apps+ocdlfcez#facebookmail.com
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="b1_03df95f3306af0a88432e7fcca22f7ac"
Return-Path: apps+ocdlfcez#facebookmail.com
X-OriginalArrivalTime: 08 Apr 2008 22:14:55.0926 (UTC) FILETIME=[F9D6A560:01C899C5]
.
C: RETR 3210
S: -ERR POP3 session timed out
javax.mail.MessagingException: No inputstream from datasource;
SentDate : Wed Apr 09 01:14:55 AST 2008
nested exception is:
As I said in my comment, this is just a simple case of the session timing out. Like anything, the mail server will have a time limit to prevent excessive access, which is how would describe downloading emails for over an hour!
There is nothing wrong with your code, your just asking too much of hotmail / the mail server!
Though, just some friendly advice: the next time you ask a question here on SO, please don't post irrelevant information like you have done here. In cases like yours, it is helpful to see atleast a snippet of the code that is responsible for that part of the application that is functioning incorrectly and any exceptions - we'd also need to see the line(s) of code mentioned in the stack trace... However, a start would be to actually ask a question instead of this stating a fact, like you have done here!