java compile error Set/HtmlUnit question

T

tom

i've got a test app that i'm trying to get to compile. it deals with
the htmlunit lib. new to java, and as far as i can tell, the issue
seems to be some kind of conflict between the httpunit, and htmlunit
Cookie defs...

any help/pointerst regarding the cookie/list issue would be helpful...

thanks



here's the compile cmd/return errs....
============================================
javac -classpath '/opt/htmlunit/lib/*:/parseapp2/' sj_registrar.java

sj_registrar.java:57: incompatible types
found : java.util.Set<com.gargoylesoftware.htmlunit.util.Cookie>
required: java.util.Set<org.apache.commons.httpclient.Cookie>
Set<org.apache.commons.httpclient.Cookie> cookies =
webClient.getCookieManager().getCookies();

^
1 error



here's the test code:
==================
/*
// chunk to test the htmlunit process for extracting data from
// dynamic/javascript sites...
//
//
//877-633-8870
*/

//package com.examples.htmlunit;
//package parseapp2;

import java.io.IOException;
import java.net.URL;
import java.util.List;
import java.util.Set;

import org.apache.commons.httpclient.Cookie;

import com.gargoylesoftware.htmlunit.CookieManager;
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.RefreshHandler;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlTable;
import com.gargoylesoftware.htmlunit.html.HtmlTableRow;

public class sj_registrar {

public static void main(String[] args) throws Exception {

// Create and initialize WebClient object
// WebClient webClient = new WebClient
(BrowserVersion.EXPLORER_7);
WebClient webClient = new WebClient
(BrowserVersion.FIREFOX_3);
//WebClient webClient = new WebClient();
webClient.setThrowExceptionOnScriptError(false);
webClient.setRefreshHandler(new RefreshHandler() {
public void handleRefresh(Page page, URL url,
int arg) throws IOException {
//System.out.println("handleRefresh");
}

});

// visit Yahoo Mail login page and get the Form object
String url;
//url="http://apps.oti.fsu.edu/RegistrarCourseLookup/
SearchForm";
url="https://cmshr.sjsu.edu/psc/HSJPRDF/EMPLOYEE/
HSJPRD/c/COMMUNITY_ACCESS.CLASS_SEARCH.GBL?
FolderPath=PORTAL_ROOT_OBJECT.PA_HC_CLASS_SEARCH&amp;PortalActualURL=https
%3a%2f%2fcmshr.sjsu.edu%2fpsc%2fHSJPRDF%2fEMPLOYEE%2fHSJPRD%2fc
%2fCOMMUNITY_ACCESS.CLASS_SEARCH.GBL&amp;PortalRegistryName=EMPLOYEE&amp;PortalServletURI=https
%3a%2f%2fcmshr.sjsu.edu%2fpsp%2fHSJPRDF%2f&amp;PortalURI=https%3a%2f
%2fcmshr.sjsu.edu%2fpsc%2fHSJPRDF
%2f&amp;PortalHostNode=HRMS&amp;NoCrumbs=yes";
//HtmlPage page = (HtmlPage)
webClient.getPage("https://login.yahoo.com/config/
login_verify2?.intl=us&.src=ym");
HtmlPage page = (HtmlPage) webClient.getPage(url);

//HtmlPage foo = page.getContentAsString();
//Set<Cookie> cookies = webClient.getCookieManager
().getCookies();
Set<org.apache.commons.httpclient.Cookie> cookies =
webClient.getCookieManager().getCookies();

BLOWING UP HERE!!!!
//cookies = webclient.getCookieManager().getCookies;
// try{
// }
// catch(ScriptException e){}

System.out.println("here \n"); //disply the text/content of
the page
//Set<Cookie> cookies = wb.getCookieManager().getCookies();
String strCookie = "";

for(Cookie c : cookies){
strCookie +=c.getName()+"="+c.getValue()+";";
}
System.out.println(strCookie); //disply the text/content of
the page

String foo1 = page.getWebResponse().getContentAsString
();
System.out.println(foo1); //disply the text/content of the
page
System.exit(0);


// System.out.println("\n\n\n"); //disply the text/content of
the page
HtmlForm form = page.getFormByName("searchForm");
//String foo2 = form.getContentAsString();
String foo2 = form.asText();
// System.out.println(foo2); //disply the text/content of the
page
// System.out.println("qqqqqqqqq \n\n"); //disply the
text/content of the page

//set the term
String termval="20101";
form.getSelectByName("term").setSelectedAttribute
(termval,true);
foo2=form.getSelectByName("term").asXml();
// System.out.println(foo2); //disply the text/content of the
page
webClient.waitForBackgroundJavaScript(25);
// page.wait(1000);
foo2=form.getSelectByName("department").asXml();
// System.out.println(foo2); //disply the text/content of the
page
// System.out.println("\n\n\n\n\n\n"); //disply the
text/content of the page
// foo1 = page.getWebResponse().getContentAsString();
foo1 = page.asXml();
System.out.println(foo1); //disply the text/content of the
page
}
}
 
T

tom

Looks like your cookie manager class (which you failed to include) is
returning a java.util.Set<com.gargoylesoftware.htmlunit.util.Cookie>,
while the code you posted requires a
java.util.Set<org.apache.commons.httpclient.Cookie>.

Either change the variable type so it matches the return value, or
change the return value so that it matches the variable type.

By the way, you should have posted a SSCCE.  And in a SSCCE, if you've
commented out a line of code, it almost always doesn't belong in the SSCCE.

Pete

hi pete...

untill 5 mins ago.. i had no idea what a SSCCE was!! but it makes
sense.. i'l keeo it in mind.


as for the example, it's a compilation of a few different apps from
different emails from the web. the section of code that deals with the
"Set<...>" cookie... was from one of the emails.. there's no guarantee
that it would work.. there's no other classes to be imported in the
examples that i've seen.

to be honest, i can't find a working example of this method/class from
all the chunks of code that i've seen...

thanks for your comments!

tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top