Project

General

Profile

« Previous | Next » 

Revision 6282

route all /d1/cn/* traffic through the CNRestServlet/Handler -- inspect the pathInfo when deciding what action to take and also strip off any extra parts (like pid).
include query() method pass-through to CNodeService

View differences:

lib/web.xml.tomcat5
266 266
		<servlet-name>CNRestServlet</servlet-name>
267 267
		<url-pattern>/d1/cn/*</url-pattern>
268 268
	</servlet-mapping>
269
	<!-- CNCore-->
270
	<servlet-mapping>
271
		<servlet-name>CNRestServlet</servlet-name>
272
		<url-pattern>/d1/cn/object/*</url-pattern>
273
	</servlet-mapping>
274
	<servlet-mapping>
275
		<servlet-name>CNRestServlet</servlet-name>
276
		<url-pattern>/d1/cn/formats/*</url-pattern>
277
	</servlet-mapping>
278
	<servlet-mapping>
279
		<servlet-name>CNRestServlet</servlet-name>
280
		<url-pattern>/d1/cn/log/*</url-pattern>
281
	</servlet-mapping>
282
	<servlet-mapping>
283
		<servlet-name>CNRestServlet</servlet-name>
284
		<url-pattern>/d1/cn/reserve/*</url-pattern>
285
	</servlet-mapping>
286
	<servlet-mapping>
287
		<servlet-name>CNRestServlet</servlet-name>
288
		<url-pattern>/d1/cn/meta/*</url-pattern>
289
	</servlet-mapping>
290
	<!-- CNRead-->
291
	<servlet-mapping>
292
		<servlet-name>CNRestServlet</servlet-name>
293
		<url-pattern>/d1/cn/resolve/*</url-pattern>
294
	</servlet-mapping>
295
	<servlet-mapping>
296
		<servlet-name>CNRestServlet</servlet-name>
297
		<url-pattern>/d1/cn/assertRelation/*</url-pattern>
298
	</servlet-mapping>
299
	<servlet-mapping>
300
		<servlet-name>CNRestServlet</servlet-name>
301
		<url-pattern>/d1/cn/checksum/*</url-pattern>
302
	</servlet-mapping>
303
	<!-- CNAuthorization -->
304
	<servlet-mapping>
305
		<servlet-name>CNRestServlet</servlet-name>
306
		<url-pattern>/d1/cn/owner/*</url-pattern>
307
	</servlet-mapping>
308
	<servlet-mapping>
309
		<servlet-name>CNRestServlet</servlet-name>
310
		<url-pattern>/d1/cn/isAuthorized/*</url-pattern>
311
	</servlet-mapping>
312
	<servlet-mapping>
313
		<servlet-name>CNRestServlet</servlet-name>
314
		<url-pattern>/d1/cn/accessRules/*</url-pattern>
315
	</servlet-mapping>
316
	<!-- CNReplication -->
317
	<servlet-mapping>
318
		<servlet-name>CNRestServlet</servlet-name>
319
		<url-pattern>/d1/cn/notify/*</url-pattern>
320
	</servlet-mapping>
321
	<servlet-mapping>
322
		<servlet-name>CNRestServlet</servlet-name>
323
		<url-pattern>/d1/cn/meta/replication/*</url-pattern>
324
	</servlet-mapping>
325
	<servlet-mapping>
326
		<servlet-name>CNRestServlet</servlet-name>
327
		<url-pattern>/d1/cn/meta/policy/*</url-pattern>
328
	</servlet-mapping>
329 269
	
330 270
	<!-- MN REST services -->
331 271
	<servlet-mapping>
src/edu/ucsb/nceas/metacat/restservice/CNResourceHandler.java
28 28
import java.io.IOException;
29 29
import java.io.InputStream;
30 30
import java.io.OutputStream;
31
import java.io.PrintWriter;
32 31
import java.io.UnsupportedEncodingException;
33 32
import java.util.Date;
34 33
import java.util.Map;
......
62 61
import org.dataone.service.types.ObjectFormatList;
63 62
import org.dataone.service.types.ObjectLocationList;
64 63
import org.dataone.service.types.Permission;
64
import org.dataone.service.types.QueryType;
65 65
import org.dataone.service.types.Subject;
66 66
import org.dataone.service.types.SystemMetadata;
67 67
import org.jibx.runtime.JiBXException;
......
135 135
    	super.handle(httpVerb);
136 136
    	
137 137
        try {
138
            //substring off the "d1/cn/" part of the url
139
        	String resourcePrefix = RESOURCE_BASE_URL + "/cn/";
140
            String resource = request.getServletPath();
141
            resource = resource.substring(resource.indexOf(resourcePrefix) + resourcePrefix.length());
142
            resource = resource.trim();
138

  
139
        	// get the resource
140
            String resource = request.getPathInfo();
141
            resource = resource.substring(resource.indexOf("/") + 1);
143 142
                        
143
            // get the rest
144
            String extra = null;
145
            if (resource.lastIndexOf("/") != -1) {
146
                extra = resource.substring(resource.lastIndexOf("/") + 1);
147
            }
148
            
144 149
            logMetacat.debug("handling verb " + httpVerb + " request with resource '" + resource + "'");
145 150
            boolean status = false;
146 151

  
147 152
            if (resource != null) {
148 153

  
149
                if (resource.equals(RESOURCE_ACCESS_RULES) && httpVerb == PUT) {
154
                if (resource.startsWith(RESOURCE_ACCESS_RULES) && httpVerb == PUT) {
150 155
                    logMetacat.debug("Setting access policy");
151 156
                    setAccess();
152 157
                    status = true;
153 158
                    logMetacat.debug("done setting access");
154 159
                    
155
                } else if (resource.equals(RESOURCE_META)) {
160
                } else if (resource.startsWith(RESOURCE_META)) {
156 161
                    logMetacat.debug("Using resource: " + RESOURCE_META);
157
                    String objectId = request.getPathInfo();
158
                    if (objectId != null && objectId.length() > 1) {
159
                        objectId = request.getPathInfo().substring(1);
160
                    }
162
                    
161 163
                    // get
162 164
                    if (httpVerb == GET) {
163
                        getSystemMetadataObject(objectId);
165
                        getSystemMetadataObject(extra);
164 166
                        status = true;
165 167
                    }
166 168
                    // post to register system metadata
167 169
                    if (httpVerb == POST) {
168
                    	registerSystemMetadata(objectId);
170
                    	registerSystemMetadata(extra);
169 171
                    	status = true;
170 172
                    }
171 173

  
172
                } else if (resource.equals(RESOURCE_RESERVE)) {
174
                } else if (resource.startsWith(RESOURCE_RESERVE)) {
173 175
                    // reserve the ID (in params)
174 176
                    if (httpVerb == POST) {
175 177
                    	reserve();
176 178
                    	status = true;
177 179
                    }
178
                } else if (resource.equals(RESOURCE_ASSERT_RELATION)) {
179
                	String objectId = request.getPathInfo();
180
                    if (objectId != null && objectId.length() > 1) {
181
                        objectId = request.getPathInfo().substring(1);
182
                    }
180
                } else if (resource.startsWith(RESOURCE_ASSERT_RELATION)) {
181
                	
183 182
                    // reserve the ID (in params)
184 183
                    if (httpVerb == GET) {
185
                    	assertRelation(objectId);
184
                    	assertRelation(extra);
186 185
                    	status = true;
187 186
                    }    
188
                } else if (resource.equals(RESOURCE_RESOLVE)) {
189
                	String objectId = request.getPathInfo();
190
                    if (objectId != null && objectId.length() > 1) {
191
                        objectId = request.getPathInfo().substring(1);
192
                    }
187
                } else if (resource.startsWith(RESOURCE_RESOLVE)) {
188
                	
193 189
                    // resolve the object location
194 190
                    if (httpVerb == GET) {
195
                    	resolve(objectId);
191
                    	resolve(extra);
196 192
                    	status = true;
197 193
                    }
198
                } else if (resource.equals(RESOURCE_OWNER)) {
199
                	String objectId = request.getPathInfo();
200
                    if (objectId != null && objectId.length() > 1) {
201
                        objectId = request.getPathInfo().substring(1);
202
                    }
194
                } else if (resource.startsWith(RESOURCE_OWNER)) {
195
                	
203 196
                    // set the owner
204 197
                    if (httpVerb == PUT) {
205
                    	owner(objectId);
198
                    	owner(extra);
206 199
                    	status = true;
207 200
                    }    
208
                } else if (resource.equals(RESOURCE_OWNER)) {
209
                	String objectId = request.getPathInfo();
210
                    if (objectId != null && objectId.length() > 1) {
211
                        objectId = request.getPathInfo().substring(1);
212
                    }
201
                } else if (resource.startsWith(RESOURCE_OWNER)) {
202
                	
213 203
                    // set the owner
214 204
                    if (httpVerb == PUT) {
215
                    	owner(objectId);
205
                    	owner(extra);
216 206
                    	status = true;
217 207
                    }
218
                } else if (resource.equals(RESOURCE_IS_AUTHORIZED)) {
219
                	String objectId = request.getPathInfo();
220
                    if (objectId != null && objectId.length() > 1) {
221
                        objectId = request.getPathInfo().substring(1);
222
                    }
208
                } else if (resource.startsWith(RESOURCE_IS_AUTHORIZED)) {
209
                	
223 210
                    // authorized?
224 211
                    if (httpVerb == GET) {
225
                    	isAuthorized(objectId);
212
                    	isAuthorized(extra);
226 213
                    	status = true;
227 214
                    }    
228
                } else if (resource.equals(RESOURCE_OBJECTS)) {
215
                } else if (resource.startsWith(RESOURCE_OBJECTS)) {
229 216
                    logMetacat.debug("Using resource 'object'");
230 217
                    logMetacat.debug("D1 Rest: Starting resource processing...");
231

  
232
                    String objectId = request.getPathInfo();
233
                    if (objectId != null && objectId.length() > 1) {
234
                        objectId = request.getPathInfo().substring(1);
235
                    }
236
                    else {
237
                        objectId = null;
238
                    }
239 218
                    
240
                    logMetacat.debug("objectId: " + objectId);
219
                    logMetacat.debug("objectId: " + extra);
241 220
                    logMetacat.debug("verb:" + httpVerb);
242 221

  
243 222
                    if (httpVerb == GET) {
244
                        getObject(objectId);
223
                    	if (extra != null) {
224
                    		getObject(extra);
225
                    	} else {
226
                    		query();
227
                    	}
245 228
                        status = true;
246 229
                    } else if (httpVerb == POST) {
247
                        putObject(objectId, FUNCTION_NAME_INSERT);
230
                        putObject(extra, FUNCTION_NAME_INSERT);
248 231
                        status = true;
249 232
                    }
250 233
                    
251
                } else if (resource.equals(RESOURCE_FORMATS)) {
234
                } else if (resource.startsWith(RESOURCE_FORMATS)) {
252 235
                  logMetacat.debug("Using resource: " + RESOURCE_FORMATS);
253 236
                  
254
                  // check for a format identifier
255
                  String fmtid = request.getPathInfo();
256 237
                  
257
                  if (fmtid != null && fmtid.length() > 1 ) {
258
                  	fmtid = request.getPathInfo().substring(1);
259
                  } else {
260
                  	fmtid = null;
261
                  }
262 238
                  
263 239
                  // handle each verb
264 240
                  if (httpVerb == GET) {
265
                  	if (fmtid == null) {
241
                  	if (extra == null) {
266 242
                  		// list the formats collection
267 243
                  		listFormats();
268 244
                  	} else {
269 245
                  		// get the specified format
270
                  		getFormat(fmtid);
246
                  		getFormat(extra);
271 247
                  	}
272 248
                  	status = true;
273 249
                  }
274 250
                  
275
                } else if (resource.equals(RESOURCE_LOG)) {
251
                } else if (resource.startsWith(RESOURCE_LOG)) {
276 252
                    logMetacat.debug("Using resource: " + RESOURCE_LOG);
277 253
                    //handle log events
278 254
                    if (httpVerb == GET) {
......
280 256
                        status = true;
281 257
                    }
282 258

  
283
                } else if (resource.equals(RESOURCE_CHECKSUM)) {
259
                } else if (resource.startsWith(RESOURCE_CHECKSUM)) {
284 260
                    logMetacat.debug("Using resource: " + RESOURCE_CHECKSUM);
285 261
                    //handle checksum requests
286 262
                    if (httpVerb == GET) {
287 263
                    
288
                        String guid = request.getPathInfo();
289
                        if (guid != null && guid.length() > 1) {
290
                            guid = request.getPathInfo().substring(1); //trim the slash
291
                        }
292
                        checksum(guid);
264
                        checksum(extra);
293 265
                        status = true;
294 266
                    }
295 267
                } 
......
790 762
    }
791 763
    
792 764
    /**
793
     * Earthgrid API > Query Service > Query Function : translates ecogrid query document to metacat query 
794
     * then calls DBQuery > createResultDocument function and then again translate resultset to ecogrid resultset
795
     * 
796
     * NOTE:
797
     *      This is the only method that uses EcoGrid classes for its implementation.  
798
     *      It does so because it takes an EcoGrid Query as input, and outputs an
799
     *      EcoGrid ResultSet document.  These documents are parsed by the auto-generated
800
     *      EcoGrid classes from axis, and so we link to them here rather than re-inventing them.
801
     *      This creates a circular dependency, because the Metacat classes are needed
802
     *      to build the EcoGrid implementation, and the EcoGrid jars are needed to build this query()
803
     *      method.  This circularity could be resolved by moving the EcoGrid classes
804
     *      to Metacat directly.  As we transition away from EcoGrid SOAP methods in
805
     *      favor of these REST interfaces, this circular dependency can be eliminated.
806
     *        
765
     *	Pass to the CN search service
766
     *
767
     * @throws NotImplemented 
768
     * @throws InvalidRequest 
769
     * @throws NotAuthorized 
770
     * @throws ServiceFailure 
771
     * @throws InvalidToken 
807 772
     * @throws Exception
808 773
     */
