Example usage for java.lang Long Long

List of usage examples for java.lang Long Long

Introduction

In this page you can find the example usage for java.lang Long Long.

Prototype

@Deprecated(since = "9")
public Long(String s) throws NumberFormatException 

Source Link

Document

Constructs a newly allocated Long object that represents the long value indicated by the String parameter.

Usage

From source file:com.mockey.ui.HistoryHtmlServlet.java

/**
 * // w  ww  .  j  av  a  2s  .  co  m
 */
public void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    StringBuffer returnHTML = new StringBuffer();

    Long fulfilledRequestId = null;
    try {

        fulfilledRequestId = new Long(req.getParameter("fulfilledRequestId"));
        FulfilledClientRequest fCRequest = store.getFulfilledClientRequestsById(fulfilledRequestId);
        String contextRootScenarioURL = Url.getContextAwarePath("/scenario", req.getContextPath());

        returnHTML.append("<script type=\"text/javascript\">");
        returnHTML.append("$(document).ready(function() {");
        returnHTML.append("    $('textarea.resizable:not(.processed)').TextAreaResizer();");
        returnHTML.append("    $('iframe.resizable:not(.processed)').TextAreaResizer();");
        returnHTML.append("});");
        returnHTML.append("</script>");
        returnHTML.append("<table class=\"history\" width=\"100%\">");
        returnHTML.append("     <tbody>");
        returnHTML.append("<tr>");
        returnHTML.append("<td>");
        returnHTML.append("<div class=\"conflict_message\">");
        String contextRoot = req.getContextPath();
        String doitagainUrl = Url.getContextAwarePath("/doitagain", contextRoot);
        returnHTML.append("<form id=\"child\" action=\"" + doitagainUrl
                + "\" method=\"post\" style=\"background-color:#FFD7D7\" >");
        returnHTML.append("<input type=\"hidden\" name=\"fulfilledClientRequestId\" value=\""
                + fCRequest.getId() + "\" />");
        returnHTML.append("<h2>Request:</h2>");
        returnHTML.append("<p><h4>" + fCRequest.getRawRequest() + "</h4></p>");
        returnHTML.append("<p>Header (pipe delimited)</p>");
        returnHTML.append("<p><textarea class=\"resizable\" name=\"requestHeader\" rows=\"5\" cols=\"100%\">"
                + fCRequest.getClientRequestHeaders() + "</textarea></p>");
        returnHTML.append("<p>Parameters (pipe delimited)</p>");
        returnHTML
                .append("<p><textarea class=\"resizable\" name=\"requestParameters\" rows=\"5\" cols=\"100%\">"
                        + fCRequest.getClientRequestParameters() + "</textarea></p>");
        returnHTML.append("<p>Body</p>");
        returnHTML.append("<p><textarea class=\"resizable\" name=\"requestBody\" rows=\"10\" >"
                + fCRequest.getClientRequestBody() + "</textarea></p>");
        returnHTML.append(
                "<input type=\"submit\" name=\"NewParameters\" value=\"Send This Again\" class=\"button\" />");
        returnHTML
                .append(" This will build a request with the body, parameters, and header information above. ");
        returnHTML.append("</form>");
        returnHTML.append("</div>");
        returnHTML.append("</td>");
        returnHTML.append("</tr>");
        returnHTML.append(" <tr>");
        returnHTML.append("<td >");
        returnHTML.append("<form id=\"child\" action=\"" + contextRootScenarioURL + "\" method=\"post\">");
        returnHTML.append("<input type=\"hidden\" name=\"actionTypeGetFlag\" value=\"true\" />");
        returnHTML.append(
                "<input type=\"hidden\" name=\"serviceId\" value=\"" + fCRequest.getServiceId() + "\" />");
        returnHTML.append(
                "<div id=\"scenario" + fCRequest.getId() + "\" class=\"addition_message mockeyResponse\">");
        returnHTML.append("<h2>Response: </h2>");
        returnHTML.append("<p>Status</p>");
        returnHTML.append("<p>");
        returnHTML.append("    <textarea class=\"resizable\" name=\"responseStatus\" rows=\"1\" >"
                + fCRequest.getResponseMessage().getHttpResponseStatusCode() + "</textarea>");
        returnHTML.append("</p>");
        returnHTML.append("<p>Header</p>");
        returnHTML.append("<p>");
        returnHTML.append("<textarea class=\"resizable\" name=\"responseHeader\" rows=\"10\" >"
                + fCRequest.getResponseMessage().getHeaderInfo() + "</textarea>");
        returnHTML.append("</p>");
        returnHTML.append("<p>Body</p>");
        returnHTML.append("<p>");
        returnHTML.append(
                "<textarea style=\"margin-top: 0px;\" name=\"responseMessage\" class=\"resizable responseContent\" rows=\"10\" >"
                        + StringEscapeUtils.escapeXml(fCRequest.getResponseMessage().getBody())
                        + "</textarea>");
        returnHTML.append("</p>");
        returnHTML.append("<p>");
        returnHTML.append("<input type=\"submit\" name=\"Save\" value=\"Save Response as a Scenario\" />");
        String inspectFulfilledRequestURL = Url.getContextAwarePath("/inspect", req.getContextPath());
        returnHTML.append(" View response body as: ");
        returnHTML.append("<a href=\"" + inspectFulfilledRequestURL
                + "?content_type=text/xml;&fulfilledRequestId=" + fulfilledRequestId + "\">XML</a> ");
        returnHTML.append("<a href=\"" + inspectFulfilledRequestURL
                + "?content_type=text/plain;&fulfilledRequestId=" + fulfilledRequestId + "\">Plain</a> ");
        returnHTML.append("<a href=\"" + inspectFulfilledRequestURL
                + "?content_type=text/css;&fulfilledRequestId=" + fulfilledRequestId + "\">CSS</a> ");
        returnHTML.append("<a href=\"" + inspectFulfilledRequestURL
                + "?content_type=application/json;&fulfilledRequestId=" + fulfilledRequestId + "\">JSON</a> ");
        String encoded = URLEncoder.encode("text/html;charset=utf-8", "utf-8");
        returnHTML.append("<a href=\"" + inspectFulfilledRequestURL + "?content_type=" + encoded
                + "&fulfilledRequestId=" + fulfilledRequestId + "\">HTML</a> ");
        returnHTML.append("</p>");
        returnHTML.append("</form>");
        returnHTML.append("</div>");
        returnHTML.append("</td>");
        returnHTML.append("</tr>");
        returnHTML.append("</tbody>");
        returnHTML.append("</table>");

        //

    } catch (Exception e) {
        returnHTML.append("Sorry, history for this request is not available.");
    }

    resp.setContentType("text/html");

    PrintStream out = new PrintStream(resp.getOutputStream());

    out.println(returnHTML.toString());
}

