Example usage for org.springframework.util MultiValueMap toString

List of usage examples for org.springframework.util MultiValueMap toString

Introduction

In this page you can find the example usage for org.springframework.util MultiValueMap toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:com.svds.geolocationservice.controllers.GeoLocationRestController.java

/**
 * Test method for REST server//w w  w .j a v a  2s . c o  m
 * 
 * @param requestParams
 * @return
 */
@RequestMapping(value = "/testValue", method = RequestMethod.GET)
public String testValue(@RequestParam MultiValueMap<String, String> requestParams) {

    Gson gson = gsonBuilder.setPrettyPrinting().create();
    LOG.info("at testValue: " + requestParams.toString());
    return gson.toJson(requestParams);
}

From source file:de.zib.vold.userInterface.RESTController.java

/**
 * Handles Delete requests.//from   w  w  w  .  ja v a  2s.  com
 *
 * This method is used by clients to delete keys.
 *
 * @param clientIpAddress The ip of the sending client, it's extracted from the request itself.
 * @param args The URL arguments of the request.
 * @param request Request informations
 * @return A map of keys with its lifetime, whereas the livetime is zero if an error for that key occured.
 */
@RequestMapping(method = RequestMethod.DELETE)
public ResponseEntity<Map<String, String>> delete(@ModelAttribute("clientIpAddress") String clientIpAddress,
        @RequestParam MultiValueMap<String, String> args, HttpServletRequest request) {

    // guard
    {
        logger.debug("DELETE: " + args.toString());

        checkState();
    }

    Map<String, String> invalidKeys = new HashMap<String, String>();

    // get actual scope
    String scope;
    {
        scope = request.getRequestURI();
        String removepath = removePrefix + request.getContextPath() + request.getServletPath();

        scope = scope.substring(removepath.length(), scope.length());
    }

    // process each key
    {
        for (Map.Entry<String, List<String>> entry : args.entrySet()) {
            URIKey urikey;
            String source;
            Key k;

            // build key
            {
                urikey = URIKey.fromURIString(entry.getKey(), enc);

                File path_correction = new File(scope + "/" + urikey.getKey().get_scope());

                k = new Key(path_correction.getPath(), urikey.getKey().get_type(),
                        urikey.getKey().get_keyname());

                if (null == urikey.getSource()) {
                    source = clientIpAddress;
                } else {
                    source = urikey.getSource();
                }
            }

            // handle write request for that key
            {
                try {
                    frontend.delete(source, k);
                } catch (VoldException e) {
                    logger.error("Could not handle write request for key " + entry.getKey() + ". ", e);
                    invalidKeys.put(entry.getKey(), "ERROR: " + e.getMessage());
                }
            }
        }
    }

    return new ResponseEntity<Map<String, String>>(invalidKeys, HttpStatus.OK);
}

From source file:de.zib.vold.userInterface.RESTController.java

/**
 * Handles Post requests.// ww w . ja  v  a 2s . c om
 *
 * This method is used by clients to submit new keys, refresh their registration or delete them.
 *
 * @param clientIpAddress The ip of the sending client, it's extracted from the request itself.
 * @param args The URL arguments of the request.
 * @param request Request informations
 * @return A map of keys with its lifetime, whereas the livetime is zero if an error for that key occured.
 */
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<Map<String, String>> refresh(@ModelAttribute("clientIpAddress") String clientIpAddress,
        @RequestParam MultiValueMap<String, String> args,
        @RequestHeader(value = "TIMESTAMP", defaultValue = "unset") String timeStampHeader,
        HttpServletRequest request) {
    final long timeStamp;
    if (timeStampHeader.equals("unset"))
        timeStamp = DateTime.now().getMillis();
    else
        timeStamp = Long.parseLong(timeStampHeader);

    // guard
    {
        logger.debug("POST: " + args.toString());

        checkState();
    }

    Map<String, String> invalidKeys = new HashMap<String, String>();

    // get actual scope
    String scope;
    {
        scope = request.getRequestURI();
        String removepath = removePrefix + request.getContextPath() + request.getServletPath();

        scope = scope.substring(removepath.length(), scope.length());
    }

    // process each key
    {
        for (Map.Entry<String, List<String>> entry : args.entrySet()) {
            URIKey urikey;
            String source;
            Key k;

            // build key
            {
                urikey = URIKey.fromURIString(entry.getKey(), enc);

                File path_correction = new File(scope + "/" + urikey.getKey().get_scope());

                k = new Key(path_correction.getPath(), urikey.getKey().get_type(),
                        urikey.getKey().get_keyname());

                if (null == urikey.getSource()) {
                    source = clientIpAddress;
                } else {
                    source = urikey.getSource();
                }
            }

            // handle write request for that key
            {
                try {
                    frontend.refresh(source, k, timeStamp);
                } catch (VoldException e) {
                    logger.error("Could not handle write request for key " + entry.getKey() + ". ", e);
                    invalidKeys.put(entry.getKey(), "ERROR: " + e.getMessage());
                }
            }
        }
    }

    return new ResponseEntity<Map<String, String>>(invalidKeys, HttpStatus.OK);
}

