Example usage for java.net URLDecoder decode

List of usage examples for java.net URLDecoder decode

Introduction

In this page you can find the example usage for java.net URLDecoder decode.

Prototype

public static String decode(String s, Charset charset) 

Source Link

Document

Decodes an application/x-www-form-urlencoded string using a specific java.nio.charset.Charset Charset .

Usage

From source file:com.cabserver.handler.Driver.java

@POST
@Path("login")
@Produces(MediaType.TEXT_HTML)//from  ww w  . j a  v a 2 s .com
public Response login(String jsonData) {
    // String data = "";
    HashMap<String, String> responseMap = new HashMap<String, String>();
    try {

        // log.info("Inside Driver >> login before decoding = " + jsonData);

        jsonData = (URLDecoder.decode(jsonData, "UTF-8"));

        // log.info("Inside Driver >> login >>" + jsonData);

        // jsonData = jsonData.split("=")[1];
        if (jsonData.contains("=")) {
            jsonData = jsonData.split("=")[1];
            // log.info("Inside Driver >> signup >> data=" + jsonData);
        }

        log.info("login >> data=" + jsonData);

        if (jsonData != null && jsonData.length() > 1) {

            // Gson gson = new Gson();
            JSONParser parser = new JSONParser();
            JSONObject obj = (JSONObject) parser.parse(jsonData);

            // LoginInfo result = new LoginInfo();
            String phone = (String) obj.get("phone");
            // String password = (String) obj.get("password");

            // log.info("Driver Phone =" + phone);
            // log.info("password =" + password);

            if (phone != null) {

                DriverMaster driverMaster = DatabaseManager.validateDriver(phone);

                if (driverMaster != null) {

                    // log.info("Inside Driver >> Login Successfull. HTTP bookingStatus code is 200.");

                    responseMap.put("code", "200");
                    responseMap.put("msg", "Login Succesful.");
                    responseMap.put("driverId", driverMaster.getDriverId());
                    responseMap.put("firstName", driverMaster.getFirstName());
                    responseMap.put("phoneNumber", driverMaster.getPhoneNumber());
                    responseMap.put("driverStatus", driverMaster.getDriverStatus());
                    responseMap.put("currAddr", driverMaster.getCurrAddr());
                    responseMap.put("currLongt", driverMaster.getCurrLongt());
                    responseMap.put("currLat", driverMaster.getCurrLat());
                    responseMap.put("bookingId", driverMaster.getBookingId());

                    log.info("login >>  Login response = " + responseMap.toString());

                } else {
                    log.info("login >> Login Error. HTTP bookingStatus code is "
                            + ConfigDetails.constants.get("BOOKING_FAILED_CODE") + ".");

                    responseMap.put("code", ConfigDetails.constants.get("BOOKING_FAILED_CODE"));
                    responseMap.put("msg", "Driver phone doesn't exists.");
                }

            }

        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    if (responseMap.size() < 1) {

        log.info("Login Error. HTTP bookingStatus code is " + ConfigDetails.constants.get("BOOKING_FAILED_CODE")
                + ".");

        responseMap.put("code", ConfigDetails.constants.get("BOOKING_FAILED_CODE"));
        responseMap.put("msg", "Server Error.");
        return Response.status(200).entity(jsonCreater(responseMap)).build();
    } else {
        return Response.status(200).entity(jsonCreater(responseMap)).build();
    }

}

From source file:com.xidu.framework.common.util.EnDecoderUtils.java

/**
 * decode input string by specific coding.
 * /*from   w w w  .  j  a va2s  . c  o m*/
 * @Date : 2011-3-23
 * @param input
 *            - string
 * @param coding
 *            - coding string
 * @return encoded string
 */
public static String decode(String input, String coding) {
    if (StringUtils.isBlank(input)) {
        return "";
    }
    try {
        return URLDecoder.decode(input, coding);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return input;
}

From source file:com.dgq.utils.EncodeUtils.java

/**
 * URL ?, EncodeUTF-8./*from w w w.  j  av a2s . c o m*/
 */
public static String urlDecode(String part) {
    try {
        return URLDecoder.decode(part, DEFAULT_URL_ENCODING);
    } catch (UnsupportedEncodingException e) {
        throw new SecurityException("URL?!");
    }
}

From source file:feedme.controller.SocketServer.java

/**
 * Called when a socket connection opened
 * *//*from   ww w.  jav a  2  s  . co  m*/
@OnOpen
public void onOpen(Session session) {

    System.out.println(session.getId() + " has opened a connection");

    Map<String, String> queryParams = getQueryMap(session.getQueryString());

    String name = "";

    if (queryParams.containsKey("name")) {

        // Getting client name via query param
        name = queryParams.get("name");
        try {
            name = URLDecoder.decode(name, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        // Mapping client name and session id

    }
    if (!name.equals("customer")) {
        nameSessionPair.put(name, session);
        sessions.add(session);
    }

    // Adding session to session list

    try {
        // Sending session id to the client that just connected
        session.getBasicRemote().sendText(jsonUtils.getClientDetailsJson(name, "Your session details"));
    } catch (IOException e) {
        e.printStackTrace();
    }

    System.out.println("Sessions size " + sessions.size());
    for (Iterator<Map.Entry<String, Session>> it = nameSessionPair.entrySet().iterator(); it.hasNext();) {
        Map.Entry<String, Session> e = it.next();
        System.out.println("rest id " + e.getKey() + " rest_session_id " + e.getValue().getId().toString());
    }

}

From source file:com.macrosoft.common.encode.Encodes.java

/**
 * URL ?, EncodeUTF-8. //from w  w w  . j  av a2  s .  c  o m
 */
public static String urlDecode(String part) {
    try {
        return URLDecoder.decode(part, DEFAULT_URL_ENCODING);
    } catch (UnsupportedEncodingException e) {
        throw Exceptions.unchecked(e);
    }
}

From source file:com.shangpin.utils.Encodes.java

/**
 * URL ?, EncodeUTF-8.//from  w ww .j av a 2 s  .  c om
 */
public static String urlDecode(String part) {

    try {
        return URLDecoder.decode(part, DEFAULT_URL_ENCODING);
    } catch (UnsupportedEncodingException e) {
        throw Exceptions.unchecked(e);
    } catch (NullPointerException e) {
        return null;
    }
}

From source file:zipkin.sparkstreaming.job.ZipkinSparkStreamingConfiguration.java

static String pathToJar(Class<?> type) {
    URL jarFile = type.getProtectionDomain().getCodeSource().getLocation();
    try {//w  w  w  . j  a  v  a2 s.co  m
        return URLDecoder.decode(jarFile.getPath(), "UTF-8");
    } catch (UnsupportedEncodingException e) {
        return null;
    }
}

From source file:com.depas.utils.FileUtils.java

private static String getConfigDirectoryPath(Class<?> c, String rootDirectory) {
    // get url to iwc/idc directory on classpath
    try {//from  w  ww  .j a  v a2 s.c o m
        URL url = ClassLoader.getSystemResource(rootDirectory);
        if (url == null) {
            // try this classpath, for running in eclipse
            url = c.getClassLoader().getResource(rootDirectory);
        }
        if (url != null) {
            String path = url.getPath();
            if (!path.endsWith("\\") && !path.endsWith("/")) {
                path += "/";
            }
            return URLDecoder.decode(path, "UTF-8");
        } else {
            return null;
        }
    } catch (Exception ex) {
        logger.warn("Error obtaining file path to '" + rootDirectory + "' config directory: " + ex);
        return null;
    }

}

From source file:ma.glasnost.orika.test.perf.MultiThreadedTestCase.java

private static Set<Class<?>> getNonAnonymousClasses() {
    Set<Class<?>> classes = new HashSet<Class<?>>();
    File classFolder;//from   w w w.j a  va  2 s .c  o  m
    try {
        classFolder = new File(
                URLDecoder.decode(MultiThreadedTestCase.class.getResource("/").getFile(), "UTF-8"));
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }
    List<Class<?>> allClasses = DynamicSuite.findTestCases(classFolder, ".*");
    for (Class<?> aClass : allClasses) {
        if (!aClass.isAnonymousClass()) {
            classes.add(aClass);
        }
    }
    return classes;
}

From source file:com.salesforce.ide.core.internal.utils.ForceIdeUrlParser.java

private String extractInnerString(final String preFix, final String suffix, final boolean canTerminate)
        throws UnsupportedEncodingException {

    String innerValue = "";
    int startNdx = url.toLowerCase().indexOf(preFix.toLowerCase());
    if (-1 == startNdx) {
        return innerValue;
    }/*from  www. j a v a2 s  .  co  m*/

    startNdx += preFix.length();

    int endNdx = url.toLowerCase().indexOf(suffix.toLowerCase(), startNdx);
    if (-1 == endNdx) {
        if (canTerminate) {
            endNdx = url.length();
        } else {
            return innerValue;
        }
    }
    innerValue = url.substring(startNdx, endNdx);

    return URLDecoder.decode(innerValue, CharEncoding.UTF_8);
}