From source file:cz.muni.fi.pv168.CustomerManagerTest.java

/**
 * Test of addCustomer method, of class CustomerManagerImplementation.
 *//* w  ww  .j  a  v a  2  s .  c o m*/
@Test
public void testAddCustomer() {
    Customer customer = newCustomer("Vitalii", "Chepeliuk", "Komarov", "5-20-86", "AK 373979");
    manager.addCustomer(customer);
    Long ID = customer.getID();
    assertNotNull(ID);
    Customer result = manager.findCustomerByID(ID);
    assertEquals(customer, result);
    assertNotSame(customer, result);
    assertCustomerDeepEquals(customer, result);

    try {
        manager.addCustomer(null);
        fail();
    } catch (IllegalArgumentException ex) {
    }

    customer = newCustomer("Juraj", "Kolchak", "Brno", "5-34-13", "AK 474854");
    customer.setID(new Long(50L));
    try {
        manager.addCustomer(customer);
        fail();
    } catch (IllegalArgumentException ex) {
    }
    customer.setID(null);
    customer.setDriversLicense(null);
    try {
        manager.addCustomer(customer);
        fail();
    } catch (IllegalArgumentException ex) {
    }
}

From source file:br.mdarte.exemplo.academico.cd.EstudanteDAO.java

public List<AbstractEntity> select(long id) throws DAOException {
    List<AbstractEntity> lista = new ArrayList<AbstractEntity>();
    try {/*from   ww w.java2s. co  m*/
        Session session = currentSession();
        EstudanteAbstract res = (EstudanteAbstract) session.load(EstudanteImpl.class, new Long(id));
        org.hibernate.Hibernate.initialize(res);
        lista.add(res);
    } catch (ObjectNotFoundException onfe) {
        throw new DAOException(onfe);
    } catch (HibernateException he1) {
        throw new DAOException(he1);
    }
    return lista;
}

From source file:net.nineapps.hystqio.controller.HibernateLinkDAO.java

public Link add(Link link) {

    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from w w w  .j ava 2  s .co m

    Query query = session.createQuery("from Link where url = :url");
    query.setString("url", link.getUrl());
    Link oldLink = (Link) query.uniqueResult();
    if (null != oldLink)
        return oldLink;

    session.save(link);
    if (null == link.getShortCode()) {
        link.setShortCode(generateShortcode(session));
        link.setClicks(new Long(0));
        link.setCreated(new Date(new java.util.Date().getTime()));
        session.save(link);
    }
    session.getTransaction().commit();
    return link;
}

From source file:com.mytwitter.retrofit.RetrofitRequestInterceptor2.java

License:asdf