From source file:de.zib.vold.userInterface.RESTController.java

/**
 * Handles Put requests.//  ww  w .  j a v a2  s . c o  m
 *
 * This method is used by clients to submit new keys.
 *
 * @param clientIpAddress The ip of the sending client, it's extracted from the request itself.
 * @param args The URL arguments of the request.
 //* @param argsbody The PUT body arguments of the request.
 * @param request Request informations
 * @return A map of keys with its lifetime, whereas the livetime is zero if an error for that key occured.
 */
@RequestMapping(method = RequestMethod.PUT)
public ResponseEntity<Map<String, String>> insert(@ModelAttribute("clientIpAddress") String clientIpAddress,
        @RequestParam MultiValueMap<String, String> args,
        //@RequestBody MultiValueMap< String, String > argsbody,
        @RequestHeader(value = "TIMESTAMP", defaultValue = "unset") String timeStampHeader,
        HttpServletRequest request) throws IOException {

    MultiValueMap<String, String> argsbody = getBody();
    final long timeStamp;
    if (timeStampHeader.equals("unset"))
        timeStamp = DateTime.now().getMillis();
    else
        timeStamp = Long.parseLong(timeStampHeader);

    // guard
    {
        if (argsbody != null)
            logger.debug("PUT: " + args.toString() + " AND " + argsbody.toString());
        else
            logger.debug("PUT: " + args.toString());

        checkState();
    }

    Map<String, String> invalidKeys = new HashMap<String, String>();

    // get actual scope
    String scope;
    {
        scope = request.getRequestURI();
        String removepath = removePrefix + request.getContextPath() + request.getServletPath();

        scope = scope.substring(removepath.length(), scope.length());
    }

    // merge args to argsbody
    {
        if (null == argsbody) {
            if (null == args) {
                logger.warn("Got a totally empty request from " + clientIpAddress + ".");
                return new ResponseEntity<Map<String, String>>(invalidKeys, HttpStatus.OK);
            }

            argsbody = args;
        } else if (null != args) {
            argsbody.putAll(args);
        }
    }

    // process each key
    {
        for (Map.Entry<String, List<String>> entry : argsbody.entrySet()) {
            URIKey urikey;
            String source;
            Key k;

            // build key
            {
                urikey = URIKey.fromURIString(entry.getKey(), enc);

                File path_correction = new File(scope + "/" + urikey.getKey().get_scope());

                k = new Key(path_correction.getPath(), urikey.getKey().get_type(),
                        urikey.getKey().get_keyname());

                if (null == urikey.getSource()) {
                    source = clientIpAddress;
                } else {
                    source = urikey.getSource();
                }
            }

            // handle write request for that key
            {
                try {
                    logger.debug(
                            "Inserting " + entry.getValue().size() + " values for key " + urikey.toURIString());
                    frontend.insert(source, k, new HashSet<String>(entry.getValue()), timeStamp);
                } catch (VoldException e) {
                    logger.error("Could not handle write request for key " + entry.getKey() + ". ", e);
                    invalidKeys.put(entry.getKey(), "ERROR: " + e.getMessage());
                }
            }
        }
    }

    return new ResponseEntity<Map<String, String>>(invalidKeys, HttpStatus.OK);
}

From source file:org.encuestame.oauth2.support.OAuth2Support.java

public AccessGrant exchangeForAccess(String authorizationCode, String redirectUri) {
    log.debug("exchangeForAccess:{" + authorizationCode);
    log.debug("exchangeForAccess redirectUri{: " + redirectUri);
    MultiValueMap<String, String> requestParameters = new LinkedMultiValueMap<String, String>();
    requestParameters.set("client_id", clientId);
    requestParameters.set("client_secret", clientSecret);
    requestParameters.set("code", authorizationCode);
    requestParameters.set("redirect_uri", redirectUri);
    requestParameters.set("grant_type", "authorization_code");
    log.debug("requestParameters " + requestParameters.toString());
    Map result = getRestTemplate().postForObject(accessTokenUrl, requestParameters, Map.class);
    log.debug("Access Grant " + result.toString());
    return new AccessGrant(valueOf(result.get("access_token")), valueOf(result.get("refresh_token")));
}

From source file:org.encuestame.oauth2.support.OAuth2Support.java

/**
 *
 * @param refreshToken/*from   ww w .  jav a2  s. c  o  m*/
 * @return
 */
public AccessGrant refreshToken(final String refreshToken) {
    log.debug("refreshToken" + refreshToken);
    MultiValueMap<String, String> requestParameters = new LinkedMultiValueMap<String, String>();
    requestParameters.set("client_id", clientId);
    requestParameters.set("client_secret", clientSecret);
    requestParameters.set("refresh_token", refreshToken);
    requestParameters.set("grant_type", "refresh_token");
    log.debug("requestParameters " + requestParameters.toString());
    @SuppressWarnings("unchecked")
    Map<String, ?> result = getRestTemplate().postForObject(accessTokenUrl, requestParameters, Map.class);
    log.debug(result);
    return new AccessGrant(valueOf(result.get("access_token")), refreshToken);
}