Example usage for org.springframework.http MediaType TEXT_PLAIN_VALUE

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

Introduction

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

Prototype

String TEXT_PLAIN_VALUE

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

Click Source Link

Document

A String equivalent of MediaType#TEXT_PLAIN .

Usage

From source file:com.kajj.tools.logviewer.LogViewerRestController.java

/**
 * Returns the last <code>numberOfLines</code> from the specified log file. The log file must
 * be in the containers log directory to be read.
 *
 * @param fileName the name of the log file.
 * @param numberOfLines the number of lines to return in the tail.
 * @return The last <code>numberOfLines</code> of the specified log file.
 *///from  w  ww .j ava  2 s  .  co m
@RequestMapping(value = "/logs/{fileName}/tail", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE)
public ResponseEntity<String> tailLog(@PathVariable final String fileName,
        @RequestParam(value = "lines", defaultValue = "100") final int numberOfLines) {
    try {
        final List<String> logs = logRepository.getTailLog(fileName, numberOfLines);

        final StringBuilder tail = new StringBuilder();
        int i = 1;
        for (final String log : logs) {
            tail.append(i++).append(": ").append(log).append("\n");
        }

        return new ResponseEntity(tail.toString(), HttpStatus.OK);
    } catch (final IOException ioe) {
        throw new ResourceAccessException("Unable to read log file", ioe);
    }
}

From source file:test.phoenixnap.oss.plugin.naming.testclasses.UriPrefixIgnoredController.java

@RequestMapping(value = METHOD_PART + "/base/endpoint", method = { RequestMethod.POST }, produces = {
        MediaType.TEXT_PLAIN_VALUE })
public String secondEndpointAgain(@RequestBody ThreeElementClass request) {
    return null;/*from   w ww .  ja  v a  2s. com*/
}

From source file:org.zalando.logbook.servlet.example.ExampleController.java

@RequestMapping(value = "/read-byte", produces = MediaType.TEXT_PLAIN_VALUE)
public void readByte(final HttpServletRequest request, final HttpServletResponse response) throws IOException {

    final ServletInputStream input = request.getInputStream();
    final ServletOutputStream output = response.getOutputStream();

    while (true) {
        final int read = input.read();
        if (read == -1) {
            break;
        }/*from  w w w .ja  v  a 2 s  . c o m*/
        output.write(read);
    }
}

From source file:org.calrissian.restdoclet.example.spring.ExampleController.java

/**
 * Simply adds the value provided via the query parameter to a running total.
 *
 * @param value Value to be added to a running total.
 * @return The current total./*w  ww. j a v  a  2 s .  co m*/
 */
@RequestMapping(value = "/add", method = POST, produces = MediaType.TEXT_PLAIN_VALUE)
@ResponseBody
public String postExample(@RequestParam int value) {
    count += value;
    return Integer.toString(count);
}

From source file:com.biblio.web.rest.UserResource.java

@RequestMapping(value = "/register", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE,
        MediaType.TEXT_PLAIN_VALUE })

public Object createUser(@RequestBody @Valid ManagedUserVM managedUserVM, BindingResult bindingResult)
        throws MessagingException {
    Map<String, Object> modele = new HashMap<>();

    if (bindingResult.hasErrors()) {

        modele.put(Constants.ERROR, true);
        modele.put(Constants.MESSAGE, "Enregistrement chou");
        bindingResult.getFieldErrors().stream().forEach((f) -> {
            System.out.println("Field " + f.getField());
            System.out.println("error" + f.getDefaultMessage());
            modele.put(f.getField(), f.getDefaultMessage());
        });/*from  ww  w . jav  a2  s .  com*/

        return modele;
    }

    if (userRepository.findOneByLogin(managedUserVM.getLogin()).isPresent()) {

        modele.put(Constants.ERROR, "true");
        modele.put(Constants.MESSAGE, "Enregistrement chou");
        modele.put("login", "Ce nom d'utilisateur existe deja");
        return modele;
    }

    if (userRepository.findOneByEmail(managedUserVM.getEmail()).isPresent()) {
        modele.put(Constants.ERROR, "true");
        modele.put(Constants.MESSAGE, "Enregistrement chou");
        modele.put("email", "Ce email est deja utilis");

        return modele;
    }

    managedUserVM.setPassword("123456");

    if (managedUserVM.getType() != null && managedUserVM.getType() == 2) {
        managedUserVM.getRoles().add(ConstantRole.ADMIN_ROLE);
    } else {
        managedUserVM.getRoles().add(ConstantRole.USER_ROLE);
    }

    managedUserVM.setPassword(RandomUtil.generateAlphaNumerique(8));
    User u = userService.createUser(managedUserVM);
    modele.put(Constants.MESSAGE, "Enregistrement russi");
    try {
        mailService.sendEmail(u.getEmail(), "Mot de passe", " Les parametre de compte\n Username : "
                + u.getLogin() + " \n password " + managedUserVM.getPassword(), true, true);
    } catch (Exception e) {
        System.out.println("ex");
        return modele;
    }
    return modele;
}

