Project

General

Profile

Revision 6642

Although parameters for setReplicationStatus() are expected as multipart/form-data fields, they seem to be added to the HttpServletRequest as URL parameters during the proxy forwarding in d1_cn_rest_proxy. Test for their existence as multipart fields, but fall back to request params, otherwise, throw an InvalidRequest exception.

View differences:

src/edu/ucsb/nceas/metacat/restservice/CNResourceHandler.java
1143 1143
        try {
1144 1144
            serialVersionStr = multipartparams.get("serialVersion").get(0);
1145 1145
            serialVersion = new Long(serialVersionStr).longValue();
1146
            
1147
        } catch (NullPointerException e) {
1148
            String msg = "The 'serialVersion' must be provided as a parameter and was not.";
1146
        
1147
        } catch (NumberFormatException nfe) {
1148
            String msg = "The 'serialVersion' must be a positive integer and was not.";
1149 1149
            logMetacat.error(msg);
1150 1150
            throw new InvalidRequest("4730", msg);
1151 1151
            
1152
        } catch (NullPointerException e) {
1153
            logMetacat.debug("The 'serialVersion' parameter was not found in the " +
1154
                "multipartparams map.  Trying the params map.");
1155
            try {
1156
                serialVersionStr = params.get("serialVersion")[0];
1157
                serialVersion = new Long(serialVersionStr).longValue();
1158
                
1159
            } catch (NumberFormatException e1) {
1160
                String msg = "The 'serialVersion' must be a positive integer and was not.";
1161
                logMetacat.error(msg);
1162
                throw new InvalidRequest("4730", msg);
1163
                
1164
            } catch (NullPointerException npe) {
1165
                String msg = "The 'serialVersion' must be provided as a parameter and was not.";
1166
                logMetacat.error(msg);
1167
                throw new InvalidRequest("4730", msg);
1168

  
1169
            }
1170
            
1152 1171
        }
1153 1172
        
1154 1173
        // get the replication status param
1155 1174
        try {
1156 1175
            replicationStatus = multipartparams.get("replicationStatus").get(0);
1157 1176
            status = ReplicationStatus.convert(replicationStatus);
1158
        } catch (Exception e) {
1159
            // TODO Auto-generated catch block
1160
            e.printStackTrace();
1177
            
1178
        } catch (NullPointerException npe) {
1179

  
1180
            logMetacat.debug("The 'replicationStatus' parameter was not found in the " +
1181
            "multipartparams map.  Trying the params map.");
1182
            
1183
            try {
1184
                replicationStatus = params.get("replicationStatus")[0];
1185
                status = ReplicationStatus.convert(replicationStatus);
1186
                
1187
            } catch (Exception e) {
1188
                String msg = "The 'replicationStatus' must be provided as a parameter and was not.";
1189
                logMetacat.error(msg);
1190
                throw new InvalidRequest("4730", msg);
1191
                
1192
            }
1193
            
1161 1194
        }
1162 1195
        
1163 1196
        // get the target node reference param
1164
        targetNode = multipartparams.get("nodeRef").get(0);
1165
        targetNodeRef = new NodeReference();
1166
        targetNodeRef.setValue(targetNode);
1197
        try {
1198
            targetNode = multipartparams.get("nodeRef").get(0);
1199
            targetNodeRef = new NodeReference();
1200
            targetNodeRef.setValue(targetNode);
1201
            
1202
        } catch (NullPointerException e) {
1203
            logMetacat.debug("The 'nodeRef' parameter was not found in the " +
1204
            "multipartparams map.  Trying the params map.");
1205
            
1206
            try {
1207
                targetNode = params.get("nodeRef")[0];
1208
                targetNodeRef = new NodeReference();
1209
                targetNodeRef.setValue(targetNode);
1210
                
1211
            } catch (Exception e1) {
1212
                String msg = "The 'nodeRef' must be provided as a parameter and was not.";
1213
                logMetacat.error(msg);
1214
                throw new InvalidRequest("4730", msg);
1215
                
1216
            }
1217
            
1218
        }
1167 1219
        
1168 1220
        result = 
1169 1221
            CNodeService.getInstance(request).setReplicationStatus(session, identifier, targetNodeRef, status, serialVersion);       

Also available in: Unified diff