java

Java code posted
created at 14 May 14:07

Edit | Back
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package edu.javacourse.rest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.*;
import java.util.Enumeration;

/**
 * @author Artem Pronchakov | email/xmpp: artem.pronchakov@calisto.email
 */
@ApplicationPath("/rest")
@Path("/context")
public class RestContext extends Application {

    private static final Logger log = LoggerFactory.getLogger(RestContext.class);

    @Context
    private HttpServletRequest request;

    @Context
    private HttpHeaders headers;

    @Context
    private UriInfo uriInfo;

    @Context
    private SecurityContext securityContext;

    @GET
    @Path("/query")
    public void query() {
        final Enumeration<String> parameterNames = request.getParameterNames();
        while (parameterNames.hasMoreElements()) {
            final String parameter = parameterNames.nextElement();
            log.debug("*** Parameter name from Request: {}:{} ", parameter, request.getParameter(parameter));
        }
        log.debug("*** Headers: {} ", headers.getRequestHeaders());
        log.debug("*** UriInfo: {} ", uriInfo.getRequestUri());
        log.debug("*** Is Secure: {} ", securityContext.isSecure());
        log.debug("*** User Principal: {} ", securityContext.getUserPrincipal() != null ? securityContext.getUserPrincipal().getName() : "Anonymous");
    }


}
1.48 KB in 6 ms with coderay