Example usage for org.jsoup.nodes Element attr

List of usage examples for org.jsoup.nodes Element attr

Introduction

In this page you can find the example usage for org.jsoup.nodes Element attr.

Prototype

public String attr(String attributeKey) 

Source Link

Document

Get an attribute's value by its key.

Usage

From source file:com.zacwolf.commons.email.Email.java

private void prepareImgs(final org.jsoup.nodes.Document doc, final Multipart htmlmultipart) {
    final Map<String, EmailAttachment> attachments = getAttachments();
    final org.jsoup.select.Elements imgs = doc.getElementsByTag("img");
    for (org.jsoup.nodes.Element img : imgs) {
        final String src = img.attr("src");
        final String cid = !src.startsWith("cid:") ? null : src.substring(4);
        try {//from  w w w.jav a2 s . c om
            EmailAttachment attachment;
            ByteArrayOutputStream baos;
            if (cid != null) {
                attachment = attachments.get(cid);
                img.attr("alt", attachment.getDescription());
                if (!img.attr("style").contains("display:"))//all inline images need the display:block; added for GMail compatability
                    img.attr("style", img.attr("style") + (!img.attr("style").endsWith(";") ? ";" : "")
                            + "display:block;");
                if (cid.toLowerCase().contains("_banner")
                        && doc.select("#banner").attr("style").contains("-radius")) {
                    BufferedImage image = makeRoundedBanner(
                            ImageIO.read(new ByteArrayInputStream(attachment.data)), 20);
                    doc.select("#contenttable").attr("style",
                            "width:" + image.getWidth() + "px;" + doc.select("#contenttable").attr("style"));
                    baos = new ByteArrayOutputStream();
                    try {
                        ImageIO.write(image, EmailAttachment.CONTENT_MIMETYPES.get(attachment.contenttype),
                                baos);
                    } finally {
                        baos.flush();
                    }
                    attachment = new EmailAttachment(attachment.filename, attachment.contenttype,
                            baos.toByteArray(), cid, "Rounded banner image");
                    if (htmlmultipart == null)
                        dataurlEncode(img, attachment);
                    if (doc.select("#footer").size() == 1
                            && doc.select("#footer").first().attr("style").contains("-radius")) {
                        Color bgcolor = Color.WHITE;
                        Color border = null;
                        String newstyle = "";
                        String[] styles = doc.select("#footer").first().attr("style").split(";");
                        for (String style : styles) {
                            if (style.startsWith("border"))
                                border = getColorFromStyle(style, null);
                            else if (style.startsWith("background-color:"))
                                bgcolor = getColorFromStyle(style, Color.WHITE);
                            else
                                newstyle += style + ";";
                        }
                        baos = new ByteArrayOutputStream();
                        try {
                            ImageIO.write(makeRoundedFooter(image.getWidth(), 20, bgcolor, border), "png",
                                    baos);
                        } finally {
                            baos.flush();
                        }
                        doc.select("#footer").first().parent()
                                .html("<td style=\"margin:0px;padding:0px;\" valign=\"top\" style=\"" + newstyle
                                        + "\"><img id=\"footer\" alt=\"rounded footer image\" src=\"cid:"
                                        + getREFID() + "_rounded_footer\" style=\"display:block;\" /></td>");
                    }
                    if (htmlmultipart == null)
                        dataurlEncode(doc.select("#footer").first(),
                                new EmailAttachment("footer.png", "image/png", baos.toByteArray(),
                                        getREFID() + "_rounded_footer", "Rounded footer image"));
                    else
                        htmlmultipart.addBodyPart(new EmailAttachment("footer.png", "image/png",
                                baos.toByteArray(), getREFID() + "_rounded_footer", "Rounded footer image"));
                } else if (htmlmultipart == null) {
                    dataurlEncode(img, attachment);
                }
                if (htmlmultipart != null)
                    htmlmultipart.addBodyPart(attachment);
            }
        } catch (Exception e) {
            throw new NullPointerException(
                    "Problem with embedding images into content.\nContact the content owner.\n\nERROR:" + e);
        }
    }
}

From source file:com.serphacker.serposcope.scraper.google.scraper.GoogleScraper.java

