if (auth.getScheme().equals("cookie")) {
Cookie cookie = new Cookie(auth.getName(),auth.getPassword());
cookie.setPath("/");
request.getCookies().add(cookie);
} else {
request.setChallengeResponse(new ChallengeResponse(ChallengeScheme.HTTP_BASIC,auth.getName(),auth.getPassword()));
}
}
Response response = client.handle(request);
if (!response.getStatus().isSuccess()) {
log.log(Level.SEVERE,"Failed to retrieve media, status="+response.getStatus().getCode()+", src="+srcRef);
errorCount++;
return;
}
if (contentType!=null) {
// The entry's media type wins. Sometimes file resources do not
// report the media type correctly
response.getEntity().setMediaType(contentType);
}
try {
entry = app.createMediaEntry(user,feed,response.getEntity(),src,entryId);
app.updateEntry(user,feed,entry,entryDoc);
} catch (AppException ex) {
log.severe("Failed to create media entry "+index.getId()+", src="+srcRef);
if (ex.getStatus()==Status.SERVER_ERROR_INTERNAL) {
log.log(Level.SEVERE,ex.getMessage(),ex);
} else {
log.severe("Status="+ex.getStatus().getCode()+", "+ex.getMessage());
}
errorCount++;
}
}
} else {
try {
app.updateEntry(user,feed,entryId,entryDoc);
} catch (AppException ex) {
if (ex.getStatus()==Status.SERVER_ERROR_INTERNAL) {
log.log(Level.SEVERE,ex.getMessage(),ex);
} else {
log.severe("Status="+ex.getStatus().getCode()+", "+ex.getMessage());
}
errorCount++;
return;
}
if (src!=null) {
URI srcRef = baseURI.resolve(src);
Client client = new Client(new Context(log),Protocol.valueOf(srcRef.getScheme()));
client.getContext().getAttributes().put("hostnameVerifier", org.apache.commons.ssl.HostnameVerifier.DEFAULT);
/*
Request headRequest = new Request(Method.HEAD,new Reference(srcRef.toString()));
if (auth!=null) {
headRequest.setChallengeResponse(new ChallengeResponse(ChallengeScheme.HTTP_BASIC,auth.getName(),auth.getPassword()));
}
Response headResponse = client.handle(headRequest);
if (!headResponse.getStatus().isSuccess()) {
log.log(Level.SEVERE,"Failed to retrieve media head, status="+headResponse.getStatus().getCode()+", src="+srcRef);
errorCount++;
return;
}
boolean outOfDate = true;
if (headResponse.isEntityAvailable()) {
outOfDate = headResponse.getEntity().getModificationDate().after(resource.getEdited());
if (outOfDate) {
log.info("Out of date: "+headResponse.getEntity().getModificationDate()+" > "+resource.getEdited());
}
}
*/
Request request = new Request(Method.GET,new Reference(srcRef.toString()));
if (auth!=null) {
if (auth.getScheme().equals("cookie")) {
Cookie cookie = new Cookie(auth.getName(),auth.getPassword());
cookie.setPath("/");
request.getCookies().add(cookie);
} else {
request.setChallengeResponse(new ChallengeResponse(ChallengeScheme.HTTP_BASIC,auth.getName(),auth.getPassword()));
}
}
Date edited = new Date(resource.getEdited().getTime());
request.getConditions().setUnmodifiedSince(edited);
log.info("Attempting update media from "+srcRef.toString()+", edited="+edited);