private void throwProductNotFound(String collection, String product, String item) { throw new ResourceNotFoundException( item + " '" + product + "' in collection '" + collection + "' could not be found"); }
@ExceptionHandler(ResourceNotFoundException.class) public void handleResourceNotFound( ResourceNotFoundException e, HttpServletResponse response, WebRequest request, OutputStream os) throws IOException { notifyExceptionToCallbacks(request, response, e); String quietOnNotFound = request.getParameter("quietOnNotFound"); // yes this is seriously a thing String message = e.getMessage(); if (Boolean.parseBoolean(quietOnNotFound)) { message = ""; } else { LOGGER.log(Level.SEVERE, e.getMessage(), e); } response.setStatus(404); StreamUtils.copy(message, Charset.forName("UTF-8"), os); }
/** If the coverage doesn't exists throws a REST exception with HTTP 404 code. */ private void checkCoverageExists( CoverageInfo coverage, String workspaceName, String coverageName) { if (coverage == null) { throw new ResourceNotFoundException( String.format("No such coverage: %s,%s", workspaceName, coverageName)); } }
/** If the feature type doesn't exists throws a REST exception with HTTP 404 code. */ private void checkFeatureTypeExists( FeatureTypeInfo featureType, String workspaceName, String storeName, String featureTypeName) { if (featureType == null && storeName == null) { throw new ResourceNotFoundException( String.format("No such feature type: %s,%s", workspaceName, featureTypeName)); } else if (featureType == null) { throw new ResourceNotFoundException( String.format( "No such feature type: %s,%s,%s", workspaceName, storeName, featureTypeName)); } }
private WMTSStoreInfo getExistingWMTSStore(String workspaceName, String storeName) { WMTSStoreInfo original = catalog.getStoreByName(workspaceName, storeName, WMTSStoreInfo.class); if (original == null) { throw new ResourceNotFoundException( "No such wmts store: " + workspaceName + "," + storeName); } return original; }
private CollectionLayer buildCollectionLayerFromFeature( Feature feature, boolean notFoundOnEmpty) { CollectionLayer layer = CollectionLayer.buildCollectionLayerFromFeature(feature); if (layer == null && notFoundOnEmpty) { throw new ResourceNotFoundException(); } return layer; }
/** Helper method that find a store based on the workspace name and store name. */ private DataStoreInfo getExistingDataStore(String workspaceName, String storeName) { DataStoreInfo original = catalog.getDataStoreByName(workspaceName, storeName); if (original == null) { throw new ResourceNotFoundException( "No such data store: " + workspaceName + "," + storeName); } return original; }
/** Helper method that find a store based on the workspace name and store name. */ private CoverageStoreInfo getExistingCoverageStore(String workspaceName, String storeName) { CoverageStoreInfo original = catalog.getCoverageStoreByName(workspaceName, storeName); if (original == null) { throw new ResourceNotFoundException( "No such coverage store: " + workspaceName + "," + storeName); } return original; }
private DataStoreInfo getExistingDataStore(String workspaceName, String storeName) { DataStoreInfo original = catalog.getDataStoreByName(workspaceName, storeName); if (original == null) { throw new ResourceNotFoundException( "No such datastore: " + workspaceName + "," + storeName); } return original; }
private CoverageStoreInfo getExistingCoverageStore(String workspaceName, String storeName) { CoverageStoreInfo original = catalog.getCoverageStoreByName(workspaceName, storeName); if (original == null) { throw new ResourceNotFoundException( "No such coverage store: " + workspaceName + "," + storeName); } return original; }
/** * Verifies the workspace name (if not null) for a REST request, throwing an appropriate * exception if invalid * * @param workspaceName The workspace name. Ignored if null. * @throws RestException if the workspace name is not null and the workspace doesn't exist in * the catalog */ private void checkWorkspaceName(String workspaceName) throws RestException { if (workspaceName != null && catalog.getWorkspaceByName(workspaceName) == null) { throw new ResourceNotFoundException("Workspace " + workspaceName + " not found"); } }
protected NamespaceInfo getNamespaceInternal(String workspaceName) { if (Objects.isNull(workspaceName)) { throw new NullPointerException(); } else { NamespaceInfo ns = catalog.getNamespaceByPrefix(workspaceName); if (Objects.isNull(ns)) { throw new ResourceNotFoundException("Could not find workspace " + workspaceName); } else { return ns; } } }
protected NamespaceInfo getNamespaceInternal(String workspaceName) { if (Objects.isNull(workspaceName)) { throw new NullPointerException(); } else { NamespaceInfo ns = catalog.getNamespaceByPrefix(workspaceName); if (Objects.isNull(ns)) { throw new ResourceNotFoundException("Could not find workspace " + workspaceName); } else { return ns; } } }
private WMSStoreInfo getExistingWMSStore(String workspaceName, String storeName) { WMSStoreInfo original = catalog.getStoreByName(workspaceName, storeName, WMSStoreInfo.class); if (original == null) { throw new ResourceNotFoundException( "No such wms store: " + workspaceName + "," + storeName); } return original; }
protected StyleInfo getStyleInternal(String styleName, String workspace) { LOGGER.fine("GET style " + styleName); StyleInfo sinfo = catalog.getStyleByName(workspace, styleName); if (sinfo == null) { String message = "No such style: " + styleName; if (workspace != null) { message = "No such style " + styleName + " in workspace " + workspace; } throw new ResourceNotFoundException(message); } else { return sinfo; } }
@GetMapping(value = "/{workspaceName}") public RestWrapper<WorkspaceInfo> workspaceGet(@PathVariable String workspaceName) { WorkspaceInfo wkspace = catalog.getWorkspaceByName(workspaceName); if (wkspace == null) { throw new ResourceNotFoundException("No such workspace: '" + workspaceName + "' found"); } LOGGER.info("GET " + workspaceName); LOGGER.info("got " + wkspace.getName()); return wrapObject(wkspace, WorkspaceInfo.class); }
private CoverageInfo getExistingStructuredCoverage( String workspaceName, String storeName, String coverageName) { WorkspaceInfo ws = catalog.getWorkspaceByName(workspaceName); if (ws == null) { throw new ResourceNotFoundException("No such workspace : " + workspaceName); } CoverageStoreInfo store = catalog.getCoverageStoreByName(ws, storeName); if (store == null) { throw new ResourceNotFoundException("No such coverage store: " + storeName); } Optional<CoverageInfo> optCoverage = catalog.getCoveragesByStore(store) .stream() .filter(si -> coverageName.equals(si.getName())) .findFirst(); if (!optCoverage.isPresent()) { throw new ResourceNotFoundException("No such coverage in store: " + coverageName); } return optCoverage.get(); }
@GetMapping( value = "/{namespaceName}", produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_HTML_VALUE, MediaType.APPLICATION_XML_VALUE } ) public RestWrapper<NamespaceInfo> namespaceGet(@PathVariable String namespaceName) { NamespaceInfo namespace = catalog.getNamespaceByPrefix(namespaceName); if (namespace == null) { throw new ResourceNotFoundException("No such namespace: '" + namespaceName + "' found"); } LOGGER.info("GET " + namespaceName); LOGGER.info("got " + namespace.getName()); return wrapObject(namespace, NamespaceInfo.class); }
protected WMSLayerInfo getResourceInternal( final String workspaceName, @Nullable final String storeName, final String layerName) { final NamespaceInfo ns = getNamespaceInternal(workspaceName); final WMSLayerInfo layer; if (Objects.isNull(layerName)) { throw new NullPointerException(); } else if (Objects.isNull(storeName)) { layer = catalog.getResourceByName(ns, layerName, WMSLayerInfo.class); if (Objects.isNull(layer)) { throw new ResourceNotFoundException( "No such cascaded wms: " + workspaceName + "," + layerName); } else { return layer; } } else { WMSStoreInfo store = getStoreInternal(ns, storeName); layer = catalog.getResourceByStore(store, layerName, WMSLayerInfo.class); if (Objects.isNull(layer)) { throw new ResourceNotFoundException( "No such cascaded wms: " + workspaceName + "," + layerName); } else { return layer; } } }
/** * A single layer as JSON, XML or HTML. * * @param layerName * @return A single layer */ @GetMapping( path = "/{layerName}", produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_HTML_VALUE } ) public RestWrapper<LayerInfo> layerGet( @PathVariable String layerName, @PathVariable(required = false) String workspaceName) { if (workspaceName != null) { layerName = workspaceName + ":" + layerName; } LayerInfo layer = catalog.getLayerByName(layerName); if (layer == null) { throw new ResourceNotFoundException("No such layer: " + layerName); } return wrapObject(layer, LayerInfo.class); }