809
    private void query() throws Exception {
810
        /*  This block commented out because of the EcoGrid circular dependency.
811
         *  For now, query will not be supported until the circularity can be
812
         *  resolved, probably by moving the ecogrid query syntax transformers
813
         *  directly into the Metacat codebase.  MBJ 2010-02-03
814
         
815
        try {
816
            EcogridQueryParser parser = new EcogridQueryParser(request
817
                    .getReader());
818
            parser.parseXML();
819
            QueryType queryType = parser.getEcogridQuery();
820
            EcogridJavaToMetacatJavaQueryTransformer queryTransformer = 
821
                new EcogridJavaToMetacatJavaQueryTransformer();
822
            QuerySpecification metacatQuery = queryTransformer
823
                    .transform(queryType);
824

  
825
            DBQuery metacat = new DBQuery();
826

  
827
            boolean useXMLIndex = (new Boolean(PropertyService
828
                    .getProperty("database.usexmlindex"))).booleanValue();
829
            String xmlquery = "query"; // we don't care the query in resultset,
830
            // the query can be anything
831
            PrintWriter out = null; // we don't want metacat result, so set out null
832

  
833
            // parameter: queryspecification, user, group, usingIndexOrNot
834
            StringBuffer result = metacat.createResultDocument(xmlquery,
835
                    metacatQuery, out, username, groupNames, useXMLIndex);
836

  
837
            // create result set transfer       
838
            String saxparser = PropertyService.getProperty("xml.saxparser");
839
            MetacatResultsetParser metacatResultsetParser = new MetacatResultsetParser(
840
                    new StringReader(result.toString()), saxparser, queryType
841
                            .getNamespace().get_value());
842
            ResultsetType records = metacatResultsetParser.getEcogridResult();
843

  
844
            System.out
845
                    .println(EcogridResultsetTransformer.toXMLString(records));
846
            response.setContentType("text/xml");
847
            out = response.getWriter();
848
            out.print(EcogridResultsetTransformer.toXMLString(records));
849

  
850
        } catch (Exception e) {
851
            e.printStackTrace();
852
        }*/
853
        response.setContentType("text/xml");
854
        response.setStatus(501);
855
        PrintWriter out = response.getWriter();
856
        out.print("<error>Query operation not yet supported by Metacat.</error>");
857
        out.close();
774
    private void query() throws InvalidToken, ServiceFailure, NotAuthorized, InvalidRequest, NotImplemented {
775
        
776
    	String query = null;
777
		QueryType queryType = null;
778
		try {
779
			query = params.get("query")[0];
780
		} catch (Exception e) {
781
			logMetacat.warn("query not specified");
782
		}
783
		try {
784
			String qt = params.get("queryType")[0];
785
			queryType = QueryType.valueOf(qt);
786
		} catch (Exception e) {
787
			logMetacat.warn("queryType not specified");
788
		}
789
		
790
    	// expecting to throw NotImplemented
791
		CNodeService.getInstance().search(session, queryType, query);
858 792
    }
859 793

  
860 794
}

Also available in: Unified diff