Java 类org.apache.catalina.util.URLEncoder 实例源码

项目:tomcat7    文件:TestApplicationContextGetRequestDispatcher.java   
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {

    AsyncContext ac = req.startAsync();
    // Quick and dirty. Sufficient for this test but ignores lots of
    // edge cases.
    String target = null;
    if (dispatchPath != null) {
        target = req.getServletPath();
        int lastSlash = target.lastIndexOf('/');
        target = target.substring(0, lastSlash + 1);
        if (encodePath) {
            target = URLEncoder.DEFAULT.encode(target, "UTF-8");
        }
        target += dispatchPath;
    }
    try {
        ac.dispatch(target);
    } catch (UnsupportedOperationException uoe) {
        ac.complete();
        resp.setContentType("text/plain");
        resp.setCharacterEncoding("UTF-8");
        resp.getWriter().print(NULL);
    }
}
项目:apache-tomcat-7.0.73-with-comment    文件:TestApplicationContextGetRequestDispatcher.java   
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {

    AsyncContext ac = req.startAsync();
    // Quick and dirty. Sufficient for this test but ignores lots of
    // edge cases.
    String target = null;
    if (dispatchPath != null) {
        target = req.getServletPath();
        int lastSlash = target.lastIndexOf('/');
        target = target.substring(0, lastSlash + 1);
        if (encodePath) {
            target = URLEncoder.DEFAULT.encode(target, "UTF-8");
        }
        target += dispatchPath;
    }
    try {
        ac.dispatch(target);
    } catch (UnsupportedOperationException uoe) {
        ac.complete();
        resp.setContentType("text/plain");
        resp.setCharacterEncoding("UTF-8");
        resp.getWriter().print(NULL);
    }
}
项目:lazycat    文件:AsyncContextImpl.java   
@Override
public void dispatch() {
    check();
    String path;
    String pathInfo;
    ServletRequest servletRequest = getRequest();
    if (servletRequest instanceof HttpServletRequest) {
        HttpServletRequest sr = (HttpServletRequest) servletRequest;
        path = sr.getServletPath();
        pathInfo = sr.getPathInfo();
    } else {
        path = request.getServletPath();
        pathInfo = request.getPathInfo();
    }
    if (pathInfo != null) {
        path += pathInfo;
    }
    if (this.context.getDispatchersUseEncodedPaths()) {
        path = URLEncoder.DEFAULT.encode(path, "UTF-8");
    }
    dispatch(path);
}
项目:identity-outbound-auth-sms-otp    文件:SMSOTPAuthenticator.java   
/**
 * Proceed with SMS API's rest call.
 *
 * @param context      the AuthenticationContext
 * @param smsUrl       the smsUrl
 * @param httpMethod   the httpMethod
 * @param headerString the headerString
 * @param payload      the payload
 * @param httpResponse the httpResponse
 * @param mobile       the mobile number
 * @param otpToken     the OTP token
 * @return true or false
 * @throws IOException
 * @throws AuthenticationFailedException
 */
public boolean sendRESTCall(AuthenticationContext context, String smsUrl, String httpMethod,
                            String headerString, String payload, String httpResponse, String mobile,
                            String otpToken) throws IOException, AuthenticationFailedException {
    if (log.isDebugEnabled()) {
        log.debug("Preparing message for sending out");
    }
    HttpURLConnection httpConnection;
    boolean connection;
    String smsMessage = SMSOTPConstants.SMS_MESSAGE;
    URLEncoder encoder = new URLEncoder();
    String encodedMobileNo = encoder.encode(mobile);
    smsUrl = smsUrl.replaceAll("\\$ctx.num", encodedMobileNo).replaceAll("\\$ctx.msg",
            smsMessage.replaceAll("\\s", "+") + otpToken);
    URL smsProviderUrl = new URL(smsUrl);
    String subUrl = smsProviderUrl.getProtocol();
    if (subUrl.equals(SMSOTPConstants.HTTPS)) {
        httpConnection = (HttpsURLConnection) smsProviderUrl.openConnection();
        connection = getConnection(httpConnection, context, headerString, payload, httpResponse, encodedMobileNo,
                smsMessage, otpToken, httpMethod);
    } else {
        httpConnection = (HttpURLConnection) smsProviderUrl.openConnection();
        connection = getConnection(httpConnection, context, headerString, payload, httpResponse, encodedMobileNo,
                smsMessage, otpToken, httpMethod);
    }
    return connection;
}
项目:tomcat7    文件:Request.java   
/**
 * Return a RequestDispatcher that wraps the resource at the specified
 * path, which may be interpreted as relative to the current request path.
 *
 * @param path Path of the resource to be wrapped
 */
