List of usage examples for javax.servlet.http HttpServletRequest getHeader
public String getHeader(String name);
String
. From source file:jetbrick.web.mvc.multipart.CommonsFileUpload.java
@Override public MultipartRequest transform(HttpServletRequest request) throws IOException { String contextType = request.getHeader("Content-Type"); if (contextType == null || !contextType.startsWith("multipart/form-data")) { return null; }/* www . j av a 2 s . c o m*/ String encoding = request.getCharacterEncoding(); MultipartRequest req = new MultipartRequest(request); ServletFileUpload upload = new ServletFileUpload(); upload.setHeaderEncoding(encoding); try { FileItemIterator it = upload.getItemIterator(request); while (it.hasNext()) { FileItemStream item = it.next(); String fieldName = item.getFieldName(); InputStream stream = item.openStream(); try { if (item.isFormField()) { req.setParameter(fieldName, Streams.asString(stream, encoding)); } else { String originalFilename = item.getName(); if (originalFilename == null || originalFilename.length() == 0) { continue; } File diskFile = UploadUtils.getUniqueTemporaryFile(originalFilename); OutputStream fos = new FileOutputStream(diskFile); try { IoUtils.copy(stream, fos); } finally { IoUtils.closeQuietly(fos); } FilePart filePart = new FilePart(fieldName, originalFilename, diskFile); req.addFile(filePart); } } finally { IoUtils.closeQuietly(stream); } } } catch (FileUploadException e) { throw new IllegalStateException(e); } return req; }
From source file:com.iwancool.dsm.service.impl.AbstractBaseService.java
/** * ?IP?/*from w w w .ja v a 2 s .c om*/ * * @author long * @create 2014-4-16 ?6:05:46 * @since * @param request * @return */ protected String getRequestIPAddress(HttpServletRequest request) { String remoteIp = request.getHeader("x-forwarded-for"); if (remoteIp == null || remoteIp.isEmpty() || "unknown".equalsIgnoreCase(remoteIp)) { remoteIp = request.getHeader("X-Real-IP"); } if (remoteIp == null || remoteIp.isEmpty() || "unknown".equalsIgnoreCase(remoteIp)) { remoteIp = request.getHeader("Proxy-Client-IP"); } if (remoteIp == null || remoteIp.isEmpty() || "unknown".equalsIgnoreCase(remoteIp)) { remoteIp = request.getHeader("WL-Proxy-Client-IP"); } if (remoteIp == null || remoteIp.isEmpty() || "unknown".equalsIgnoreCase(remoteIp)) { remoteIp = request.getHeader("HTTP_CLIENT_IP"); } if (remoteIp == null || remoteIp.isEmpty() || "unknown".equalsIgnoreCase(remoteIp)) { remoteIp = request.getHeader("HTTP_X_FORWARDED_FOR"); } if (remoteIp == null || remoteIp.isEmpty() || "unknown".equalsIgnoreCase(remoteIp)) { remoteIp = request.getRemoteAddr(); } if (remoteIp == null || remoteIp.isEmpty() || "unknown".equalsIgnoreCase(remoteIp)) { remoteIp = request.getRemoteHost(); } return remoteIp; }
From source file:com.bstek.dorado.view.resolver.OldIconsFileResolver.java
protected ResourcesWrapper createResourcesWrapper(HttpServletRequest request, DoradoContext context) throws Exception { String resourceType = PNG;//from ww w. j av a 2 s. com String ua = request.getHeader("User-Agent"); if (ua.indexOf(CHROME_FRAME) < 0) { boolean isMSIE = (ua != null && ua.indexOf(MSIE) != -1); if (isMSIE) { float version = NumberUtils.toFloat(MSIE_VERSION_PATTERN.matcher(ua).replaceAll("$1"), Float.MAX_VALUE); if (version < 7) { resourceType = GIF; } } } Resource[] resources = context.getResources(ICON_PATH + resourceType); return new ResourcesWrapper(resources, getResourceTypeManager().getResourceType(resourceType)); }
From source file:com.wisemapping.rest.view.ImportTransformationView.java
private void setContentDisposition(HttpServletRequest request, HttpServletResponse response, String fileName) { final String userAgent = request.getHeader("user-agent"); String disposition = fileName; boolean isInternetExplorer = (userAgent.contains("MSIE")); try {/* w w w . j a v a 2 s .c o m*/ byte[] fileNameBytes = fileName.getBytes((isInternetExplorer) ? ("windows-1250") : ("utf-8")); String dispositionFileName = ""; for (byte b : fileNameBytes) { dispositionFileName += (char) (b & 0xff); } disposition = "attachment; filename=\"" + dispositionFileName + "\""; } catch (UnsupportedEncodingException ence) { // ... handle exception ... } response.setHeader("Content-disposition", disposition); }
From source file:core.NiprSyncController.java
private boolean isAuthorized(HttpServletRequest request, HttpServletResponse response) { String lAuthHeader = request.getHeader("Authorization"); if (!Configuration.IsAuthenticated(lAuthHeader)) { System.out.println("Authentication Failed"); response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); return false; }//from w w w. j a va2s. c om return true; }
From source file:org.n52.web.BaseController.java
protected boolean isRequestingPdfData(HttpServletRequest request) { return APPLICATION_PDF.getMimeType().equals(request.getHeader("Accept")); }
From source file:org.n52.web.BaseController.java
protected boolean isRequestingJsonData(HttpServletRequest request) { return APPLICATION_JSON.getMimeType().equals(request.getHeader("Accept")); }
From source file:com.flexive.war.filter.BrowserDetect.java
public BrowserDetect(HttpServletRequest request) { this(request.getHeader("User-Agent")); }
From source file:com.alliander.osgp.shared.security.AuthenticationTokenProcessingFilter.java
/** * Get value from header or query parameters. * * @param request//from w ww. j a va 2 s . c o m * servlet request * @return value when found or null otherwise */ private String getValue(final HttpServletRequest request, final String headerKey, final String paramKey) { String value = request.getHeader(headerKey); // Second fetch from query parameters if (value == null) { value = request.getParameter(paramKey); } return value; }
From source file:com.hobba.hobaserver.services.security.ChallengeUtil.java
private String getChallenge(HttpServletRequest request) { String header = request.getHeader("Authorized"); String[] headerParams = header.split("[.]"); String chalenge = headerParams[1]; return new String(Base64.decodeBase64(chalenge)); }