Example usage for org.springframework.http MediaType TEXT_XML_VALUE

List of usage examples for org.springframework.http MediaType TEXT_XML_VALUE

Introduction

In this page you can find the example usage for org.springframework.http MediaType TEXT_XML_VALUE.

Prototype

String TEXT_XML_VALUE

To view the source code for org.springframework.http MediaType TEXT_XML_VALUE.

Click Source Link

Document

A String equivalent of MediaType#TEXT_XML .

Usage

From source file:org.geoserver.opensearch.rest.CollectionsController.java

@GetMapping(path = "{collection}/metadata", produces = { MediaType.TEXT_XML_VALUE })
public void getCollectionMetadata(@PathVariable(name = "collection", required = true) String collection,
        HttpServletResponse response) throws IOException {
    // query one collection and grab its OGC links
    Feature feature = queryCollection(collection, q -> {
        q.setProperties(Collections.singletonList(FF.property(OpenSearchAccess.METADATA_PROPERTY_NAME)));
    });//from   w  ww .  j  av  a2  s.  co  m

    // grab the metadata
    Property metadataProperty = feature.getProperty(OpenSearchAccess.METADATA_PROPERTY_NAME);
    if (metadataProperty != null && metadataProperty.getValue() instanceof String) {
        String value = (String) metadataProperty.getValue();
        response.setContentType("text/xml");
        StreamUtils.copy(value, Charset.forName("UTF-8"), response.getOutputStream());
    } else {
        throw new ResourceNotFoundException("Metadata for collection '" + collection + "' could not be found");
    }
}

From source file:org.geoserver.opensearch.rest.CollectionsController.java

@PutMapping(path = "{collection}/metadata", consumes = MediaType.TEXT_XML_VALUE)
public void putCollectionMetadata(@PathVariable(name = "collection", required = true) String collection,
        HttpServletRequest request) throws IOException {
    // check the collection is there
    queryCollection(collection, q -> {
    });//  ww w.j a v  a 2 s.  c om

    // TODO: validate it's actual ISO metadata
    String metadata = IOUtils.toString(request.getReader());
    checkWellFormedXML(metadata);

    // prepare the update
    Filter filter = FF.equal(FF.property(COLLECTION_ID), FF.literal(collection), true);
    runTransactionOnCollectionStore(
            fs -> fs.modifyFeatures(OpenSearchAccess.METADATA_PROPERTY_NAME, metadata, filter));
}

From source file:org.geoserver.opensearch.rest.CollectionsControllerTest.java

@Test
public void testPutCollectionMetadata() throws Exception {
    MockHttpServletResponse response;// w w  w  .j  a v  a  2 s  .  c o m
    createTest123Collection();

    // create the metadata
    response = putAsServletResponse("rest/oseo/collections/TEST123/metadata",
            getTestData("/test123-metadata.xml"), MediaType.TEXT_XML_VALUE);
    assertEquals(200, response.getStatus());

    // grab and check
    assertTest123Metadata();
}

From source file:org.geoserver.opensearch.rest.ProductsController.java

@PutMapping(path = "{product:.+}/metadata", consumes = MediaType.TEXT_XML_VALUE)
public void putCollectionMetadata(@PathVariable(name = "collection", required = true) String collection,
        @PathVariable(name = "product", required = true) String product, HttpServletRequest request)
        throws IOException {
    // check the product exists
    queryProduct(collection, product, q -> {
    });/*from ww w  .  jav a  2  s .c o  m*/

    // TODO: validate it's actual O&M metadata
    String metadata = IOUtils.toString(request.getReader());
    checkWellFormedXML(metadata);

    // prepare the update
    Filter filter = getProductFilter(collection, product);
    runTransactionOnProductStore(
            fs -> fs.modifyFeatures(OpenSearchAccess.METADATA_PROPERTY_NAME, metadata, filter));
}

From source file:org.geoserver.opensearch.rest.ProductsControllerTest.java

@Test
public void testPutProductMetadata() throws Exception {
    testCreateProduct();/*from  w  ww. ja v  a  2 s.c o m*/

    // create the metadata
    MockHttpServletResponse response = putAsServletResponse(
            "rest/oseo/collections/SENTINEL2/products/S2A_OPER_MSI_L1C_TL_SGS__20180101T000000_A006640_T32TPP_N02.04/metadata",
            getTestData("/product-metadata.xml"), MediaType.TEXT_XML_VALUE);
    assertEquals(200, response.getStatus());

    // grab and check
    assertProductMetadata();
}

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)//  www .j av a2  s .  c  o 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");
    }/*from   w w  w. j  ava  2  s  . co m*/
    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 va2  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 a  v  a2s  .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();/*  w  w  w .jav  a 2 s .com*/

    try {
        putMap(map);
    } catch (Exception e) {
        throw createRestException(e);
    }
}