From source file:com.ge.predix.controller.test.AcsMonitoringControllerIT.java

public void testMonitoringHeartBeat() throws Exception {
    this.mockMvc.perform(get(HEARTBEAT_URL).accept(MediaType.TEXT_PLAIN_VALUE)).andExpect(status().isOk())
            .andExpect(content().contentType("text/plain;charset=UTF-8")).andExpect(content().string("alive"));
}

From source file:org.oncoblocks.centromere.web.controller.ReadOnlyApiController.java

/**
 * {@code POST /}/*from   w ww  . j a  v  a2  s.com*/
 * Attempts to create a new record using the submitted entity. Throws an exception if the
 *   entity already exists.
 *
 * @return updated representation of the submitted entity
 */
@RequestMapping(value = "", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE,
        ApiMediaTypes.APPLICATION_HAL_JSON_VALUE, ApiMediaTypes.APPLICATION_HAL_XML_VALUE,
        MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_PLAIN_VALUE })
public HttpEntity<?> create(@RequestBody T entity, HttpServletRequest request) {
    throw new MethodNotAllowedException();
}

From source file:org.openbaton.nfvo.api.RestKeys.java

/**
 * Generate a new Key with the given name for the given project
 *
 * @param name : name of the key to be created
 *///from w  w  w  . j  av a 2  s .  c o m
@RequestMapping(value = "generate", method = RequestMethod.POST, produces = MediaType.TEXT_PLAIN_VALUE)
@ResponseStatus(HttpStatus.CREATED)
public String generateKey(@RequestHeader(value = "project-id") String projectId, @RequestBody String name)
        throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeySpecException, IOException {
    log.debug("Generating key with name: " + name);
    return keyManagement.generateKey(projectId, name);
}

From source file:org.energyos.espi.datacustodian.web.api.ManageRESTController.java

/**
 * Provides access to administrative commands through the pattern:
 * DataCustodian/manage?command=[resetDataCustodianDB |
 * initializeDataCustodianDB]//from w  w  w .j  a  v a2  s .  co m
 * 
 * @param response
 *            Contains text version of stdout of the command
 * @param params
 *            [["command" . ["resetDataCustodianDB" |
 *            "initializeDataCustodianDB"]]]
 * @param stream
 * @throws IOException
 */
@RequestMapping(value = Routes.DATA_CUSTODIAN_MANAGE, method = RequestMethod.GET, produces = "text/plain")
@ResponseBody
public void doCommand(HttpServletResponse response, @RequestParam Map<String, String> params,
        InputStream stream) throws IOException {

    response.setContentType(MediaType.TEXT_PLAIN_VALUE);

    try {
        try {
            String commandString = params.get("command");
            System.out.println("[Manage] " + commandString);
            ServletOutputStream output = response.getOutputStream();

            output.println("[Manage] Restricted Management Interface");
            output.println("[Manage] Request: " + commandString);

            String command = null;

            // parse command
            if (commandString.contains("resetDataCustodianDB")) {
                command = "/etc/OpenESPI/DataCustodian/resetDatabase.sh";
            } else if (commandString.contains("initializeDataCustodianDB")) {
                command = "/etc/OpenESPI/DataCustodian/initializeDatabase.sh";

            }

            if (command != null) {
                Process p = Runtime.getRuntime().exec(command);
                p.waitFor();
                output.println("[Manage] Result: ");
                BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));

                String line = reader.readLine();

                while (line != null) {
                    System.out.println("[Manage] " + line);
                    output.println("[Manage]: " + line);
                    line = reader.readLine();
                }
                reader = new BufferedReader(new InputStreamReader(p.getErrorStream()));
                output.println("[Manage] Errors: ");
                line = reader.readLine();
                while (line != null) {
                    System.out.println("[Manage] " + line);
                    output.println("[Manage]: " + line);
                    line = reader.readLine();
                }
            }

        } catch (IOException e1) {
        } catch (InterruptedException e2) {
        }

        System.out.println("[Manage] " + "Done");

    } catch (Exception e) {
        System.out.printf("**** [Manage] Error: %s\n", e.toString());
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    }

}

From source file:org.zalando.logbook.servlet.example.ExampleController.java

@RequestMapping(value = "/read-bytes", produces = MediaType.TEXT_PLAIN_VALUE)
public void readBytes(final HttpServletRequest request, final HttpServletResponse response) throws IOException {

    final ServletInputStream input = request.getInputStream();
    final ServletOutputStream output = response.getOutputStream();

    final byte[] buffer = new byte[1];

    while (true) {
        final int read = input.read(buffer);
        if (read == -1) {
            break;
        }//from w  ww  .j  av a2s.  c om
        output.write(buffer);
    }
}