Example usage for javax.servlet.http HttpServletRequest getRequestURL

List of usage examples for javax.servlet.http HttpServletRequest getRequestURL

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getRequestURL.

Prototype

public StringBuffer getRequestURL();

Source Link

Document

Reconstructs the URL the client used to make the request.

Usage

From source file:gov.nih.nci.system.web.util.RESTUtil.java

public static Object getObject(String className, String idValue, HttpServletRequest request,
        String base64encodedUsernameAndPassword, boolean collection)
        throws gov.nih.nci.system.client.util.xml.XMLUtilityException {
    try {//from  w w  w  . ja  v a 2 s . c  om
        String url = request.getRequestURL().toString();
        String queryStr = "id";
        List<String> idValues = new ArrayList<String>();
        if (idValue.indexOf(",") != -1) {
            StringTokenizer tokenizer = new StringTokenizer(idValue, ",");
            while (tokenizer.hasMoreTokens())
                idValues.add(tokenizer.nextToken());
        } else {
            idValues.add(idValue);
        }
        //Set returnCollection = new HashSet();
        Collection returnCollection = new HashSet();
        for (String idStr : idValues) {
            String restURL = url.substring(0, url.lastIndexOf("/"));
            WebClient client = WebClient.create(restURL);

            if (base64encodedUsernameAndPassword != null) {
                client.header("Authorization", "Basic " + base64encodedUsernameAndPassword);
            }
            String path = "rest/" + className.substring(className.lastIndexOf(".") + 1, className.length())
                    + "/" + idStr;
            client.path(path);
            client.type("application/xml").accept("application/xml");
            Response r = client.get();
            if (r.getStatus() != Status.OK.getStatusCode()) {
                throw new gov.nih.nci.system.client.util.xml.XMLUtilityException(
                        "Failed to lookup id: " + idStr + " for class: " + className);
            } else {
                InputStream is = (InputStream) r.getEntity();
                InputStreamReader in = new InputStreamReader(is);
                String jaxbContextName = className.substring(0, className.lastIndexOf("."));
                Unmarshaller unmarshaller = new JAXBUnmarshaller(true, jaxbContextName);
                XMLUtility myUtil = new XMLUtility(null, unmarshaller);
                Object obj = myUtil.fromXML(in);
                if (collection) {
                    returnCollection.add(obj);
                    //return returnCol;
                } else
                    return obj;
            }
        }

        return returnCollection;
    } catch (gov.nih.nci.system.client.util.xml.XMLUtilityException e) {
        throw e;
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new gov.nih.nci.system.client.util.xml.XMLUtilityException(
                "Failed to lookup id: " + idValue + " for class: " + className);
    }
}

From source file:edu.pitt.dbmi.ccd.anno.links.ResourceLinks.java

default Link getRequestLink(HttpServletRequest request) {
    final StringBuffer url = request.getRequestURL();
    final String query = request.getQueryString();
    if (query == null) {
        return new Link(url.toString(), Link.REL_SELF);
    } else {//from   www  .  ja v  a 2  s. co m
        return new Link(url.append("?").append(query).toString(), Link.REL_SELF);
    }
}

From source file:helpers.FileUpload.java

public boolean doPost(HttpServletRequest request) {
    String directory = request.getRequestURL().toString() + "assets/uploads";

    boolean error_exist = false;
    String complete_file_name = null;
    MultipartRequest mr = null;//w ww.j  a  va2  s. c  o m
    try {
        mr = new MultipartRequest(request, "assets/uploads/", 10000000);
    } catch (IOException i) {
        //file size too big
        error_exist = true;
    }

    if (!error_exist) {
        Enumeration e = mr.getFileNames();
        String parameter_file_name = (String) e.nextElement();
        String file_name = mr.getFilesystemName(parameter_file_name);

        if (file_name == null) {
            //no file uploaded
        } else {
            complete_file_name = file_name + parameter_file_name;
        }
    }

    return true;
}

From source file:com.sambrannen.samples.events.web.RestEventController.java

private String buildNewLocation(HttpServletRequest request, Long id) {
    String url = request.getRequestURL().append("/{id}").toString();
    UriTemplate uriTemplate = new UriTemplate(url);
    return uriTemplate.expand(id).toASCIIString();
}

From source file:com.pamarin.income.security.JsfRedirectStrategy.java

private String getRequestUrl(HttpServletRequest request) {
    StringBuffer requestURL = request.getRequestURL();

    String queryString = request.getQueryString();
    if (StringUtils.hasText(queryString)) {
        requestURL.append("?").append(queryString);
    }// ww w . ja v a2  s . com

    return requestURL.toString();
}

From source file:org.cloudfoundry.identity.app.web.HomeController.java

@RequestMapping("/logout")
public String logout(Model model, HttpServletRequest request) {
    String redirect = request.getRequestURL().toString();
    model.addAttribute("cflogout", logoutUrl + "?redirect=" + redirect);
    return "loggedout";
}

From source file:com.janrain.servlet.LoggingMappingExceptionResolver.java

@Override
protected void logException(Exception ex, HttpServletRequest request) {
    super.logException(ex, request);
    logger.error("Error processing request: " + request.getRequestURL(), ex);
}

From source file:com.epam.hybris.test.storefront.security.impl.DefaultGuestCheckoutCartCleanStrategy.java

@Override
public boolean checkWhetherURLContainsCheckoutPattern(final HttpServletRequest request) {
    return request.getRequestURL().toString().matches(getCheckoutURLPattern());
}

From source file:de.hska.ld.core.config.filter.CrossOriginFilter.java

public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) req;
    String url = request.getRequestURL().toString();
    if (!url.contains("push")) {
        String origin = request.getHeader("Origin");
        HttpServletResponse response = (HttpServletResponse) res;
        response.setHeader("Access-Control-Allow-Credentials", "true");
        response.setHeader("Access-Control-Allow-Origin", origin);
        response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT");
        response.setHeader("Access-Control-Max-Age", "3600");
        response.setHeader("Access-Control-Allow-Headers", "x-requested-with, Content-Type, Authorization");
    }/*from   w  w w .  ja  v  a 2  s.  c om*/
    try {
        chain.doFilter(req, res);
    } catch (NestedServletException nse) {
        if (!(nse.getCause() instanceof NullPointerException && nse.getCause().getMessage() == null)) {
            if (!(nse.getCause() instanceof IllegalArgumentException)) {
                nse.printStackTrace();
            }
        }
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }
}

From source file:com.fileupload.myjavaservice.MyJavaService.java

/**
 * This is sample java operation that accepts an input from the caller and responds with "Hello".
 *
 * SecurityService that is Autowired will provide access to the security context of the caller. It has methods like isAuthenticated(),
 * getUserName() and getUserId() etc which returns the information based on the caller context.
 *
 * Methods in this class can declare HttpServletRequest, HttpServletResponse as input parameters to access the
 * caller's request/response objects respectively. These parameters will be injected when request is made (during API invocation).
 *///w w  w.  j a v a 2 s.  c  o  m
public String sampleJavaOperation(String name, HttpServletRequest request) {
    logger.debug("Starting sample operation with request url " + request.getRequestURL().toString());

    String result = null;
    if (securityService.isAuthenticated()) {
        result = "Hello " + name + ", You are logged in as " + securityService.getLoggedInUser().getUserName();
    } else {
        result = "Hello " + name + ", You are not authenticated yet!";
    }
    logger.debug("Returning {}", result);
    return result;
}