List of usage examples for org.springframework.http MediaType APPLICATION_XML_VALUE
String APPLICATION_XML_VALUE
To view the source code for org.springframework.http MediaType APPLICATION_XML_VALUE.
Click Source Link
From source file:org.geoserver.backuprestore.rest.RestoreController.java
@GetMapping(path = "restore{.+}", produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_XML_VALUE, MediaType.APPLICATION_XML_VALUE }) public Object restoreGet(@RequestParam(name = "format", required = false) String format) { Object lookup = lookupRestoreExecutionsContext(null, true, false); if (lookup != null) { if (lookup instanceof RestoreExecutionAdapter) { return wrapObject((RestoreExecutionAdapter) lookup, RestoreExecutionAdapter.class); } else {/*from w ww . j a va 2 s .com*/ return wrapList((List<RestoreExecutionAdapter>) lookup, RestoreExecutionAdapter.class); } } return null; }
From source file:org.geoserver.backuprestore.rest.RestoreController.java
@GetMapping(path = "restore/{restoreId:.+}", produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_XML_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.ALL_VALUE }) public Object restoreGet(@RequestParam(name = "format", required = false) String format, @PathVariable String restoreId, HttpServletResponse response) { Object lookup = lookupRestoreExecutionsContext(getExecutionIdFilter(restoreId), true, false); if (lookup != null) { if (lookup instanceof RestoreExecutionAdapter) { if (restoreId.endsWith(".zip")) { try { // get your file as InputStream File file = ((RestoreExecutionAdapter) lookup).getArchiveFile().file(); InputStream is = new FileInputStream(file); // copy it to response's OutputStream org.apache.commons.io.IOUtils.copy(is, response.getOutputStream()); response.flushBuffer(); } catch (IOException ex) { LOGGER.log(Level.INFO, "Error writing file to output stream.", ex); throw new RuntimeException("IOError writing file to output stream"); }/*from w w w. j a v a 2 s . c o m*/ } else { return wrapObject((RestoreExecutionAdapter) lookup, RestoreExecutionAdapter.class); } } else { return wrapList((List<RestoreExecutionAdapter>) lookup, RestoreExecutionAdapter.class); } } return null; }
From source file:org.geoserver.backuprestore.rest.RestoreController.java
@DeleteMapping(path = "restore/{restoreId:.+}", produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_XML_VALUE, MediaType.APPLICATION_XML_VALUE }) public Object restoreDelete(@RequestParam(name = "format", required = false) String format, @PathVariable String restoreId) throws IOException { final String executionId = getExecutionIdFilter(restoreId); Object lookup = lookupRestoreExecutionsContext(executionId, true, false); if (lookup != null) { if (lookup instanceof RestoreExecutionAdapter) { try { getBackupFacade().abandonExecution(Long.valueOf(executionId)); } catch (Exception e) { throw new IOException(e); }/*from w w w . j a v a2 s . c om*/ return wrapObject((RestoreExecutionAdapter) lookup, RestoreExecutionAdapter.class); } else { return wrapList((List<RestoreExecutionAdapter>) lookup, RestoreExecutionAdapter.class); } } return null; }
From source file:org.geoserver.backuprestore.rest.RestoreController.java
@PostMapping(value = { "/restore" }, consumes = { MediaType.TEXT_XML_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE, MediaTypeExtensions.TEXT_JSON_VALUE }) @ResponseStatus(HttpStatus.CREATED)/*from w ww .j a v a2 s . c o m*/ public Object restorePost(@RequestBody(required = true) RestoreExecutionAdapter restore, @RequestHeader("Content-Type") String contentType, UriComponentsBuilder builder) throws IOException { RestoreExecutionAdapter execution = null; if (restore.getId() != null) { Object lookup = lookupBackupExecutionsContext(String.valueOf(restore.getId()), false, false); if (lookup != null) { // Restore instance already exists... trying to restart it. try { getBackupFacade().restartExecution(restore.getId()); LOGGER.log(Level.INFO, "Restore restarted: " + restore.getArchiveFile()); return wrapObject((RestoreExecutionAdapter) lookup, RestoreExecutionAdapter.class); } catch (Exception e) { LOGGER.log(Level.WARNING, "Could not restart the restore: " + restore.getArchiveFile()); throw new IOException(e); } } } else { // Start a new execution asynchronously. You will need to query for the status in order to follow the progress. execution = getBackupFacade().runRestoreAsync(restore.getArchiveFile(), restore.getFilter(), asParams(restore.getOptions())); LOGGER.log(Level.INFO, "Restore file: " + restore.getArchiveFile()); return wrapObject((RestoreExecutionAdapter) execution, RestoreExecutionAdapter.class); } return null; }
From source file:org.geoserver.rest.catalog.StyleController.java
@PostMapping(value = { "/styles", "/layers/{layerName}/styles", "/workspaces/{workspaceName}/styles" }, consumes = { MediaType.TEXT_XML_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE, MediaTypeExtensions.TEXT_JSON_VALUE }) @ResponseStatus(HttpStatus.CREATED)/*ww w . j a va2 s. co m*/ public String stylePost(@RequestBody StyleInfo style, @PathVariable(required = false) String layerName, @PathVariable(required = false) String workspaceName, @RequestParam(defaultValue = "false", name = "default") boolean makeDefault) { if (workspaceName != null && catalog.getWorkspaceByName(workspaceName) == null) { throw new ResourceNotFoundException("Workspace " + workspaceName + " not found"); } checkFullAdminRequired(workspaceName); if (layerName != null) { StyleInfo existing = catalog.getStyleByName(style.getName()); if (existing == null) { throw new ResourceNotFoundException(); } LayerInfo l = catalog.getLayerByName(layerName); l.getStyles().add(existing); //check for default if (makeDefault) { l.setDefaultStyle(existing); } catalog.save(l); LOGGER.info("POST style " + style.getName() + " to layer " + layerName); } else { if (workspaceName != null) { style.setWorkspace(catalog.getWorkspaceByName(workspaceName)); } catalog.add(style); LOGGER.info("POST style " + style.getName()); } return style.getName(); }
From source file:org.geoserver.rest.catalog.StyleController.java
@PutMapping(value = { "/styles/{styleName}", "/workspaces/{workspaceName}/styles/{styleName}" }, consumes = { MediaType.TEXT_XML_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE, MediaTypeExtensions.TEXT_JSON_VALUE }) public void stylePut(@RequestBody StyleInfo info, @PathVariable String styleName, @PathVariable(required = false) String workspaceName) { if (workspaceName != null && catalog.getWorkspaceByName(workspaceName) == null) { throw new ResourceNotFoundException("Workspace " + workspaceName + " not found"); }/*w ww . j av a2s .c om*/ checkFullAdminRequired(workspaceName); StyleInfo original = catalog.getStyleByName(workspaceName, styleName); //ensure no workspace change if (info.getWorkspace() != null) { if (!info.getWorkspace().equals(original.getWorkspace())) { throw new RestException("Can't change the workspace of a style, instead " + "DELETE from existing workspace and POST to new workspace", HttpStatus.FORBIDDEN); } } new CatalogBuilder(catalog).updateStyle(original, info); catalog.save(original); }
From source file:org.geoserver.rest.security.AbstractAclController.java
@GetMapping(produces = { MediaType.APPLICATION_JSON_VALUE, MediaTypeExtensions.TEXT_JSON_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE }) @ResponseBody/*from w ww.j a v a2 s . c o m*/ public RuleMap rulesGet() throws IOException { checkUserIsAdmin(); try { return getMap(); } catch (Exception e) { throw createRestException(e); } }
From source file:org.geoserver.rest.security.AbstractAclController.java
@PostMapping(consumes = { MediaType.APPLICATION_JSON_VALUE, MediaTypeExtensions.TEXT_JSON_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE }) public void rulesPost(@RequestBody RuleMap map) throws IOException { checkUserIsAdmin();/*from w ww . j av a2 s. c o m*/ try { postMap(map); } catch (Exception e) { throw createRestException(e); } }
From source file:org.geoserver.rest.security.AbstractAclController.java
@PutMapping(consumes = { MediaType.APPLICATION_JSON_VALUE, MediaTypeExtensions.TEXT_JSON_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE }) public void rulesPut(@RequestBody RuleMap map) throws IOException { checkUserIsAdmin();/*from w w w . j ava 2 s .c o m*/ try { putMap(map); } catch (Exception e) { throw createRestException(e); } }
From source file:org.geoserver.rest.security.MasterPasswordController.java
@GetMapping(produces = { MediaType.APPLICATION_JSON_VALUE, MediaTypeExtensions.TEXT_JSON_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE }) public NamedMap<String, String> masterPasswordGet() throws IOException { if (!getManager().checkAuthenticationForAdminRole()) { throw new RestException("Amdinistrative privelges required", HttpStatus.FORBIDDEN); }//from w w w. j a v a2s .c om char[] masterpw = getManager().getMasterPasswordForREST(); NamedMap<String, String> m = new NamedMap<>(XML_ROOT_ELEM); m.put(MP_CURRENT_KEY, new String(masterpw)); getManager().disposePassword(masterpw); return m; }