@Override
public Response intercept(Chain chain) throws IOException {
    Request original = chain.request();

    TwitterSession session = Twitter.getSessionManager().getActiveSession();
    TwitterAuthToken authToken = session.getAuthToken();

    String oauth_signature_method = "HMAC-SHA1";
    String oauth_consumer_key = "TMr0RTusaWKrhnsTjRHpKqfBA";
    String oauth_token = authToken.token;
    String uuid_string = UUID.randomUUID().toString();
    uuid_string = uuid_string.replaceAll("-", "");
    String oauth_nonce = uuid_string; // any relatively random alphanumeric string will work here. I used UUID minus "-" signs
    Date now = Calendar.getInstance().getTime();
    String oauth_timestamp = (new Long(now.getTime() / 1000)).toString(); // get current time in milliseconds, then divide by 1000 to get seconds
    // I'm not using a callback value. Otherwise, you'd need to include it in the parameter string like the example above
    // the parameter string must be in alphabetical order
    String parameter_string = "oauth_consumer_key=" + oauth_consumer_key + "&oauth_nonce=" + oauth_nonce
            + "&oauth_signature_method=" + oauth_signature_method + "&oauth_timestamp=" + oauth_timestamp
            + "&oauth_version=1.0";
    System.out.println("parameter_string=" + parameter_string);
    String signature_base_string = "GET&https%3A%2F%2Fapi.twitter.com%2F1.1%2Fstatuses%2Fhome_timeline.json&"
            + URLEncoder.encode(parameter_string, "UTF-8");
    System.out.println("signature_base_string=" + signature_base_string);
    String oauth_signature = "";

    try {//  www .  j  av a 2s.c  o  m
        oauth_signature = computeSignature(signature_base_string, "3yasdfasmyconsumersecretfasd53&"); // note the & at the end. Normally the user access_token would go here, but we don't know it yet for request_token
        System.out.println("oauth_signature=" + URLEncoder.encode(oauth_signature, "UTF-8"));
    } catch (GeneralSecurityException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    /*String authorization_header_string =
        " oauth_consumer_key=\"" + oauth_consumer_key+
        "\", oauth_nonce=\"" + oauth_nonce +
        "\", oauth_signature=\""+URLEncoder.encode(oauth_signature, "UTF-8")+ "\""+
        " oauth_signature_method=\"HMAC-SHA1\""+
        "\", oauth_timestamp=\""+ oauth_timestamp +
        "\", oauth_token=\""+oauth_token+
                "\" OAuth oauth_version=\"1.0\"";*/

    String authorization_header_string = "OAuth oauth_version=\"1.0\","
            + " oauth_signature_method=\"HMAC-SHA1\"" + ", oauth_nonce=\"" + oauth_nonce
            + "\", oauth_timestamp=\"" + oauth_timestamp + "\", oauth_consumer_key=\"" + oauth_consumer_key
            + "\", oauth_token=\"" + oauth_token + "\", oauth_signature=\""
            + URLEncoder.encode(oauth_signature, "UTF-8") + "\"";

    /*String authorization_header_string="OAuth oauth_version=\"1.0\","+
        " oauth_signature_method=\"HMAC-SHA1\""+
        ", oauth_nonce=\"" + oauth_nonce +
        "\", oauth_timestamp=\""+ oauth_timestamp +
        "\", oauth_consumer_key=\"" + oauth_consumer_key+
        "\", oauth_token=\""+oauth_token+
        "\", oauth_signature=\""+URLEncoder.encode(oauth_signature, "UTF-8")+ "\"";*/

    //String authorization_header_string = "OAuth oauth_consumer_key=\"" + oauth_consumer_key + "\",oauth_signature_method=\"HMAC-SHA1\",oauth_timestamp=\"" +
    //oauth_timestamp + "\",oauth_nonce=\"" + oauth_nonce + "\",oauth_version=\"1.0\",oauth_signature=\"" + URLEncoder.encode(oauth_signature, "UTF-8") + "\"";

    System.out.println("authorization_header_string=" + authorization_header_string);

    // Customize the request
    Request request = original.newBuilder().header("Accept", "application/json")
            .header("Authorization", authorization_header_string).method(original.method(), original.body())
            .build();

    Response response = chain.proceed(request);

    // Customize or return the response
    return response;
}

From source file:com.redhat.rhn.domain.token.ActivationKeyFactory.java

/**
 * Creates and fills out a new Activation Key (Including generating a key/token).
 * Sets deployConfigs to false, disabled to 0, and usage limit to null.
 * @param user The user for the key/*  w  w w .j av  a2s  .co  m*/
 * @param note The note to attach to the key
 * @return Returns the newly created ActivationKey.
 */
public static ActivationKey createNewKey(User user, String note) {
    return createNewKey(user, null, "", note, new Long(0), null, false);
}

From source file:com.springsource.html5expense.controller.FileAttachmentController.java

@RequestMapping(value = "/download")
public void download(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String attachmentId = request.getParameter("attachmentId");
    Attachment attachment = this.attachmentService.getAttachment(new Long(attachmentId));
    response.setContentType(attachment.getContentType());
    response.setHeader("Content-Disposition", "attachment; filename=\"" + attachment.getFileName() + "\"");
    response.setHeader("cache-control", "must-revalidate");
    OutputStream out = response.getOutputStream();
    out.write(attachment.getContent());/*from w  ww.j av  a  2 s  . co  m*/
    out.flush();

}

From source file:org.tibetjungle.demo.service.ContactServiceImpl.java

public void create(Contact contact) {
    // Create the Contact itself
    contact.setId(new Long(counter++));
    contactDao.create(contact);//from  w  w w  . j a  v  a2 s. co m

    // Grant the current principal administrative permission to the contact
    aclPermissionService.grantAfterCreating(contact, new PrincipalSid(getUsername()),
            BasePermission.ADMINISTRATION);

    if (logger.isDebugEnabled()) {
        logger.debug(
                "Created contact " + contact + " and granted admin permission to recipient " + getUsername());
    }
}

From source file:com.mockey.ui.TwistInfoDeleteServlet.java

/**
 * Handles the following activities for <code>TwistInfo</code>
 * //from   w w  w. java  2s  .  co  m
 */
public void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    String responseType = req.getParameter("response-type");
    // If type is JSON, then respond with JSON
    // Otherwise, direct to JSP

    Long twistInfoId = null;
    TwistInfo twistInfo = null;
    try {
        twistInfoId = new Long(req.getParameter(PARAMETER_KEY_TWIST_ID));
        twistInfo = store.getTwistInfoById(twistInfoId);
        store.deleteTwistInfo(twistInfo);
    } catch (Exception e) {
        // Do nothing. If the value doesn't exist, oh well. 
    }

    if (PARAMETER_KEY_RESPONSE_TYPE_VALUE_JSON.equalsIgnoreCase(responseType)) {
        // ***********************
        // BEGIN - JSON response
        // ***********************
        resp.setContentType("application/json");
        PrintWriter out = resp.getWriter();
        try {
            JSONObject jsonResponseObject = new JSONObject();
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("success", "Deleted");
            jsonResponseObject.put("result", jsonObject);
            out.println(jsonResponseObject.toString());

        } catch (JSONException jsonException) {
            throw new ServletException(jsonException);
        }

        out.flush();
        out.close();
        return;
        // ***********************
        // END - JSON response
        // ***********************

    } else {
        List<TwistInfo> twistInfoList = store.getTwistInfoList();
        Util.saveSuccessMessage("Deleted", req);
        req.setAttribute("twistInfoList", twistInfoList);
        req.setAttribute("twistInfoIdEnabled", store.getUniversalTwistInfoId());

        RequestDispatcher dispatch = req.getRequestDispatcher("/twistinfo_setup.jsp");
        dispatch.forward(req, resp);
        return;
    }

}

