Skip to content

Commit 0450a65

Browse files
committed
DM-8157: Cleanup of URLFileInfoProcessor, removed redudent logging, and better handling of URL status 500
1 parent 0a1df68 commit 0450a65

File tree

8 files changed

+38
-84
lines changed

8 files changed

+38
-84
lines changed

src/firefly/java/edu/caltech/ipac/firefly/server/packagedata/FileInfo.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class FileInfo implements HasAccessInfo {
2424
private boolean hasAccess = true;
2525
private Object extraData = null;
2626
private Map<String, String> cookies;
27+
private int responseCode= -1;
2728

2829
private FileNameResolver _resolver = null;
2930

@@ -38,6 +39,13 @@ public FileInfo(String internalFilename, String externalName, long sizeInBytes)
3839
_sizeInBytes = sizeInBytes;
3940
}
4041

42+
public FileInfo(String internalFilename, String externalName, long sizeInBytes, int responseCode) {
43+
_internalFilename = internalFilename;
44+
_externalName = externalName;
45+
_sizeInBytes = sizeInBytes;
46+
this.responseCode= responseCode;
47+
}
48+
4149
public FileInfo(String internalFilename, FileNameResolver resolver, long sizeInBytes) {
4250
_internalFilename = internalFilename;
4351
_externalName = null;
@@ -126,6 +134,8 @@ public String resolveFileName(String name) {
126134
return _resolver.getResolvedName(name);
127135
}
128136

137+
public int getResponseCode() { return responseCode; }
138+
129139
public interface FileNameResolver {
130140
public String getResolvedName(String input);
131141
}

src/firefly/java/edu/caltech/ipac/firefly/server/query/BaseFileInfoProcessor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ public FileInfo getData(ServerRequest request) throws DataAccessException {
4343
}
4444
onComplete(request, fi);
4545
return fi;
46+
} catch (DataAccessException e) {
47+
throw e;
4648
} catch (Exception e) {
47-
_logger.error(e, "Error while processing request:" + StringUtils.truncate(request, 256));
4849
throw new DataAccessException("Request failed due to unexpected exception: ", e);
4950
}
5051
}

src/firefly/java/edu/caltech/ipac/firefly/server/query/URLFileInfoProcessor.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@
77
import edu.caltech.ipac.firefly.server.ServerContext;
88
import edu.caltech.ipac.firefly.server.packagedata.FileInfo;
99
import edu.caltech.ipac.firefly.server.visualize.LockingVisNetwork;
10+
<<<<<<< Updated upstream
11+
=======
12+
import edu.caltech.ipac.util.FileUtil;
13+
>>>>>>> Stashed changes
1014
import edu.caltech.ipac.util.download.FailedRequestException;
1115
import edu.caltech.ipac.visualize.net.AnyUrlParams;
1216