protected Status handleCaptchaRedirect(String captchaRedirect) {
    if (captchaRedirect == null || !captchaRedirect.contains("?continue=")) {
        return Status.ERROR_NETWORK;
    }/*w  w  w  .  j a  v a2 s  . co  m*/
    LOG.debug("captcha form detected via {}", http.getProxy() == null ? new DirectNoProxy() : http.getProxy());

    int status = http.get(captchaRedirect);
    if (status == 403) {
        return Status.ERROR_IP_BANNED;
    }

    if (solver == null) {
        return Status.ERROR_CAPTCHA_NO_SOLVER;
    }

    String content = http.getContentAsString();
    if (content == null) {
        return Status.ERROR_NETWORK;
    }

    String imageSrc = null;
    Document captchaDocument = Jsoup.parse(content, captchaRedirect);
    Elements elements = captchaDocument.getElementsByTag("img");
    for (Element element : elements) {
        String src = element.attr("abs:src");
        if (src != null && src.contains("/sorry/image")) {
            imageSrc = src;
        }
    }

    if (imageSrc == null) {
        LOG.debug("can't find captcha img tag");
        return Status.ERROR_NETWORK;
    }

    Element form = captchaDocument.getElementsByTag("form").first();
    if (form == null) {
        LOG.debug("can't find captcha form");
        return Status.ERROR_NETWORK;
    }

    String continueValue = null;
    String formIdValue = null;
    String formUrl = form.attr("abs:action");
    String formQValue = null;

    Element elementCaptchaId = form.getElementsByAttributeValue("name", "id").first();
    if (elementCaptchaId != null) {
        formIdValue = elementCaptchaId.attr("value");
    }
    Element elementContinue = form.getElementsByAttributeValue("name", "continue").first();
    if (elementContinue != null) {
        continueValue = elementContinue.attr("value");
    }
    Element elementQ = form.getElementsByAttributeValue("name", "q").first();
    if (elementQ != null) {
        formQValue = elementQ.attr("value");
    }

    if (formUrl == null || (formIdValue == null && formQValue == null) || continueValue == null) {
        LOG.debug("invalid captcha form");
        return Status.ERROR_NETWORK;
    }

    int imgStatus = http.get(imageSrc, captchaRedirect);
    if (imgStatus != 200 || http.getContent() == null) {
        LOG.debug("can't download captcha image {} (status code = {})", imageSrc, imgStatus);
        return Status.ERROR_NETWORK;
    }

    CaptchaImage captcha = new CaptchaImage(new byte[][] { http.getContent() });
    boolean solved = solver.solve(captcha);
    if (!solved || !Captcha.Status.SOLVED.equals(captcha.getStatus())) {
        LOG.error("solver can't resolve captcha (overload ?) error = {}", captcha.getError());
        return Status.ERROR_CAPTCHA_INCORRECT;
    }
    LOG.debug("got captcha response {} in {} seconds from {}", captcha.getResponse(),
            captcha.getSolveDuration() / 1000l,
            (captcha.getLastSolver() == null ? "?" : captcha.getLastSolver().getFriendlyName()));

    try {
        formUrl += "?continue=" + URLEncoder.encode(continueValue, "utf-8");
    } catch (Exception ex) {
    }
    formUrl += "&captcha=" + captcha.getResponse();

    if (formIdValue != null) {
        formUrl += "&id=" + formIdValue;
    }
    if (formQValue != null) {
        formUrl += "&q=" + formQValue;
    }

    int postCaptchaStatus = http.get(formUrl, captchaRedirect);

    if (postCaptchaStatus == 302) {
        String redirectOnSuccess = http.getResponseHeader("location");
        if (redirectOnSuccess.startsWith("http://")) {
            redirectOnSuccess = "https://" + redirectOnSuccess.substring(7);
        }

        int redirect1status = http.get(redirectOnSuccess, captchaRedirect);
        if (redirect1status == 200) {
            return Status.OK;
        }

        if (redirect1status == 302) {
            if (http.get(http.getResponseHeader("location"), captchaRedirect) == 200) {
                return Status.OK;
            }
        }
    }

    if (postCaptchaStatus == 503) {
        LOG.debug("reporting incorrect captcha (incorrect response = {})", captcha.getResponse());
        solver.reportIncorrect(captcha);
    }

    return Status.ERROR_CAPTCHA_INCORRECT;
}

From source file:com.danielme.muspyforandroid.services.MuspyClient.java

