Example usage for org.springframework.web.bind.annotation RequestMethod toString

List of usage examples for org.springframework.web.bind.annotation RequestMethod toString

Introduction

In this page you can find the example usage for org.springframework.web.bind.annotation RequestMethod toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.BaseCrudControllerTest.java

/**
 * Creates a request from the given parameters.
 * <p>/* ww  w . jav a2s  . com*/
 * The requestURI is automatically preceded with "/rest/" + RestConstants.VERSION_1.
 * 
 * @param method
 * @param requestURI
 * @return
 */
public MockHttpServletRequest request(RequestMethod method, String requestURI) {
    MockHttpServletRequest request = new MockHttpServletRequest(method.toString(),
            "/rest/" + RestConstants.VERSION_1 + "/" + requestURI);
    request.addHeader("content-type", "application/json");
    return request;
}

From source file:org.impalaframework.extension.mvc.annotation.handler.AnnotationHandlerMethodResolver.java

private Method getHandlerMethod(String lookupPath, String methodLookupPath, HttpServletRequest request) {

    for (Method handlerMethod : getHandlerMethods()) {
        RequestMapping mapping = AnnotationUtils.findAnnotation(handlerMethod, RequestMapping.class);
        String[] values = mapping.value();

        if (values[0].equals(lookupPath)) {

            RequestMethod[] method = mapping.method();
            if (method != null && method.length > 0) {
                for (RequestMethod requestMethod : method) {
                    if (request.getMethod().equals(requestMethod.toString())) {
                        pathMethodCache.put(methodLookupPath, handlerMethod);
                        return handlerMethod;
                    }/*w  w  w. j  a  v  a 2 s .c  om*/
                }
            } else {
                pathMethodCache.put(methodLookupPath, handlerMethod);
                return handlerMethod;
            }
        }
    }

    return null;
}

From source file:org.openmrs.module.emrapi.web.controller.BaseEmrControllerTest.java

/**
 * Creates a request from the given parameters.
 * <p>/*from  w  w w  .j av  a  2s.  c om*/
 * The requestURI is automatically preceded with "/rest/" + RestConstants.VERSION_1.
 *
 * @param method
 * @param requestURI
 * @return
 */
public MockHttpServletRequest request(RequestMethod method, String requestURI) {
    MockHttpServletRequest request = new MockHttpServletRequest(method.toString(), requestURI);
    request.addHeader("content-type", "application/json");
    return request;
}

From source file:org.bahmni.module.bahmnicore.web.v1_0.search.BahmniMainResourceControllerTest.java

/**
 * Creates a request from the given parameters.
 * <p>/*from   w  ww.  java2 s  . com*/
 * The requestURI is automatically preceded with "/rest/" + RestConstants.VERSION_1.
 * 
 * @param method
 * @param requestURI
 * @return
 */
public MockHttpServletRequest request(RequestMethod method, String requestURI) {
    MockHttpServletRequest request = new MockHttpServletRequest(method.toString(),
            "/rest/" + getNamespace() + "/" + requestURI);
    request.addHeader("content-type", "application/json");
    return request;
}

From source file:edu.kit.scc.http.HttpClient.java

private HttpResponse makeRequest(HttpURLConnection urlConnection, String user, String password, String body,
        RequestMethod method) {
    HttpResponse response = null;/*from   w w w.j a v a 2  s.  com*/
    OutputStream out = null;
    InputStream in = null;
    BufferedReader buffReader = null;

    try {
        urlConnection.setRequestMethod(method.toString());
        urlConnection.setRequestProperty("Accept", "*/*");

        if (user != null && !user.isEmpty()) {
            if (password != null && !password.isEmpty()) {
                String value = Base64.encodeBase64String((user + ":" + password).getBytes());
                log.debug("Authorization: Basic {}", value);
                urlConnection.setRequestProperty("Authorization", "Basic " + value);
            } else {
                log.debug("Authorization: Bearer {}", user);
                urlConnection.setRequestProperty("Authorization", "Bearer " + user);
            }
        }

        if (body != null) {
            urlConnection.setDoOutput(true);

            byte[] bodyBytes = body.getBytes("UTF-8");
            out = urlConnection.getOutputStream();
            out.write(bodyBytes);
        }

        urlConnection.connect();
        in = urlConnection.getInputStream();
        buffReader = new BufferedReader(new InputStreamReader(in));
        StringBuffer stringBuffer = new StringBuffer();
        String inputLine;
        while ((inputLine = buffReader.readLine()) != null) {
            stringBuffer.append(inputLine);
        }
        response = new HttpResponse(urlConnection.getResponseCode(), stringBuffer.toString());

    } catch (IOException e) {
        // e.printStackTrace();
        log.error("ERROR {}", e.getMessage());
    } catch (Exception e) {
        // e.printStackTrace();
        log.error("ERROR {}", e.getMessage());
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                // e.printStackTrace();
                log.error("ERROR {}", e.getMessage());
            }
        }
        if (out != null) {
            try {
                out.close();
            } catch (IOException e) {
                // e.printStackTrace();
                log.error("ERROR {}", e.getMessage());
            }
        }
        if (buffReader != null) {
            try {
                buffReader.close();
            } catch (IOException e) {
                // e.printStackTrace();
                log.error("ERROR {}", e.getMessage());
            }
        }
    }
    return response;
}