Example usage for javax.servlet.http HttpServletRequest setCharacterEncoding

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

Introduction

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

Prototype

public void setCharacterEncoding(String env) throws UnsupportedEncodingException;

Source Link

Document

Overrides the name of the character encoding used in the body of this request.

Usage

From source file:com.megaeyes.web.controller.VISController.java

@ControllerDescription(description = "?id?", isLog = false, isCheckSession = true)
@RequestMapping("/deleteGVIC.json")
public void deletevic(HttpServletRequest request, HttpServletResponse response)
        throws UnsupportedEncodingException {
    request.setCharacterEncoding("UTF-8");
    String id = (String) request.getAttribute("id");
    BaseResponse resp = new BaseResponse();
    try {/*from w ww.  j  av a2s  .co m*/
        vISManager.deleteVic(id, false);
        resp.setCode(ErrorCode.SUCCESS);
    } catch (BusinessException be) {
        resp.setCode(be.getCode());
        resp.setMessage(be.getMessage());
    }
    writePageNoZip(response, resp);
}

From source file:com.megaeyes.web.controller.VISController.java

@ControllerDescription(description = "?", isLog = true, isCheckSession = true)
@RequestMapping("/deleteVisJson.json")
public void deleteVis(HttpServletRequest request, HttpServletResponse response)
        throws UnsupportedEncodingException {
    request.setCharacterEncoding("UTF-8");
    // System.out.println("In deleteVISJsonServlet ...");
    BaseResponse resp = new BaseResponse();
    String id = (String) request.getAttribute("id");
    try {//from   w  ww. ja  v  a  2 s . c  om
        vISManager.DeleteVis(id, false);
        resp.setCode(ErrorCode.SUCCESS);
    } catch (BusinessException be) {
        resp.setCode(be.getCode());
        resp.setMessage(be.getMessage());
    }
    writePageNoZip(response, resp);
}

From source file:com.megaeyes.web.controller.VISController.java

@ControllerDescription(description = "??ID?", isLog = false, isCheckSession = true)
@RequestMapping("/listGVICByVisId.json")
public void listVicByVisId(HttpServletRequest request, HttpServletResponse response)
        throws UnsupportedEncodingException {
    request.setCharacterEncoding("UTF-8");
    String visId = (String) request.getAttribute("visId");
    ListGenVicResponse resp = new ListGenVicResponse();
    try {//  w ww .  j a  v a2 s.c  o m
        List<ListVideoInputChannelVO> vics = vISManager.listVicByVisId(visId);
        resp.setVics(vics);
        resp.setCode(ErrorCode.SUCCESS);
    } catch (BusinessException be) {
        resp.setCode(be.getCode());
        resp.setMessage(be.getMessage());
    }
    writePageNoZip(response, resp);

}

From source file:be.fedict.eid.idp.sp.protocol.ws_federation.AuthenticationResponseProcessor.java

/**
 * Process the incoming WS-Federation response.
 * // w w w .  ja  va 2s .c  o m
 * @param recipient
 *            recipient, should match SAML v2.0 assertions's
 *            AudienceRestriction
 * @param context
 *            optional expected context
 * @param requiresResponseSignature
 *            do we expect a signature on the response or not, or
 *            <code>null</code> if to be retrieved from the
 *            {@link AuthenticationResponseService}.
 * @param request
 *            the HTTP servlet request that holds the SAML2 response.
 * @return the {@link be.fedict.eid.idp.common.saml2.AuthenticationResponse}
 * @throws AuthenticationResponseProcessorException
 *             case something went wrong
 */