@Override
public RequestDispatcher getRequestDispatcher(String path) {

    if (context == null) {
        return null;
    }

    // If the path is already context-relative, just pass it through
    if (path == null) {
        return null;
    } else if (path.startsWith("/")) {
        return (context.getServletContext().getRequestDispatcher(path));
    }

    // Convert a request-relative path to a context-relative one
    String servletPath = (String) getAttribute(
            RequestDispatcher.INCLUDE_SERVLET_PATH);
    if (servletPath == null) {
        servletPath = getServletPath();
    }

    // Add the path info, if there is any
    String pathInfo = getPathInfo();
    String requestPath = null;

    if (pathInfo == null) {
        requestPath = servletPath;
    } else {
        requestPath = servletPath + pathInfo;
    }

    int pos = requestPath.lastIndexOf('/');
    String relative = null;
    if (context.getDispatchersUseEncodedPaths()) {
        if (pos >= 0) {
            relative = URLEncoder.DEFAULT.encode(
                    requestPath.substring(0, pos + 1), "UTF-8") + path;
        } else {
            relative = URLEncoder.DEFAULT.encode(requestPath, "UTF-8") + path;
        }
    } else {
        if (pos >= 0) {
            relative = requestPath.substring(0, pos + 1) + path;
        } else {
            relative = requestPath + path;
        }
    }

    return context.getServletContext().getRequestDispatcher(relative);
}
项目:apache-tomcat-7.0.73-with-comment    文件:Request.java   
/**
 * Return a RequestDispatcher that wraps the resource at the specified
 * path, which may be interpreted as relative to the current request path.
 *
 * @param path Path of the resource to be wrapped
 */
@Override
public RequestDispatcher getRequestDispatcher(String path) {

    if (context == null) {
        return null;
    }

    // If the path is already context-relative, just pass it through
    if (path == null) {
        return null;
    } else if (path.startsWith("/")) {
        return (context.getServletContext().getRequestDispatcher(path));
    }

    // Convert a request-relative path to a context-relative one
    String servletPath = (String) getAttribute(
            RequestDispatcher.INCLUDE_SERVLET_PATH);
    if (servletPath == null) {
        servletPath = getServletPath();
    }

    // Add the path info, if there is any
    String pathInfo = getPathInfo();
    String requestPath = null;

    if (pathInfo == null) {
        requestPath = servletPath;
    } else {
        requestPath = servletPath + pathInfo;
    }

    int pos = requestPath.lastIndexOf('/');
    String relative = null;
    if (context.getDispatchersUseEncodedPaths()) {
        if (pos >= 0) {
            relative = URLEncoder.DEFAULT.encode(
                    requestPath.substring(0, pos + 1), "UTF-8") + path;
        } else {
            relative = URLEncoder.DEFAULT.encode(requestPath, "UTF-8") + path;
        }
    } else {
        if (pos >= 0) {
            relative = requestPath.substring(0, pos + 1) + path;
        } else {
            relative = requestPath + path;
        }
    }

    return context.getServletContext().getRequestDispatcher(relative);
}
项目:lazycat    文件:Request.java   
/**
 * Return a RequestDispatcher that wraps the resource at the specified path,
 * which may be interpreted as relative to the current request path.
 *
 * @param path
 *            Path of the resource to be wrapped
 */
@Override
public RequestDispatcher getRequestDispatcher(String path) {

    if (context == null) {
        return null;
    }

    // If the path is already context-relative, just pass it through
    if (path == null) {
        return null;
    } else if (path.startsWith("/")) {
        return (context.getServletContext().getRequestDispatcher(path));
    }

    // Convert a request-relative path to a context-relative one
    String servletPath = (String) getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH);
    if (servletPath == null) {
        servletPath = getServletPath();
    }

    // Add the path info, if there is any
    String pathInfo = getPathInfo();
    String requestPath = null;

    if (pathInfo == null) {
        requestPath = servletPath;
    } else {
        requestPath = servletPath + pathInfo;
    }

    int pos = requestPath.lastIndexOf('/');
    String relative = null;
    if (context.getDispatchersUseEncodedPaths()) {
        if (pos >= 0) {
            relative = URLEncoder.DEFAULT.encode(requestPath.substring(0, pos + 1), "UTF-8") + path;
        } else {
            relative = URLEncoder.DEFAULT.encode(requestPath, "UTF-8") + path;
        }
    } else {
        if (pos >= 0) {
            relative = requestPath.substring(0, pos + 1) + path;
        } else {
            relative = requestPath + path;
        }
    }

    return context.getServletContext().getRequestDispatcher(relative);
}