Skip to content

Commit 2cb760c

Browse files
authored
FIREFLY-94 follow-up: merge pr #837 from Caltech-IPAC/ff94_webdav_bug
FIREFLY-94 follow up: bug fixes
2 parents f81bc3e + 61a4aaf commit 2cb760c

File tree

10 files changed

+56
-28
lines changed

10 files changed

+56
-28
lines changed

src/firefly/java/edu/caltech/ipac/firefly/server/WebDAVWorkspaceManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public String getProp(PROPS prop) {
5555
return propVal;
5656
}
5757
if (propFound.equals(PROPS.ROOT_URL)) {
58-
propVal = WS_HOST_URL;
58+
propVal = getWsHostUrl();
5959
} else if (propFound.equals(PROPS.ROOT_DIR)) {
6060
propVal = getWsHome();
6161
} else if (propFound.equals(PROPS.AUTH)) {
@@ -106,7 +106,7 @@ public WebDAVWorkspaceManager(Partition partition, WsCredentials cred, boolean i
106106

107107
public WebDAVWorkspaceManager(Partition partition, String wsId, boolean initialize) {
108108

109-
Map<String, String> cookies = HttpServiceInput.createWithCredential(WS_HOST_URL).getCookies(); // should look at this again.
109+
Map<String, String> cookies = HttpServiceInput.createWithCredential(getWsHostUrl()).getCookies(); // should look at this again.
110110

111111
this.creds = new WsCredentials(wsId, cookies);
112112
this.partition = partition;

src/firefly/java/edu/caltech/ipac/firefly/server/WebDAVWorkspaceManagerBase.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,19 @@
3737
*/
3838
public abstract class WebDAVWorkspaceManagerBase implements WorkspaceManager {
3939

40-
protected static String WS_HOST_URL = AppProperties.getProperty("workspace.host.url", "https://irsa.ipac.caltech.edu");
40+
private static String WS_HOST_URL = AppProperties.getProperty("workspace.host.url");
4141
private static boolean INFINITY_DEPTH_SUPPORTED = AppProperties.getBooleanProperty("workspace.propfind.infinity", true);
4242

4343
private static final Logger.LoggerImpl LOG = Logger.getLogger();
4444

45+
protected String getWsHostUrl() {
46+
if (StringUtils.isEmpty(WS_HOST_URL)) {
47+
return ServerContext.getRequestOwner().getHostUrl();
48+
} else {
49+
return WS_HOST_URL;
50+
}
51+
}
52+
4553
@Override
4654
public String getProp(PROPS prop) {
4755
// TODO: this method is used only in test - do we need it?
@@ -74,7 +82,7 @@ String getResourceUrl(String relPath) {
7482
LOG.error(e, "Continue with relative path as it is: "+relPath);
7583
e.printStackTrace();
7684
}
77-
return WS_HOST_URL + getAbsPath(valid);
85+
return getWsHostUrl() + getAbsPath(valid);
7886
}
7987

8088
private Namespace getNamespace() {
@@ -480,7 +488,7 @@ private WspaceMeta convertToWspaceMeta(WspaceMeta meta, MultiStatusResponse res)
480488
meta = new WspaceMeta(getWsHome(), URLDecoder.decode(res.getHref().replaceFirst(getWsHome(), ""),"UTF-8"));
481489
}
482490
if (res.getHref() != null) {
483-
meta.setUrl(WS_HOST_URL + res.getHref());
491+
meta.setUrl(getWsHostUrl() + res.getHref());
484492
}
485493
DavPropertySet props = res.getProperties(200);
486494
if (props != null) {
@@ -537,7 +545,7 @@ private boolean executeMethod(DavMethod method, boolean releaseConnection) throw
537545
}
538546

539547
protected HttpServices.Status doExecuteMethod(DavMethod method) throws IOException {
540-
HttpServiceInput input = HttpServiceInput.createWithCredential(WS_HOST_URL);
548+
HttpServiceInput input = HttpServiceInput.createWithCredential(getWsHostUrl());
541549
return HttpServices.executeMethod(method, input);
542550
}
543551

src/firefly/java/edu/caltech/ipac/firefly/server/network/HttpServices.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,9 @@ private static String getResHeader(HttpMethod method, String key) {
382382
}
383383

384384
private static String getDetailDesc(HttpMethod method, HttpServiceInput input) throws URIException {
385-
String desc = "url: " + method.getURI() +
385+
String desc = "name: "+method.getName() +
386+
"\nstatus: "+method.getStatusText()+
387+
"\nurl: " + method.getURI() +
386388
"\nquery_str: " + method.getQueryString() +
387389
"\ninput: " + (input== null ? "" : input.getDesc()) +
388390
"\nREQUEST HEADERS: " + CollectionUtil.toString(method.getRequestHeaders()).replaceAll("\\r|\\n", "") +

src/firefly/java/edu/caltech/ipac/firefly/server/query/tables/IpacTableFromSource.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
import edu.caltech.ipac.firefly.data.TableServerRequest;
1010
import edu.caltech.ipac.firefly.data.table.MetaConst;
1111
import edu.caltech.ipac.firefly.server.ServerContext;
12+
import edu.caltech.ipac.firefly.server.network.HttpServiceInput;
1213
import edu.caltech.ipac.firefly.server.query.DataAccessException;
1314
import edu.caltech.ipac.firefly.server.query.IpacTablePartProcessor;
1415
import edu.caltech.ipac.firefly.server.query.SearchManager;
1516
import edu.caltech.ipac.firefly.server.query.SearchProcessor;
1617
import edu.caltech.ipac.firefly.server.query.SearchProcessorImpl;
17-
import edu.caltech.ipac.firefly.server.query.UserCatalogQuery;
1818
import edu.caltech.ipac.firefly.server.util.QueryUtil;
1919
import edu.caltech.ipac.firefly.server.ws.WsServerUtils;
2020
import edu.caltech.ipac.firefly.visualize.WebPlotRequest;
@@ -27,6 +27,7 @@
2727
import edu.caltech.ipac.util.FileUtil;
2828
import edu.caltech.ipac.util.StringUtils;
2929
import edu.caltech.ipac.util.cache.StringKey;
30+
import edu.caltech.ipac.util.download.FailedRequestException;
3031
import edu.caltech.ipac.util.download.URLDownload;
3132

3233
import java.io.File;
@@ -130,18 +131,25 @@ private File getSourceFile(String source, TableServerRequest request, boolean ch
130131
ext = StringUtils.isEmpty(ext) ? ".ul" : "." + ext;
131132
File nFile = createFile(request, ext);
132133

133-
HttpURLConnection conn = (HttpURLConnection) URLDownload.makeConnection(url);
134+
//HttpURLConnection conn = (HttpURLConnection) URLDownload.makeConnection(url);
135+
HttpServiceInput inputs = HttpServiceInput.createWithCredential(url.toString());
136+
HttpURLConnection conn = (HttpURLConnection)URLDownload.makeConnection(url, inputs.getCookies(), inputs.getHeaders(), false);
137+
134138
// set connect timeout in milliseconds
135139
conn.setConnectTimeout(10000);
136140
if (res == null) {
137-
URLDownload.getDataToFile(conn, nFile, null, false, true, false, Long.MAX_VALUE);
141+
// URLDownload throws FailedRequestException for statuses from 300 inclusive to 400 exclusive,
142+
// need to check for other failures
143+
FileInfo finfo = URLDownload.getDataToFile(conn, nFile, null, false, true, false, Long.MAX_VALUE);
144+
checkForFailures(finfo);
138145
res = nFile;
139146
getCache().put(key, res);
140147
} else if (checkForUpdates) {
141148
FileUtil.writeStringToFile(nFile, "workaround");
142149
nFile.setLastModified(res.lastModified());
143150
FileInfo finfo = URLDownload.getDataToFile(conn, nFile, null, false, true, true, Long.MAX_VALUE);
144151
if (finfo.getResponseCode() != HttpURLConnection.HTTP_NOT_MODIFIED) {
152+
checkForFailures(finfo);
145153
res = nFile;
146154
getCache().put(key, res);
147155
}
@@ -215,6 +223,11 @@ private boolean isWorkspace(ServerRequest r) {
215223
return ServerParams.IS_WS.equals(r.getParam(ServerParams.SOURCE_FROM));
216224
}
217225

218-
226+
private void checkForFailures(FileInfo finfo) throws FailedRequestException {
227+
if (finfo.getResponseCode() < 200 || finfo.getResponseCode() > 300) {
228+
throw new FailedRequestException("Request failed with status "+finfo.getResponseCode()+" "+
229+
finfo.getResponseCodeMsg());
230+
}
231+
}
219232
}
220233

src/firefly/java/edu/caltech/ipac/firefly/server/ws/WsServerUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public String upload(WsServerParams wsParams) throws IOException, FailedRequestE
233233
public File getTempUploadFile(String fileName) throws IOException {
234234
String ext = resolveExt(fileName);
235235

236-
return File.createTempFile("ws-upload", ext, ServerContext.getTempWorkDir());
236+
return File.createTempFile("ws-upload", ext, ServerContext.getUploadDir());
237237
}
238238

239239
public static class WsJson {

src/firefly/js/tables/ui/BasicTableView.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const BasicTableViewInternal = React.memo((props) => {
6060

6161
useEffect( () => {
6262
const changes = {};
63-
if (!columnWidths) changes.columnWidths = columnWidthsInPixel(columns, data);
63+
if (!isEmpty(columns) && !columnWidths) changes.columnWidths = columnWidthsInPixel(columns, data);
6464
if (adjScrollTop !== scrollTop) changes.scrollTop = adjScrollTop;
6565
if (adjScrollLeft !== scrollLeft) changes.scrollLeft = adjScrollLeft;
6666

src/firefly/js/ui/WorkspaceViewer.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, {memo} from 'react';
22
import PropTypes from 'prop-types';
3-
import {get} from 'lodash';
3+
import {get, truncate} from 'lodash';
44
import {isFunction, isNil, isEmpty} from 'lodash';
55
import {useFieldGroupConnector} from './FieldGroupConnector.jsx';
66
import {FieldGroup} from './FieldGroup.jsx';
@@ -65,7 +65,7 @@ export const WorkspaceView = memo( (props) => {
6565
}
6666
return (
6767
<div style={wrapperStyle}>
68-
{FilePicker({files, selectedItem: selectedFile?selectedItem:WS_HOME+'/', keepSelect, openFolders, ...eventHandlers})}
68+
{FilePicker({files, selectedItem, keepSelect, openFolders, ...eventHandlers})}
6969
</div>
7070
);
7171
});
@@ -383,7 +383,7 @@ function doUploadWorkspace(file, params={}) {
383383
* @param options
384384
*/
385385
export function doDownloadWorkspace(url, options) {
386-
fetchUrl(url, options).then( (response) => {
386+
fetchUrl(url, {method: 'post', ...options}).then( (response) => {
387387
response.json().then( (value) => {
388388
if (value.ok === 'true') {
389389
dispatchWorkspaceCreatePath({files: value.result});
@@ -392,7 +392,7 @@ export function doDownloadWorkspace(url, options) {
392392
'Save to workspace');
393393
}
394394
});
395-
});
395+
}).catch(({message}) => showInfoPopup(truncate(message, {length: 200}), 'Unexpected error'));
396396
}
397397

398398
export function workspacePopupMsg(msg, title) {

src/firefly/js/ui/tap/TapUtil.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ export function loadTapSchemas(serviceUrl) {
6060
if (getColumnIdx(tableModel, 'schema_index') >= 0) {
6161
sortTableData(tableModel.tableData.data, tableModel.tableData.columns, sortInfoString('schema_index'));
6262
}
63+
if (getColumnIdx(tableModel, 'schema_name') < 0) {
64+
tableModel.error = 'Invalid schemas table';
65+
}
6366
} else {
6467
tableModel.error = 'No schemas available';
6568
}
@@ -88,6 +91,10 @@ export function loadTapTables(serviceUrl, schemaName) {
8891
if (getColumnIdx(tableModel, 'table_index') >= 0) {
8992
sortTableData(tableModel.tableData.data, tableModel.tableData.columns, sortInfoString('table_index'));
9093
}
94+
if (getColumnIdx(tableModel, 'table_name') < 0) {
95+
tableModel.error = `Invalid tables returned for ${serviceUrl} schema ${schemaName}`;
96+
logError(tableModel.error);
97+
}
9198
} else {
9299
tableModel.error = `No tables available for ${serviceUrl} schema ${schemaName}`;
93100
logError(tableModel.error);
@@ -122,6 +129,10 @@ export function loadTapColumns(serviceUrl, schemaName, tableName) {
122129
if (getColumnIdx(tableModel, 'column_index') >= 0) {
123130
sortTableData(tableModel.tableData.data, tableModel.tableData.columns, sortInfoString('column_index'));
124131
}
132+
if (getColumnIdx(tableModel, 'column_name') < 0) {
133+
tableModel.error = `Invalid columns table returned for ${serviceUrl} schema ${schemaName} table ${tableName}`;
134+
logError(tableModel.error);
135+
}
125136
} else {
126137
tableModel.error = `No columns available for ${serviceUrl} schema ${schemaName} table ${tableName}`;
127138
logError(tableModel.error);

src/firefly/js/util/WebUtil.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -320,15 +320,9 @@ export function fetchUrl(url, options, doValidation= true, enableDefOptions= tru
320320
if (response.ok) {
321321
return response;
322322
} else if(response.status === 401){
323-
return new Error('You are no longer logged in');
323+
throw new Error('You are no longer logged in');
324324
} else {
325-
return new Error(`${url} failed with status: ${response}.statusText`);
326-
}
327-
}).catch( (error) => {
328-
if (error.name === 'AbortError') {
329-
throw error; // fetch aborted
330-
} else {
331-
throw new Error(`Request failed: ${url}`, error);
325+
throw new Error(`Request failed with status ${response.status}: ${url}`);
332326
}
333327
});
334328
}

src/firefly/js/visualize/WorkspaceCntlr.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,12 @@ function createPath(action) {
166166
dispatch(action);
167167
} else {
168168
workspacePopupMsg('Create workspace path fails: '+ value.status,
169-
'Create workspace foloder');
169+
'Create workspace folder');
170170
}
171171
});
172172
}).catch( (error) => {
173-
workspacePopupMsg('Create workspace path fails" ' + error.message,
174-
' Create workspace foloder');
173+
workspacePopupMsg('Create workspace path fails: ' + error.message,
174+
' Create workspace folder');
175175
});
176176
}
177177
}

0 commit comments

Comments
 (0)