17+
import java.io.File;
1318
import java.io.IOException;
1419
import java.net.MalformedURLException;
1520
import java.net.URL;
@@ -40,6 +45,21 @@ protected FileInfo loadData(ServerRequest sr) throws IOException, DataAccessExce
4045
}
4146
}
4247
retval= LockingVisNetwork.getFitsFile(params);
48+
if (retval.getResponseCode()>=500) {
49+
File f= new File(retval.getInternalFilename());
50+
if (f.length()<800) {
51+
String fileData= FileUtil.readFile(f);
52+
_logger.warn("Could not retrieve URL, status: "+ retval.getResponseCode(),
53+
"response: "+ fileData);
54+
f.delete();
55+
throw new DataAccessException("Could not retrieve file: "+ fileData);
56+
}
57+
else {
58+
_logger.warn("Could not retrieve URL, status: "+ retval.getResponseCode());
59+
throw new DataAccessException("Could not retrieve file");
60+
}
61+
}
62+
_logger.info("retrieving URL:" + url.toString());
4363
} catch (FailedRequestException e) {
4464
_logger.warn(e, "Could not retrieve URL");
4565
} catch (MalformedURLException e) {

src/firefly/java/edu/caltech/ipac/firefly/server/visualize/LockingVisNetwork.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ private static FileInfo lockingRetrieve(BaseNetParams params, boolean unzip)
7474
edu.caltech.ipac.util.download.FileData fd = VisNetwork.getImage(params, dl);
7575
File fitsFile = fd.getFile();
7676
if (unzip) fitsFile = unzip(fitsFile);
77-
retval = new FileInfo(fitsFile.getPath(), fd.getSuggestedExternalName(), fitsFile.length());
77+
retval = new FileInfo(fitsFile.getPath(), fd.getSuggestedExternalName(), fitsFile.length(), fd.getResponseCode());
7878
}
7979
} finally {
8080
if (params != null) _activeRequest.remove(params);

src/firefly/java/edu/caltech/ipac/firefly/server/visualize/VisServerOps.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,11 +1450,9 @@ private static WebPlotResult createError(String logMsg, PlotState state, WebPlot
14501450
if (e instanceof FileRetrieveException) {
14511451
FileRetrieveException fe = (FileRetrieveException) e;
14521452
retval = WebPlotResult.makeFail("Retrieve failed", "Could not retrieve fits file", fe.getDetailMessage(), progressKey, plotId);
1453-
fe.setSimpleToString(true);
14541453
} else if (e instanceof FailedRequestException) {
14551454
FailedRequestException fe = (FailedRequestException) e;
14561455
retval = WebPlotResult.makeFail(fe.getUserMessage(), fe.getUserMessage(), fe.getDetailMessage(), progressKey, plotId);
1457-
fe.setSimpleToString(true);
14581456
userAbort = VisContext.PLOT_ABORTED.equals(fe.getDetailMessage());
14591457
} else if (e instanceof SecurityException) {
14601458
retval = WebPlotResult.makeFail("No Access", "You do not have access to this data,", e.getMessage(), progressKey, plotId);

src/firefly/java/edu/caltech/ipac/firefly/server/visualize/WebPlotFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,10 @@ private static WebPlotInitializer[] create(Map<Band, WebPlotRequest> requestMap,
229229
throw e;
230230
} catch (FailedRequestException e) {
231231
updateProgressIsFailure(saveRequest);
232-
throw new FailedRequestException("Could not create plot. " , e.getDetailMessage() + ": "+ e.getMessage() );
232+
throw new FailedRequestException("Could not create plot. " , e.getDetailMessage() + ": "+ e.getMessage(),e);
233233
} catch (FitsException e) {
234234
updateProgressIsFailure(saveRequest);
235-
throw new FailedRequestException("Could not create plot. Invalid FITS File format.", e.getMessage());
235+
throw new FailedRequestException("Could not create plot. Invalid FITS File format.", e.getMessage(),e);
236236
} catch (Exception e) {
237237
updateProgressIsFailure(saveRequest);
238238
throw new FailedRequestException("Could not create plot.", e.getMessage(), e);

src/firefly/java/edu/caltech/ipac/firefly/server/visualize/imageretrieve/ProcessorFileRetriever.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
import edu.caltech.ipac.firefly.server.packagedata.FileInfo;
1515
import edu.caltech.ipac.firefly.server.query.DataAccessException;
1616
import edu.caltech.ipac.firefly.server.query.SearchManager;
17-
import edu.caltech.ipac.firefly.server.util.Logger;
1817
import edu.caltech.ipac.firefly.server.util.QueryUtil;
1918
import edu.caltech.ipac.firefly.visualize.WebPlotRequest;
19+
import edu.caltech.ipac.util.download.FailedRequestException;
2020
import edu.caltech.ipac.visualize.plot.GeomException;
2121

2222
import java.io.File;
@@ -48,11 +48,9 @@ public FileData getFile(WebPlotRequest request) throws FailedRequestException, G
4848
File f= new File(fi.getInternalFilename());
4949
return new FileData(f, f.getName());
5050
} catch (DataAccessException dae) {
51-
Logger.error(dae);
5251
throw new FailedRequestException("Unable to get file location info", dae.getMessage(), dae);
5352
} catch (Exception e) {
54-
Logger.error(e);
55-
throw new FailedRequestException("Unable to get file location info", e.getMessage(), e);
53+
throw new FailedRequestException("Unable to get file location info", e.getMessage(), e);
5654
}
5755
}
5856
}

src/firefly/java/edu/caltech/ipac/util/download/FailedRequestException.java

Lines changed: 1 addition & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
*/
44
package edu.caltech.ipac.util.download;
55

6-
import edu.caltech.ipac.util.ServerStringUtil;
7-
import edu.caltech.ipac.util.ThrowableUtil;
8-
96
/**
107
* This exception is thrown when a value is out of range.
118
* @author Trey Roby
@@ -14,13 +11,7 @@
1411
public class FailedRequestException extends Exception {
1512

1613
static public final String SERVICE_FAILED= "Service Failed";
17-
18-
1914
private String _detailMessage;
20-
private boolean _simple= false;
21-
private String _constructedThread= Thread.currentThread().getName();
22-
23-
private static final String NL= "\n";
2415

2516
/**
2617
* Create a new FailedRequestException Exception.
@@ -48,7 +39,7 @@ public FailedRequestException(String mess,
4839
String detailMessage,
4940
Throwable e) {
5041

51-
this(mess, detailMessage, isHtml(mess), e);
42+
this(mess, detailMessage, false, e);
5243
}
5344

5445
/**
@@ -69,68 +60,4 @@ public FailedRequestException(String userMessage,
6960
public String getUserMessage() { return getMessage(); }
7061
public String getDetailMessage() { return _detailMessage; }
7162

72-
public String toString(){
73-
StackTraceElement eAry[]= getStackTrace();
74-
StackTraceElement ste= eAry[0];
75-
String cName= ServerStringUtil.getShortClassName(ste.getClassName());
76-
77-
String detail= "";
78-
String extra= "";
79-
80-
String where = NL + NL +
81-
"========---------- Location -----------=========" +
82-
makeLineReport(this) + NL +
83-
"Thread: " + _constructedThread;
84-
if (_detailMessage != null)
85-
detail= NL + NL +
86-
"========---------- Detailed Message -----------========="
87-
+ NL +_detailMessage;
88-
return super.toString() + detail + where + (_simple? "" : makeCausedBy()) + extra;
89-
}
90-
91-
public void setSimpleToString(boolean simple) {
92-
_simple= simple;
93-
}
94-
95-
private String makeCausedBy() {
96-
String retval= "";
97-
String shortName;
98-
for (Throwable t= getCause(); (t!=null); t= t.getCause()) {
99-
shortName= ServerStringUtil.getShortClassName(t.getClass().getName());
100-
retval+= NL + NL +
101-
"========---------- Caused By " + shortName +
102-
" ----------========" + NL +
103-
ThrowableUtil.getStackTraceAsString(t) +NL+
104-
makeLineReport(t);
105-
}
106-
return retval;
107-
}
108-
109-
110-
private String makeLineReport(Throwable t) {
111-
String where = "";
112-
StackTraceElement eAry[]= t.getStackTrace();
113-
if ((eAry != null) && (eAry.length > 0))
114-
{
115-
StackTraceElement ste= eAry[0];
116-
String cName= ServerStringUtil.getShortClassName(ste.getClassName());
117-
where = NL +
118-
"Class: " + cName + NL +
119-
"Method: " + ste.getMethodName() + NL +
120-
"File: " + ste.getFileName() + NL +
121-
"Line: " + ste.getLineNumber();
122-
}
123-
124-
return where;
125-
}
126-
127-
private static boolean isHtml(String s) {
128-
boolean retval= false;
129-
if (s!=null && s.length()>6 && s.substring(0,6).equals("<html>")) {
130-
retval= true;
131-
}
132-
return retval;
133-
}
13463
}
135-
136-

0 commit comments

Comments
 (0)