public AuthenticationResponse process(String recipient, String context, Boolean requiresResponseSignature,
        HttpServletRequest request) throws AuthenticationResponseProcessorException {

    DateTime now = new DateTime();
    SecretKey secretKey = null;
    PrivateKey privateKey = null;
    int maxOffset = 5;
    boolean expectAssertionSigned = null != requiresResponseSignature ? requiresResponseSignature : false;
    ValidationService validationService = null;

    if (null != this.service) {
        secretKey = this.service.getAttributeSecretKey();
        privateKey = this.service.getAttributePrivateKey();
        maxOffset = this.service.getMaximumTimeOffset();
        expectAssertionSigned = this.service.requiresResponseSignature();
        validationService = this.service.getValidationService();
    }

    // force UTF8 encoding!
    try {
        request.setCharacterEncoding("UTF8");
    } catch (UnsupportedEncodingException e) {
        throw new AuthenticationResponseProcessorException(e);
    }

    // check wa
    String wa = request.getParameter("wa");
    if (null == wa) {
        throw new AuthenticationResponseProcessorException("Missing \"wa\" param.");
    }
    if (!wa.equals("wsignin1.0")) {
        throw new AuthenticationResponseProcessorException("Unexpected value for \"wa\" param.");
    }

    // validate optional ctx
    validateContext(context, request.getParameter("wctx"));

    // get wresult
    String wresult = request.getParameter("wresult");
    LOG.debug("wresult=\"" + wresult + "\"");

    if (null == wresult) {
        throw new AuthenticationResponseProcessorException("Missing \"wresult\" param.");
    }
    Document responseDocument = Saml2Util.parseDocument(wresult);
    RequestSecurityTokenResponseCollection rstCollections = Saml2Util
            .unmarshall(responseDocument.getDocumentElement());

    if (rstCollections.getRequestSecurityTokenResponses().size() != 1) {
        throw new AuthenticationResponseProcessorException("Expected exactly 1 RequestSecurityTokenResponse");
    }

    RequestSecurityTokenResponse rstResponse = rstCollections.getRequestSecurityTokenResponses().get(0);

    // context
    validateContext(context, rstResponse.getContext());

    // tokentype
    validateTokenType(rstResponse);

    // requesttype
    validateRequestType(rstResponse);

    // keytype
    validateKeyType(rstResponse);

    // validate security token
    Assertion assertion = validateSecurityToken(rstResponse);

    // validate assertion
    AuthenticationResponse authenticationResponse;
    try {
        authenticationResponse = Saml2Util.validateAssertion(assertion, now, maxOffset, recipient, recipient,
                null, secretKey, privateKey);
    } catch (AssertionValidationException e) {
        throw new AuthenticationResponseProcessorException(e);
    }

    // check if SP expects a signature and if there is one
    if (null == assertion.getSignature() && expectAssertionSigned) {
        throw new AuthenticationResponseProcessorException("Expected a signed assertion but was not so! ");
    }

    // validate assertion's signature if any
    if (null != assertion.getSignature()) {
        try {
            // fix for recent versions of Apache xmlsec
            assertion.getDOM().setIdAttribute("ID", true);

            List<X509Certificate> certificateChain = Saml2Util.validateSignature(assertion.getSignature());

            if (null != validationService) {
                // have to reparse the document here
                NodeList assertionNodeList = Saml2Util.parseDocument(wresult)
                        .getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "Assertion");
                LOG.debug("number of SAML2 assertions: " + assertionNodeList.getLength());
                if (1 != assertionNodeList.getLength()) {
                    throw new AuthenticationResponseProcessorException("missing SAML2 Assertion");
                }
                Element assertionElement = (Element) assertionNodeList.item(0);

                DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
                documentBuilderFactory.setNamespaceAware(true);
                DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
                Document tokenDocument = documentBuilder.newDocument();
                Node assertionTokenNode = tokenDocument.importNode(assertionElement, true);
                tokenDocument.appendChild(assertionTokenNode);

                String validationServiceLocation = validationService.getLocation();
                String expectedAudience = validationService.getExpectedAudience();
                SecurityTokenServiceClient securityTokenServiceClient = new SecurityTokenServiceClient(
                        validationServiceLocation);
                securityTokenServiceClient.validateToken(tokenDocument.getDocumentElement(), expectedAudience);
            }
            if (null != this.service) {
                this.service.validateServiceCertificate(authenticationResponse.getAuthenticationPolicy(),
                        certificateChain);
            }

        } catch (CertificateException e) {
            throw new AuthenticationResponseProcessorException(e);
        } catch (ValidationException e) {
            throw new AuthenticationResponseProcessorException(e);
        } catch (Exception e) {

            if ("javax.ejb.EJBException".equals(e.getClass().getName())) {
                Exception exception;
                try {
                    Method getCausedByExceptionMethod = e.getClass().getMethod("getCausedByException",
                            new Class[] {});
                    exception = (Exception) getCausedByExceptionMethod.invoke(e, new Object[] {});
                } catch (Exception e2) {
                    LOG.debug("error: " + e.getMessage(), e);
                    throw new AuthenticationResponseProcessorException(
                            "error retrieving the root cause: " + e2.getMessage());
                }

                throw new AuthenticationResponseProcessorException("Validation exception: "
                        + (null != exception ? exception.getMessage() : e.getMessage()));
            }

            throw new AuthenticationResponseProcessorException(e);
        }
    }

    return authenticationResponse;
}

From source file:org.dbflute.saflute.web.servlet.filter.RequestLoggingFilter.java