From source file:com.googlecode.psiprobe.controllers.DecoratorController.java

protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    try {/*from  w  w  w  .  j  av a2  s . c o  m*/
        request.setAttribute("hostname", InetAddress.getLocalHost().getHostName());
    } catch (UnknownHostException e) {
        request.setAttribute("hostname", "unknown");
    }

    Properties version = (Properties) getApplicationContext().getBean("version");
    request.setAttribute("version", version.getProperty("probe.version"));

    Object uptimeStart = getServletContext().getAttribute(UptimeListener.START_TIME_KEY);
    if (uptimeStart != null && uptimeStart instanceof Long) {
        long l = ((Long) uptimeStart).longValue();
        long uptime = System.currentTimeMillis() - l;
        long uptime_days = uptime / (1000 * 60 * 60 * 24);

        uptime = uptime % (1000 * 60 * 60 * 24);
        long uptime_hours = uptime / (1000 * 60 * 60);

        uptime = uptime % (1000 * 60 * 60);
        long uptime_mins = uptime / (1000 * 60);

        request.setAttribute("uptime_days", new Long(uptime_days));
        request.setAttribute("uptime_hours", new Long(uptime_hours));
        request.setAttribute("uptime_mins", new Long(uptime_mins));
    }

    //
    // Work out the language of the interface by matching resource files that we have
    // to the request locale.
    //
    List fileNames = getMessageFileNamesForLocale(request.getLocale());
    String lang = "en";
    for (Iterator it = fileNames.iterator(); it.hasNext();) {
        String f = (String) it.next();
        if (getServletContext().getResource(f + ".properties") != null) {
            lang = f.substring(messagesBasename.length() + 1);
            break;
        }
    }

    request.setAttribute("lang", lang);

    return super.handleRequestInternal(request, response);
}