private String getCSRF() throws Exception {
    HttpGet httpGet = new HttpGet(Constants.URL_RESET);
    HttpResponse httpResponse = getDefaultHttpClient().execute(TARGETHOST, httpGet, getBasicHttpContext());
    String responseString = EntityUtils.toString(httpResponse.getEntity());
    Document doc = Jsoup.parse(responseString);
    Elements elementsByTag = doc.getElementsByTag("input");
    for (Element element : elementsByTag) {
        if ("csrfmiddlewaretoken".equals(element.attr("name"))) {
            return element.attr("value");
        }/*from   w  w  w  . j a  v a2 s . c om*/
    }
    throw new Exception("csrf not found");
}

From source file:com.aquest.emailmarketing.web.controllers.BroadcastTemplateController.java

/**
 * Adds the tracking.//from   w w w  . j  a  va2s  . c  o  m
 *
 * @param model the model
 * @param urls the urls
 * @param principal the principal
 * @param id the id
 * @param trackingFlg the tracking flg
 * @param openGAflg the open g aflg
 * @param openPixelFlg the open pixel flg
 * @param trackingType the tracking type
 * @return the string
 */
@RequestMapping(value = "/bcastTempGenerateUrls", method = RequestMethod.POST)
public String addTracking(Model model, Urls urls, Principal principal, @RequestParam(value = "id") int id,
        @RequestParam(value = "trackingFlg", required = false) boolean trackingFlg,
        @RequestParam(value = "openGAflg", required = false) boolean openGAflg,
        @RequestParam(value = "openPixelFlg", required = false) boolean openPixelFlg,
        @RequestParam(value = "trackingType", required = false) String trackingType) {
    TrackingConfig trackingConfig = new TrackingConfig();
    BroadcastTemplate broadcastTemplate = broadcastTemplateService.getBroadcastTemplateById(id);
    String workingHtml = broadcastTemplate.getHtmlbody();
    if (trackingFlg == true) {
        if (openGAflg == true) {
            workingHtml = emailTracking.addGaOpenEmailTracking(workingHtml, urls);
            System.out.println("GA Open: " + workingHtml);
        }
        if (openPixelFlg == true) {
            workingHtml = emailTracking.addPixelOpenEmailTracking(workingHtml);
            System.out.println("Pixel Open: " + workingHtml);
        }
        if (trackingType.equals("ga")) {
            workingHtml = emailTracking.addGaTrackingToUrl(workingHtml, urls);
            System.out.println("GA Click added: " + workingHtml);
        } else if (trackingType.equals("intTrack")) {
            workingHtml = emailTracking.addIntTrackingToUrl(workingHtml, urls);
            System.out.println("Internal Tracking: " + workingHtml);
        } else {
            workingHtml = emailTracking.addBothTrackingToUrl(workingHtml, urls);
        }

    }

    broadcastTemplate.setHtmlbody_tracking(workingHtml);
    System.out.println(broadcastTemplate.getHtmlbody_tracking());
    String confirm = broadcastTemplateService.SaveOrUpdate(broadcastTemplate);
    System.out.println(confirm);
    System.out.println(trackingFlg);
    System.out.println(openGAflg);
    System.out.println(openPixelFlg);
    System.out.println(trackingType);
    if (confirm == broadcastTemplate.getB_template_name()) {
        trackingConfig.setBcast_template_id(broadcastTemplate.getId());
        // taking care of tracking flg
        int tracking_flg = 0;
        if (trackingFlg == true) {
            tracking_flg = 1;
        }
        trackingConfig.setTracking_flg(tracking_flg);
        // taking care of openGAflg
        int open_ga_flg = 0;
        if (openGAflg == true) {
            open_ga_flg = 1;
        }
        trackingConfig.setOpen_ga_flg(open_ga_flg);
        // taking care of openPixelFlg
        int open_pixel_flg = 0;
        if (openPixelFlg == true) {
            open_pixel_flg = 1;
        }
        trackingConfig.setOpen_pixel_flg(open_pixel_flg);
        // set tracking type
        trackingConfig.setTracking_type(trackingType);
        // seting utm's
        trackingConfig.setUtm_campaign(urls.getUtmCampaign());
        trackingConfig.setUtm_content(urls.getUtmContent());
        trackingConfig.setUtm_medium(urls.getUtmMedium());
        trackingConfig.setUtm_source(urls.getUtmSource());
        trackingConfigService.SaveOrUpdate(trackingConfig);
    }
    // find images in html to be able to embed images in email as in-line attachments
    EmbeddedImage embeddedImage = new EmbeddedImage();
    List<String> imgList = new ArrayList<String>();
    String html = broadcastTemplate.getHtmlbody();
    Document doc = Jsoup.parse(html);
    Elements media = doc.select("[src]");
    for (Element src : media) {
        if (src.tagName().equals("img")) {
            imgList.add(src.attr("abs:src"));
        }
    }
    model.addAttribute("imgList", imgList);
    model.addAttribute("embeddedImage", embeddedImage);
    model.addAttribute("broadcastTemplate", broadcastTemplate);
    return "bcasttempembeddedimage";
}