protected void prepareCharacterEncodingIfNeeds(HttpServletRequest request) throws UnsupportedEncodingException {
    if (request.getCharacterEncoding() == null) {
        // logging filter calls parameters for debug
        // but if no setting of encoding, Tomcat parses parameters as latin1
        // and keep the parameters parsed by wrong encoding in request object
        // so needs to set encoding here
        // (it is set in spite of log level for same behavior in several environments)
        request.setCharacterEncoding(requestCharacterEncoding != null ? requestCharacterEncoding : "UTF-8");
    }/*www .j a  v a 2 s  .  co  m*/
}

From source file:com.hp.action.CustomerAction.java

public String updateCustomer() throws UnsupportedEncodingException {
    HttpServletRequest request = (HttpServletRequest) ActionContext.getContext()
            .get(ServletActionContext.HTTP_REQUEST);
    HttpSession session = request.getSession();

    //Authorize/*from   ww  w .j ava 2  s .co  m*/
    if (!userDAO.authorize((String) session.getAttribute("user_name"),
            (String) session.getAttribute("user_password"))) {
        return LOGIN;
    }

    //request.setCharacterEncoding("UTF-8");
    request.setCharacterEncoding("UTF8");
    staffsList = staffDAO.getListUser(null);

    String test = request.getParameter("mTinhThanh");
    String name = customer.getDienThoai();

    String pw = demo.getmDienThoai();
    Float y = demo.getmYCoordinates();

    System.out.println("__" + pw + "__ " + y + " PARA: " + test);
    System.out.println("__" + name);

    // NEW
    if (customer.getStt() <= 0) {
        customer.setCoordinateX(0d);
        customer.setCoordinateY(0d);
        boolean status = customerDAO.saveOrUpdate(customer);
        customersList = customerDAO.getListCustomer();

        if (status)
            return SUCCESS;
        else
            return INPUT;
    }

    //UPDATE
    boolean status = customerDAO.update(customer);
    customersList = customerDAO.getListCustomer();

    if (status)
        return SUCCESS;
    else
        return INPUT;
}

From source file:com.megaeyes.web.controller.VISController.java

@ControllerDescription(description = "", isLog = true, isCheckSession = true)
@RequestMapping("/createAOC.json")
public void createAOC(HttpServletRequest request, HttpServletResponse response)
        throws UnsupportedEncodingException {
    request.setCharacterEncoding("UTF-8");
    BaseResponse resp = new BaseResponse();
    resp.setCode(ErrorCode.SUCCESS);//from   w  w w.ja v  a 2 s . co  m
    String name = (String) request.getAttribute("name");
    String visId = (String) request.getAttribute("visId");
    String typeId = (String) request.getAttribute("typeId");
    String location = (String) request.getAttribute("location");
    String note = (String) request.getAttribute("note");
    String organId = (String) request.getAttribute("organId");
    String epDeviceType = (String) request.getAttribute("epDeviceType");
    String sipCode = (String) request.getAttribute("sipCode");
    String longitude = (String) request.getAttribute("longitude");
    String latitude = (String) request.getAttribute("latitude");
    String channelId = (String) request.getAttribute("channelId");
    if (resp.getCode().equals(ErrorCode.SUCCESS)) {
        try {
            String id = vISManager.createAOC(visId, name, typeId, location, note, organId, epDeviceType,
                    sipCode, longitude, latitude, channelId);
            resp.setMessage(id);
            resp.setCode(ErrorCode.SUCCESS);
        } catch (BusinessException be) {
            resp.setCode(be.getCode());
            resp.setMessage(be.getMessage());
        }
    }
    writePageNoZip(response, resp);
}

From source file:com.megaeyes.web.controller.VISController.java

@ControllerDescription(description = "", isLog = false, isCheckSession = true)
@RequestMapping("/updateAOC.json")
public void updateAOC(HttpServletRequest request, HttpServletResponse response)
        throws UnsupportedEncodingException {
    request.setCharacterEncoding("UTF-8");
    BaseResponse resp = new BaseResponse();
    resp.setCode(ErrorCode.SUCCESS);//from w  ww.  jav a  2s  . c o  m
    String id = (String) request.getAttribute("id");
    String name = (String) request.getAttribute("name");
    String visId = (String) request.getAttribute("visId");
    String typeId = (String) request.getAttribute("typeId");
    String location = (String) request.getAttribute("location");
    String note = (String) request.getAttribute("note");
    String organId = (String) request.getAttribute("organId");
    String epDeviceType = (String) request.getAttribute("epDeviceType");
    String sipCode = (String) request.getAttribute("sipCode");
    String longitude = (String) request.getAttribute("longitude");
    String isSupportScheme = (String) request.getAttribute("isSupportScheme");
    String latitude = (String) request.getAttribute("latitude");
    String channelId = (String) request.getAttribute("channelId");
    if (resp.getCode().equals(ErrorCode.SUCCESS)) {
        try {
            vISManager.updateAOC(id, name, visId, typeId, location, note, isSupportScheme, organId,
                    epDeviceType, sipCode, longitude, latitude, channelId);
            resp.setCode(ErrorCode.SUCCESS);
        } catch (BusinessException be) {
            resp.setCode(be.getCode());
            resp.setMessage(be.getMessage());
        }
    }
    writePageNoZip(response, resp);
}

