Example usage for org.springframework.http MediaType APPLICATION_XML_VALUE

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

Introduction

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

Prototype

String APPLICATION_XML_VALUE

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

Click Source Link

Document

A String equivalent of MediaType#APPLICATION_XML .

Usage

From source file:org.messic.server.facade.controllers.rest.SettingsController.java

@ApiMethod(path = "/services/settings/admin", verb = ApiVerb.GET, description = "Get the Messic settings", produces = {
        MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ApiErrors(apierrors = { @ApiError(code = UnknownMessicRESTException.VALUE, description = "Unknown error"),
        @ApiError(code = NotAuthorizedMessicRESTException.VALUE, description = "Not authorized to obtain this info") })
@RequestMapping(value = "/admin", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)//from  w w  w. j a  va  2  s  .  co m
@ResponseBody
protected MessicSettings getMessicSettings()
        throws NotAuthorizedMessicRESTException, UnknownMessicRESTException {
    try {
        User user = SecurityUtil.getCurrentUser();
        User result = userAPI.getUserByLogin(user.getLogin());
        if (result.getAdministrator()) {
            MessicSettings ms = new MessicSettings(daoSettings.getSettings());
            return ms;
        } else {
            throw new NotAuthorizedMessicRESTException(new Exception("User not administrator"));
        }
    } catch (NotAuthorizedMessicRESTException e) {
        throw new NotAuthorizedMessicRESTException(e);
    } catch (Exception e) {
        throw new UnknownMessicRESTException(e);
    }
}

From source file:org.messic.server.facade.controllers.rest.PlaylistController.java

@ApiMethod(path = "/services/playlists?filterSid=${playlistSid}&songsInfo=true|false", verb = ApiVerb.GET, description = "Get all playlists", produces = {
        MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ApiErrors(apierrors = { @ApiError(code = UnknownMessicRESTException.VALUE, description = "Unknown error"),
        @ApiError(code = NotFoundMessicRESTException.VALUE, description = "Forbidden access") })
@RequestMapping(value = "", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)//w ww . j  a v a2  s .com
@ResponseBody
@ApiResponseObject
public List<Playlist> getAll(
        @RequestParam(value = "filterSid", required = false) @ApiParam(name = "filterSid", description = "SID of the playlist to filter playlists", paramType = ApiParamType.QUERY, required = false) Long filterSid,
        @RequestParam(value = "songsInfo", required = false) @ApiParam(name = "songsInfo", description = "flag to return also the songs info of the playlist or not. By default, true", paramType = ApiParamType.QUERY, required = false, allowedvalues = {
                "true", "false" }, format = "Boolean") Boolean songsInfo)
        throws UnknownMessicRESTException, NotAuthorizedMessicRESTException, NotFoundMessicRESTException {
    User user = SecurityUtil.getCurrentUser();

    try {
        if (songsInfo == null) {
            songsInfo = new Boolean(true);
        }

        if (filterSid == null || filterSid <= 0) {
            return this.playlistAPI.getAllLists(user, songsInfo);
        } else {
            ArrayList<Playlist> result = new ArrayList<Playlist>();
            result.add(this.playlistAPI.getPlaylist(user, filterSid, songsInfo));
            return result;
        }
    } catch (ResourceNotFoundMessicException rnfme) {
        throw new NotFoundMessicRESTException(rnfme);
    } catch (Exception e) {
        log.error("failed!", e);
        throw new UnknownMessicRESTException(e);
    }
}

From source file:org.messic.server.facade.controllers.rest.SettingsController.java

@ApiMethod(path = "/services/settings/{userName}/validate", verb = ApiVerb.POST, description = "Validate the username", produces = {
        MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ApiErrors(apierrors = { @ApiError(code = UnknownMessicRESTException.VALUE, description = "Unknown error"),
        @ApiError(code = NotValidUserNameMessicRESTException.VALUE, description = "Not a valid username") })
@RequestMapping(value = "/{userName}/validate", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.OK)// ww w. j av a2s  .  c o  m
@ResponseBody
@ApiResponseObject
public Boolean validateNewUsername(
        @ApiParam(name = "userName", description = "UserName to test if its valid or not", paramType = ApiParamType.PATH, required = true) @PathVariable String userName)
        throws UnknownMessicRESTException, NotValidUserNameMessicRESTException {
    long currentTime = System.currentTimeMillis();
    if (LastValidationTime == 0) {
        LastValidationTime = currentTime;
    }
    if (currentTime - LastValidationTime > ONE_HOUR) {
        validateNewUserNameCounts = 0;
    }
    validateNewUserNameCounts++;
    if (currentTime - LastValidationTime < 5000 || validateNewUserNameCounts > 50) {
        LastValidationTime = currentTime;

        // Security issue? Are we being attacked?
        // TODO inform? BLACKLIST?
        try {
            Thread.sleep(validateNewUserNameCounts * 100);
        } catch (InterruptedException e) {
            log.error("failed!", e);
        }
    }

    try {
        boolean result = userAPI.validateNewUserName(userName);
        if (result) {
            return true;
        } else {
            throw new NotValidUserNameMessicRESTException(new Exception("Not valid username to be created."));
        }
    } catch (Exception e) {
        throw new UnknownMessicRESTException(e);
    }
}

From source file:com.frequentis.maritime.mcsr.web.rest.InstanceResourceIntTest.java

@Before
public void initTest() throws TransformerException {
    instanceSearchRepository.deleteAll();
    instance = new Instance();
    // Common/*from w w  w.j  a  v  a  2s .  c  o m*/
    instance.setEndpointType(DEFAULT_ENDPOINT_TYPE);
    instance.setGeometryContentType(DEFAULT_GEOMETRY_CONTENT_TYPE);
    instance.setOrganizationId(DEFAULT_ORGANIZATION_ID);

    // All these field are overridden by XML (XML is required)
    instance.setName(DEFAULT_NAME);
    instance.setVersion(DEFAULT_VERSION);
    instance.setComment(DEFAULT_COMMENT);
    instance.setInstanceId(DEFAULT_INSTANCE_ID);
    instance.setKeywords(DEFAULT_KEYWORDS);
    instance.setStatus(DEFAULT_STATUS);
    instance.setUnlocode(DEFAULT_UNLOCODE);
    instance.setEndpointUri(DEFAULT_ENDPOINT_URI);

    // Create XML
    xmlSearchRepository.deleteAll();

    Xml xml = new Xml();
    xml.setName(DEFAULT_NAME);
    xml.setComment(DEFAULT_COMMENT);
    xml.setContentContentType(MediaType.APPLICATION_XML_VALUE);

    XMLInstanceBuilder xmlBuilder = new XMLInstanceBuilder();
    InstanceXML x = xmlBuilder.getBuilderXml();
    x.setName(DEFAULT_NAME);
    x.setDescription(DEFAULT_COMMENT);
    x.setURL(DEFAULT_ENDPOINT_URI);
    x.setKeywords(DEFAULT_KEYWORDS);
    x.setId(DEFAULT_INSTANCE_ID);
    x.setStatus(Status.valueOf(DEFAULT_STATUS));
    x.setServiceType(DEFAULT_ENDPOINT_TYPE);
    x.setIMO(DEFAULT_IMO);
    x.setVersion(DEFAULT_VERSION);
    x.setMMSI(RandomStringUtils.randomAlphabetic(5));
    x.setRequiresAuthorization("false");

    VendorInfo producedBy = x.getProducedBy();
    producedBy.setContactInfo(RandomStringUtils.randomAlphabetic(15));
    producedBy.setName(RandomStringUtils.randomAlphabetic(15));
    producedBy.setId(RandomStringUtils.randomAlphabetic(15));
    producedBy.setOrganizationId(RandomStringUtils.randomAlphabetic(15));
    producedBy.setDescription(RandomStringUtils.randomAlphabetic(15));

    VendorInfo providedBy = x.getProvidedBy();
    providedBy.setContactInfo(RandomStringUtils.randomAlphabetic(15));
    providedBy.setName(RandomStringUtils.randomAlphabetic(15));
    providedBy.setId(RandomStringUtils.randomAlphabetic(15));
    providedBy.setOrganizationId(RandomStringUtils.randomAlphabetic(15));
    providedBy.setDescription(RandomStringUtils.randomAlphabetic(15));

    ServiceLevel offersServiceLevel = x.getOffersServiceLevel();
    offersServiceLevel.setName(RandomStringUtils.randomAlphabetic(15));
    offersServiceLevel.setAvailability(1);
    offersServiceLevel.setDescription(RandomStringUtils.randomAlphabetic(15));

    CoversAreaType conversAreas = x.getCoversAreas();
    // Requires plenty of heap (parsing JSON with unls)
    // conversAreas.setUnLoCode(DEFAULT_UNLOCODE);

    List<CoverageArea> coversArea = new ArrayList<>();
    CoverageArea ca = new CoverageArea();
    ca.setName("Bermuda Triangle");
    ca.setDescription("Loosely defined region in the western part of the North Atlantic Ocean.");
    ca.setGeometryAsWKT("POLYGON((-80.190 25.774, -66.118 18.466, -64.757 32.321, -80.190 25.774))");
    coversArea.add(ca);
    conversAreas.setCoversArea(coversArea);

    ServiceDesignReference implementsServiceDesign = x.getImplementsServiceDesign();
    implementsServiceDesign.setId("awdwad");
    implementsServiceDesign.setVersion("dwadwdwad");

    xml.setContent(xmlBuilder.buildXmlString());
    xmlService.save(xml);

    // Set XML

    instance.setInstanceAsXml(xml);
}

From source file:com.orange.ngsi.server.NgsiRestBaseController.java

@RequestMapping(method = RequestMethod.POST, value = "/contextSubscriptions", consumes = {
        MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
final public ResponseEntity<SubscribeContextResponse> createSubscription(
        @RequestBody SubscribeContext subscribeContext, HttpServletRequest httpServletRequest)
        throws Exception {
    registerIntoDispatcher(httpServletRequest);
    ngsiValidation.checkSubscribeContext(subscribeContext);
    return new ResponseEntity<>(createSubscription(subscribeContext), HttpStatus.OK);
}

From source file:com.orange.ngsi.server.NgsiRestBaseController.java

@RequestMapping(method = RequestMethod.PUT, value = "/contextSubscriptions/{subscriptionID}", consumes = {
        MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
final public ResponseEntity<UpdateContextSubscriptionResponse> updateSubscription(
        @PathVariable String subscriptionID, @RequestBody UpdateContextSubscription updateContextSubscription,
        HttpServletRequest httpServletRequest) throws Exception {
    registerIntoDispatcher(httpServletRequest);
    ngsiValidation.checkUpdateSubscription(subscriptionID, updateContextSubscription);
    return new ResponseEntity<>(updateSubscription(updateContextSubscription), HttpStatus.OK);
}

From source file:org.messic.server.facade.controllers.rest.SettingsController.java

@ApiMethod(path = "/services/settings", verb = ApiVerb.POST, description = "Create or Update an User.", produces = {
        MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE }, consumes = {
                MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ApiErrors(apierrors = { @ApiError(code = UnknownMessicRESTException.VALUE, description = "Unknown error") })
@RequestMapping(value = "", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.OK)// w w w . j  a  v  a2  s .  com
@ResponseBody
@ApiResponseObject
protected void createOrUpdate(@ApiBodyObject @RequestBody User user) throws Exception {

    User loginuser = SecurityUtil.getCurrentUser();
    User result = null;
    if (loginuser != null) {
        result = userAPI.getUserByLogin(loginuser.getLogin());
    }

    if (result == null) {
        userAPI.createUser(user);
    } else {
        user.setSid(result.getSid());
        user.setLogin(result.getLogin()); // forbiden to change the username
        userAPI.updateUser(user);
    }
}

From source file:org.messic.server.facade.controllers.rest.AlbumController.java

@ApiMethod(path = "/services/albums/{albumSid}?songsInfo=true|false&authorInfo=true|false", verb = ApiVerb.GET, description = "Get album with id {albumSid}", produces = {
        MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ApiErrors(apierrors = { @ApiError(code = UnknownMessicRESTException.VALUE, description = "Unknown error"),
        @ApiError(code = NotAuthorizedMessicRESTException.VALUE, description = "Forbidden access") })
@RequestMapping(value = "/{albumSid}", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)/*from   w ww  .  j  a v  a2  s . c  o m*/
@ResponseBody
@ApiResponseObject
public Album getAlbum(
        @PathVariable @ApiParam(name = "albumSid", description = "Sid of the album to get", paramType = ApiParamType.PATH, required = true) Long albumSid,
        @RequestParam(value = "songsInfo", required = false) @ApiParam(name = "songsInfo", description = "flag to return also the songs info of the albums or not. By default, false", paramType = ApiParamType.QUERY, required = false, allowedvalues = {
                "true", "false" }, format = "Boolean") Boolean songsInfo,
        @RequestParam(value = "authorInfo", required = false) @ApiParam(name = "authorInfo", description = "flag to return also the author info of the albums or not. By default, true", paramType = ApiParamType.QUERY, required = false, allowedvalues = {
                "true", "false" }, format = "Boolean") Boolean authorInfo,
        @RequestParam(value = "resourcesInfo", required = false) @ApiParam(name = "resourcesInfo", description = "flag to return also the artworks and others info of the albums or not. By default, the same value of songsInfo", paramType = ApiParamType.QUERY, required = false, allowedvalues = {
                "true", "false" }, format = "Boolean") Boolean resourcesInfo)
        throws UnknownMessicRESTException, NotAuthorizedMessicRESTException {

    User user = SecurityUtil.getCurrentUser();
    try {
        Album album = albumAPI.getAlbum(user, albumSid, (authorInfo != null ? authorInfo : true),
                (songsInfo != null ? songsInfo : false),
                (resourcesInfo != null ? resourcesInfo : (songsInfo != null ? songsInfo : false)));
        return album;
    } catch (Exception e) {
        log.error("failed!", e);
        throw new UnknownMessicRESTException(e);
    }
}

From source file:org.messic.server.facade.controllers.rest.SettingsController.java

@ApiMethod(path = "/services/settings/admin", verb = ApiVerb.POST, description = "Save Messic Settings.", produces = {
        MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE }, consumes = {
                MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ApiErrors(apierrors = { @ApiError(code = UnknownMessicRESTException.VALUE, description = "Unknown error"),
        @ApiError(code = NotAuthorizedMessicRESTException.VALUE, description = "User not authorized to save settings") })
@RequestMapping(value = "/admin", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.OK)//from   ww  w.  jav a 2 s .  com
@ResponseBody
@ApiResponseObject
protected void saveSettings(@ApiBodyObject @RequestBody MessicSettings settings)
        throws NotAuthorizedMessicRESTException, UnknownMessicRESTException {
    try {
        User user = SecurityUtil.getCurrentUser();
        userAPI.saveSettings(user, settings);
    } catch (NotAllowedMessicException e) {
        throw new NotAuthorizedMessicRESTException(e);
    } catch (Exception e) {
        throw new UnknownMessicRESTException(e);
    }
}

From source file:org.messic.server.facade.controllers.rest.AlbumController.java

@ApiMethod(path = "/services/albums/{albumSid}/{resourceSid}/cover", verb = ApiVerb.POST, description = "Set cover for a certain album", produces = {
        MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ApiErrors(apierrors = { @ApiError(code = UnknownMessicRESTException.VALUE, description = "Unknown error"),
        @ApiError(code = NotAuthorizedMessicRESTException.VALUE, description = "Forbidden access"),
        @ApiError(code = IOMessicRESTException.VALUE, description = "IO internal server error"), })
@RequestMapping(value = "/{albumSid}/{resourceSid}/cover", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.OK)/*w  w  w . j  a va  2  s  . c  o m*/
@ResponseBody
@ApiResponseObject
public void setAlbumCover(
        @PathVariable @ApiParam(name = "albumSid", description = "SID of the album to get the cover", paramType = ApiParamType.PATH, required = true) Long albumSid,
        @PathVariable @ApiParam(name = "resourceSid", description = "SID of the resource of the album to set as cover", paramType = ApiParamType.PATH, required = true) Long resourceSid)
        throws UnknownMessicRESTException, NotAuthorizedMessicRESTException, NotFoundMessicRESTException,
        IOMessicRESTException {
    User user = SecurityUtil.getCurrentUser();
    try {
        albumAPI.setAlbumCover(user, albumSid, resourceSid);
    } catch (Exception e) {
        log.error("failed!", e);
        throw new UnknownMessicRESTException(e);
    }
}