From source file:org.bungeni.ext.integration.bungeniportal.BungeniServiceAccess.java

private List<BasicNameValuePair> getFormFieldSelectDefaultValues(Document doc, List<String> fieldNames) {
    List<BasicNameValuePair> nvp = new ArrayList<BasicNameValuePair>(0);
    for (String fieldName : fieldNames) {
        Elements inputItems = doc.select("[name=" + fieldName + "]");
        for (int i = 0; i < inputItems.size(); i++) {
            Element inputItem = inputItems.get(i);
            Elements selItems = inputItem.select("[selected=selected]");
            for (int j = 0; j < selItems.size(); j++) {
                Element selItem = selItems.get(j);
                nvp.add(new BasicNameValuePair(fieldName, selItem.attr("value")));
            }/* w ww  .j  a  v  a  2 s .co  m*/
        }
    }
    return nvp;
}

From source file:mobi.jenkinsci.ci.client.JenkinsClient.java

private Issue getIssueFromRow(final Element row) throws MalformedURLException {
    final Element fullChangeMessage = row.select("div[class=changeset-message]").first();
    if (fullChangeMessage == null) {
        return null;
    }// ww  w .  ja  v a 2 s. c  om

    final Element issueLink = fullChangeMessage.select("pre").first().select("a").first();
    if (issueLink == null) {
        return null;
    } else {
        final Element issueIcon = issueLink.select("img").first();
        return new Issue(getUrl(issueLink, "href"), issueLink.attr("tooltip"), getUrl(issueIcon, "src"));
    }
}

From source file:se.vgregion.portal.iframe.controller.CSViewController.java

private Element findButtonWithIdWhichStartsWith(Document doc, String pattern) {
    Elements buttonElements = doc.getElementsByTag("button");
    Iterator<Element> iterator = buttonElements.iterator();
    Element dynamicValue = null;//  ww w. j  a va2  s . c o m
    while (iterator.hasNext()) {
        Element next = iterator.next();
        String id = next.attr("id");
        if (id != null && id.startsWith(pattern)) {
            dynamicValue = next;
            break;
        }
    }
    return dynamicValue;
}

From source file:net.GoTicketing.GoTicketing.java

/**
 * ???/*from  ww w  .ja  va 2  s .c  o m*/
 * @throws Exception 
 */
private void praseFormActionSrc() throws Exception {
    Document doc = Jsoup.parse(TicketingPageHTML);
    Element form = doc.getElementsByTag("form").first();
    if (form == null)
        throw new Exception("Can't get form action source !");

    String src = form.attr("action");
    FormActionSrc = host + src.replace("/", "%2F");

    FormInputData = new TreeMap<>();
    for (Element elm : form.getElementsByTag("input")) {
        if (elm.attr("type").equals("hidden"))
            FormInputData.put(elm.attr("name"), elm.attr("value"));
    }
}

From source file:neembuu.release1.externalImpl.linkhandler.YoutubeLinkHandlerProvider.java