From source file:com.megaeyes.web.controller.VISController.java

@ControllerDescription(description = "??", isLog = false, isCheckSession = true)
@RequestMapping("/listVideoInputServerByUserId.json")
public void listVideoInputServerByUserId(HttpServletRequest request, HttpServletResponse response)
        throws UnsupportedEncodingException {
    request.setCharacterEncoding("UTF-8");
    GetVideoInputServerResponse resp = new GetVideoInputServerResponse();
    String start = (String) request.getAttribute("start");
    String limit = (String) request.getAttribute("limit");
    String name = (String) request.getAttribute("name");
    String address = (String) request.getAttribute("address");
    String ip = (String) request.getAttribute("ip");
    String deviceNumber = (String) request.getAttribute("deviceNumber");
    String lineBackFew = (String) request.getAttribute("lineBackFew");
    String towerNumber = (String) request.getAttribute("towerNumber");
    String switchesIp = (String) request.getAttribute("switchesIp");
    String serialServerIp = (String) request.getAttribute("serialServerIp");
    String voltageLevel = (String) request.getAttribute("voltageLevel");
    String areaBelongs = (String) request.getAttribute("areaBelongs");
    String type = (String) request.getAttribute("type");
    if (StringUtils.isBlank(deviceNumber))
        deviceNumber = null;//  w w  w  . ja va  2  s . c o m
    String userId = (String) request.getAttribute("userId");
    try {
        List vis = vISManager.getVISByUserId(start, limit, name, address, deviceNumber, lineBackFew,
                towerNumber, switchesIp, serialServerIp, voltageLevel, areaBelongs, type, userId);
        int count = vISManager.getVISByUserIdCount(name, address, deviceNumber, lineBackFew, towerNumber,
                switchesIp, serialServerIp, voltageLevel, areaBelongs, type, userId);
        resp.setVis(vis);
        resp.setTotalCount(count + "");
    } catch (BusinessException be) {
        resp.setCode(be.getCode());
        resp.setMessage(be.getMessage());
    }
    writePageNoZip(response, resp);
}

From source file:com.megaeyes.web.controller.VISController.java

@ControllerDescription(description = "", isLog = false, isCheckSession = true)
@RequestMapping("/updateAIC.json")
public void updateAIC(HttpServletRequest request, HttpServletResponse response)
        throws UnsupportedEncodingException {
    request.setCharacterEncoding("UTF-8");
    BaseResponse resp = new BaseResponse();
    resp.setCode(ErrorCode.SUCCESS);//from  ww w. jav  a 2 s  . co m
    String name = (String) request.getAttribute("name");
    String id = (String) request.getAttribute("id");
    String typeId = (String) request.getAttribute("typeId");
    String location = (String) request.getAttribute("location");
    String note = (String) request.getAttribute("note");
    String isSupportScheme = (String) request.getAttribute("isSupportScheme");
    String organId = (String) request.getAttribute("organId");
    String epDeviceType = (String) request.getAttribute("epDeviceType");
    String sipCode = (String) request.getAttribute("sipCode");
    String longitude = (String) request.getAttribute("longitude");
    String latitude = (String) request.getAttribute("latitude");
    String channelId = (String) request.getAttribute("channelId");
    String isShare = request.getParameter("isShare");
    if (StringUtils.isBlank(isShare)) {
        resp.setCode(ErrorCode.PARAMETER_NOT_FOUND);
        resp.setMessage("isShare");
    }
    if (resp.getCode().equals(ErrorCode.SUCCESS)) {
        try {
            vISManager.updateAIC(id, name, typeId, location, note, isSupportScheme, organId, epDeviceType,
                    sipCode, longitude, latitude, channelId, isShare);
        } catch (BusinessException be) {
            resp.setCode(be.getCode());
            resp.setMessage(be.getMessage());
        }
    }
    writePageNoZip(response, resp);
}