private BasicLinkHandler.Builder linkYoutubeExtraction(TrialLinkHandler tlh, int retryCount) throws Exception {
    String url = tlh.getReferenceLinkString();
    BasicLinkHandler.Builder linkHandlerBuilder = BasicLinkHandler.Builder.create();

    try {/*from  ww  w .j  a va2 s . co  m*/
        DefaultHttpClient httpClient = NHttpClient.getNewInstance();
        String requestUrl = "http://www.linkyoutube.com/watch/index.php?video="
                + URLEncoder.encode(url, "UTF-8");

        final String responseString = NHttpClientUtils.getData(requestUrl, httpClient);

        //Set the group name as the name of the video
        String nameOfVideo = getVideoName(url);

        String fileName = "text";

        linkHandlerBuilder.setGroupName(nameOfVideo);

        long c_duration = -1;

        Document doc = Jsoup.parse(responseString);

        Elements elements = doc.select("#download_links a");

        for (Element element : elements) {
            String singleUrl = element.attr("href");
            fileName = element.text();
            if (!singleUrl.equals("#")) {

                long length = NHttpClientUtils.calculateLength(singleUrl, httpClient);
                singleUrl = Utils.normalize(singleUrl);
                LOGGER.log(Level.INFO, "Normalized URL: " + singleUrl);

                if (length == 0) {
                    length = NHttpClientUtils.calculateLength(singleUrl, httpClient);
                }

                //LOGGER.log(Level.INFO,"Length: " + length);

                if (length <= 0) {
                    continue;
                    /*skip this url*/ }

                BasicOnlineFile.Builder fileBuilder = linkHandlerBuilder.createFile();

                try { // finding video/audio length
                    String dur = StringUtils.stringBetweenTwoStrings(singleUrl, "dur=", "&");
                    long duration = (int) (Double.parseDouble(dur) * 1000);
                    if (c_duration < 0) {
                        c_duration = duration;
                    }
                    fileBuilder.putLongPropertyValue(
                            PropertyProvider.LongProperty.MEDIA_DURATION_IN_MILLISECONDS, duration);
                    LOGGER.log(Level.INFO, "dur=" + dur);
                } catch (NumberFormatException a) {
                    // ignore
                }

                try { // finding the quality short name
                    String type = fileName.substring(fileName.indexOf("(") + 1);
                    type = type.substring(0, type.indexOf(")"));
                    fileBuilder.putStringPropertyValue(PropertyProvider.StringProperty.VARIANT_DESCRIPTION,
                            type);
                    LOGGER.log(Level.INFO, "type=" + type);
                } catch (Exception a) {
                    a.printStackTrace();
                }

                fileName = nameOfVideo + " " + fileName;

                fileBuilder.setName(fileName).setUrl(singleUrl).setSize(length).next();
            }
        }

        for (OnlineFile of : linkHandlerBuilder.getFiles()) {
            long dur = of.getPropertyProvider()
                    .getLongPropertyValue(PropertyProvider.LongProperty.MEDIA_DURATION_IN_MILLISECONDS);
            if (dur < 0 && c_duration > 0 && of.getPropertyProvider() instanceof BasicPropertyProvider) {
                ((BasicPropertyProvider) of.getPropertyProvider()).putLongPropertyValue(
                        PropertyProvider.LongProperty.MEDIA_DURATION_IN_MILLISECONDS, c_duration);
            }
        }

    } catch (Exception ex) {
        int retryLimit = ((YT_TLH) tlh).retryLimit;
        ex.printStackTrace();
        LOGGER.log(Level.INFO, "retry no. = " + retryCount);
        if (retryCount > retryLimit)
            throw ex;
        return linkYoutubeExtraction(tlh, retryCount + 1);
    }

    return linkHandlerBuilder;
}

From source file:com.app.rest.ExperianIntegrationService.java

@POST
@Path("/landingPageSubmit")
@Produces({ MediaType.APPLICATION_JSON })
@Consumes(MediaType.APPLICATION_JSON)/*from ww w .j av  a2  s .com*/
public ResponseModel getlandingPageDetails(String inputJsonObj) {

    //BasicConfigurator.configure();
    String logMarker = null;
    ResponseModel responseMap = new ResponseModel();
    try {

        //String requestParams = (String) inputJsonObj.get("input");
        Map map = parseJson(inputJsonObj);
        logger.info("getlandingPageDetails  ~ " + map.get("LOG_MARKER") == null ? "NOT_GIVEN"
                : map.get("LOG_MARKER") + " ~Entry");
        logMarker = map.get("LOG_MARKER").toString();
        //String voucherCode = "CMD1UjUz9";

        if (map.get("clientName").toString() == null) {
            responseMap.setErrorMessage("Client Name is blank");
            return responseMap;
        }

        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("clientName", map.get("clientName").toString()));
        params.add(new BasicNameValuePair("allowInput", map.get("allowInput").toString()));
        params.add(new BasicNameValuePair("allowEdit", map.get("allowEdit").toString()));
        params.add(new BasicNameValuePair("allowCaptcha", map.get("allowCaptcha").toString()));
        params.add(new BasicNameValuePair("allowConsent", map.get("allowConsent").toString()));
        params.add(new BasicNameValuePair("allowConsent_additional",
                map.get("allowConsent_additional").toString()));
        params.add(new BasicNameValuePair("allowEmailVerify", map.get("allowEmailVerify").toString()));
        params.add(new BasicNameValuePair("allowVoucher", map.get("allowVoucher").toString()));
        params.add(new BasicNameValuePair("voucherCode", map.get("voucherCode").toString()));
        params.add(new BasicNameValuePair("firstName", map.get("firstName").toString()));
        params.add(new BasicNameValuePair("surname", map.get("surName").toString()));
        params.add(new BasicNameValuePair("dateOfBirth", map.get("dateOfBirth").toString()));
        params.add(new BasicNameValuePair("gender", map.get("gender").toString()));
        params.add(new BasicNameValuePair("mobileNo", map.get("mobileNo").toString()));
        params.add(new BasicNameValuePair("email", map.get("email").toString()));
        params.add(new BasicNameValuePair("flatno", map.get("flatno").toString()));
        params.add(new BasicNameValuePair("city", map.get("city").toString()));
        params.add(new BasicNameValuePair("state", map.get("state").toString()));
        params.add(new BasicNameValuePair("pincode", map.get("pincode").toString()));
        params.add(new BasicNameValuePair("pan", map.get("pan").toString()));
        params.add(new BasicNameValuePair("reason", map.get("reason").toString()));
        params.add(new BasicNameValuePair("middleName", map.get("middleName").toString()));
        params.add(new BasicNameValuePair("telephoneNo", map.get("telephoneNo").toString()));
        params.add(new BasicNameValuePair("telephoneType", map.get("telephoneType").toString()));
        params.add(new BasicNameValuePair("passport", map.get("passport").toString()));
        params.add(new BasicNameValuePair("voterid", map.get("voterid").toString()));
        params.add(new BasicNameValuePair("aadhaar", map.get("aadhaar").toString()));
        params.add(new BasicNameValuePair("driverlicense", map.get("driverlicense").toString()));
        String request = getQuery(params);

        String jsessionId = HttpConnection.landingPageSubmit(request);

        String stageOneRequestId = HttpConnection.openCustomerDetailsFormAction(jsessionId, "");

        responseMap.setuniqueId(stageOneRequestId.toString());

        logger.info("getlandingPageDetails  ~ "
                + (map.get("LOG_MARKER") == null ? "NOT_GIVEN" : map.get("LOG_MARKER")) + " ~ request : "
                + (request == null ? "null" : request) + " jsessionId: "
                + (jsessionId == null ? "null" : jsessionId) + " stageOneRequestId: "
                + (stageOneRequestId == null ? "null" : stageOneRequestId) + "~ Log Marker 1");
        params.clear();

        params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("clientName", map.get("clientName").toString()));
        params.add(new BasicNameValuePair("allowInput", map.get("allowInput").toString()));
        params.add(new BasicNameValuePair("allowEdit", map.get("allowEdit").toString()));
        params.add(new BasicNameValuePair("allowCaptcha", map.get("allowCaptcha").toString()));
        params.add(new BasicNameValuePair("allowConsent", map.get("allowConsent").toString()));
        params.add(new BasicNameValuePair("allowConsent_additional",
                map.get("allowConsent_additional").toString()));
        params.add(new BasicNameValuePair("allowEmailVerify", map.get("allowEmailVerify").toString()));
        params.add(new BasicNameValuePair("allowVoucher", map.get("allowVoucher").toString()));
        params.add(new BasicNameValuePair("voucherCode", map.get("voucherCode").toString()));
        params.add(new BasicNameValuePair("firstName", map.get("firstName").toString()));
        params.add(new BasicNameValuePair("surname", map.get("surName").toString()));
        params.add(new BasicNameValuePair("dob", map.get("dateOfBirth").toString()));
        params.add(new BasicNameValuePair("gender", map.get("gender").toString()));
        params.add(new BasicNameValuePair("mobileNo", map.get("mobileNo").toString()));
        params.add(new BasicNameValuePair("email", map.get("email").toString()));
        params.add(new BasicNameValuePair("flatPlotHouseNo", map.get("flatno").toString()));
        params.add(new BasicNameValuePair("city", map.get("city").toString()));
        params.add(new BasicNameValuePair("state", map.get("stateid").toString()));
        params.add(new BasicNameValuePair("pincode", map.get("pincode").toString()));
        params.add(new BasicNameValuePair("panNo", map.get("pan").toString()));
        params.add(new BasicNameValuePair("reason", map.get("reason").toString()));
        params.add(new BasicNameValuePair("requestReason", map.get("reason").toString()));
        params.add(new BasicNameValuePair("middleName", map.get("middleName").toString()));
        params.add(new BasicNameValuePair("telephoneNo", map.get("telephoneNo").toString()));
        params.add(new BasicNameValuePair("telephoneType", map.get("telephoneType").toString()));
        params.add(new BasicNameValuePair("passportNo", map.get("passport").toString()));
        params.add(new BasicNameValuePair("voterIdNo", map.get("voterid").toString()));
        params.add(new BasicNameValuePair("universalIdNo", map.get("aadhaar").toString()));
        params.add(new BasicNameValuePair("driverLicenseNo", map.get("driverlicense").toString()));
        params.add(new BasicNameValuePair("hitId", stageOneRequestId));
        request = getQuery(params);

        logger.info("getlandingPageDetails  ~ "
                + (map.get("LOG_MARKER") == null ? "NOT_GIVEN" : map.get("LOG_MARKER")) + " ~ request : "
                + (request == null ? "null" : request) + " jsessionId: "
                + (jsessionId == null ? "null" : jsessionId) + " stageOneRequestId: "
                + (stageOneRequestId == null ? "null" : stageOneRequestId) + "~ Log Marker 2");

        HttpConnection.fetchScreenMetaDataAction(jsessionId, request);

        String resp = HttpConnection.submitRequest(jsessionId, request);

        logger.info("getlandingPageDetails  ~ "
                + (map.get("LOG_MARKER") == null ? "NOT_GIVEN" : map.get("LOG_MARKER")) + " ~ request : "
                + (request == null ? "null" : request) + " jsessionId: "
                + (jsessionId == null ? "null" : jsessionId) + " stageOneRequestId: "
                + (stageOneRequestId == null ? "null" : stageOneRequestId) + " resp: "
                + (resp == null ? "null" : resp) + "~ Log Marker 4");

        if (resp == null) {
            responseMap.setErrorMessage("RESPONSE_NULL");
            return responseMap;
        }

        if (resp.equals("")) {
            responseMap.setErrorMessage("RESPONSE_BLANK");
            return responseMap;
        }

        if (resp.startsWith("error")) {
            responseMap.setErrorMessage(resp.replace("error ", ""));
            return responseMap;
        }

        params.clear();

        String stageTwoRequestId = HttpConnection.directCRQRequest(resp, jsessionId, params);

        logger.info("getlandingPageDetails  ~ "
                + (map.get("LOG_MARKER") == null ? "NOT_GIVEN" : map.get("LOG_MARKER")) + " ~ request : "
                + (request == null ? "null" : request) + " jsessionId: "
                + (jsessionId == null ? "null" : jsessionId) + " stageOneRequestId: "
                + (stageOneRequestId == null ? "null" : stageOneRequestId) + " stageTwoRequestId: "
                + (stageTwoRequestId == null ? "null" : stageTwoRequestId) + "~ Log Marker 5");

        params.add(new BasicNameValuePair("captchCode", "-999"));
        params.add(new BasicNameValuePair("payFlag", "true"));
        params.add(new BasicNameValuePair("voucherCode", map.get("voucherCode").toString()));
        params.add(new BasicNameValuePair("stgOneHitId", stageOneRequestId));
        params.add(new BasicNameValuePair("stgTwoHitId", stageTwoRequestId));
        request = getQuery(params);

        String jsessionIdResp = HttpConnection.paymentSubmitRequest(request);

        logger.info("getlandingPageDetails  ~ "
                + (map.get("LOG_MARKER") == null ? "NOT_GIVEN" : map.get("LOG_MARKER")) + " ~ request : "
                + (request == null ? "null" : request) + " jsessionId: "
                + (jsessionId == null ? "null" : jsessionId) + " stageOneRequestId:  "
                + (stageOneRequestId == null ? "null" : stageOneRequestId) + " stageTwoRequestId: "
                + (stageTwoRequestId == null ? "null" : stageTwoRequestId) + " jsessionIdResp: "
                + (jsessionIdResp == null ? "null" : jsessionIdResp) + "~ Log Marker 6");

        if (jsessionIdResp.equalsIgnoreCase("customError")) {
            responseMap.setErrorMessage(jsessionIdResp);
            logger.info("getlandingPageDetails  ~ "
                    + (map.get("LOG_MARKER") == null ? "NOT_GIVEN" : map.get("LOG_MARKER"))
                    + "~ customError ~ Log Marker 6");
            return responseMap;
        }

        if (jsessionIdResp.equalsIgnoreCase("Invalid Voucher Code")) {
            responseMap.setErrorMessage("voucherExpired");
            logger.info("getlandingPageDetails  ~ "
                    + (map.get("LOG_MARKER") == null ? "NOT_GIVEN" : map.get("LOG_MARKER"))
                    + "~ voucherExpired ~ Log Marker 6");
            return responseMap;
        }
        String responseJson = null;

        String message = "";
        String answer = "";
        String qId = "";

        while (true) {
            logger.info("getlandingPageDetails  ~ "
                    + (map.get("LOG_MARKER") == null ? "NOT_GIVEN" : map.get("LOG_MARKER")) + "~ Log Marker 6");
            params.clear();
            params = new ArrayList<NameValuePair>();

            params.add(new BasicNameValuePair("stgOneHitId", stageOneRequestId));
            params.add(new BasicNameValuePair("stgTwoHitId", stageTwoRequestId));
            request = getQuery(params);

            Map questionMap = HttpConnection.generateQuestionForConsumer(jsessionIdResp, request);

            responseJson = (String) questionMap.get("responseJson");
            logger.info("getlandingPageDetails  ~ "
                    + (map.get("LOG_MARKER") == null ? "NOT_GIVEN" : map.get("LOG_MARKER")) + " ~ request : "
                    + (request == null ? "null" : request) + " jsessionId: "
                    + (jsessionId == null ? "null" : jsessionId) + " stageOneRequestId: "
                    + (stageOneRequestId == null ? "null" : stageOneRequestId) + " stageTwoRequestId: "
                    + (stageTwoRequestId == null ? "null" : stageTwoRequestId) + " responseJson: "
                    + (responseJson == null ? "null" : responseJson) + "~ Log Marker 7");

            if (responseJson.equalsIgnoreCase("passedReport")) {
                String pdfData = (String) questionMap.get("showHtmlReportForCreditReport");
                Document doc = Jsoup.parse(pdfData);
                Element input = doc.select("input[name=xmlResponse]").first();
                String response = input.attr("value");
                responseMap.setXmlResponse(response);
            }

            if (responseJson.equalsIgnoreCase("next")) {
                questionMap.put("jsessionId2", jsessionIdResp);
                responseMap.setResponseMap(questionMap);
            }

            if (responseJson.equalsIgnoreCase("systemError")) {
                responseMap.setErrorMessage("systemError");
            }

            if (responseJson.equalsIgnoreCase("inCorrectAnswersGiven")) {
                responseMap.setErrorMessage("inCorrectAnswersGiven");
            }

            if (responseJson.equalsIgnoreCase("insufficientQuestion")) {
                responseMap.setErrorMessage("insufficientQuestion");
            }

            if (responseJson.equalsIgnoreCase("creditReportEmpty")) {
                responseMap.setErrorMessage("creditReportEmpty");
            }
            if (responseJson.equalsIgnoreCase("error")) {
                responseMap.setErrorMessage("error");
            }

            return responseMap;
        }

    } catch (Exception e) {
        logger.info("getlandingPageDetails  ~ " + (logMarker == null ? "NOT_GIVEN" : logMarker) + e.toString()
                + "~ Log Marker 8 ");

        responseMap.setErrorMessage("Error occured");
        responseMap.setExceptionString(e.toString());
        return responseMap;
    }
}