java - Can I use htmlunit in a web service? -


i've been trying use htmlunit inside web service function. new web services , used tutorial implementing simple web service: http://www.eclipse.org/webtools/community/education/web/t320/implementing_a_simple_web_service.pdf

then tried implement web service 3 strings parameters, go web site using htmlunit, fill forms in site 3 strings , click on search button, parse result page , return string containing information result page. went naive approach , tried implement web service using same steps tutorial used. steps were:

  1. create dynamic web project
  2. add htmlunit jar's build path.
  3. implement working junit test function , add project
  4. create web server , client using web service wizard of eclipse.

after that, wizard generated simple interface 3 textboxes , entered values worked in junit test project. got exception said:

exception: java.lang.reflect.invocationtargetexception message: java.lang.reflect.invocationtargetexception 

since new web services did make horrible mistake when thought steps simple web service in tutorial work or error can fixed? in general can use htmlunit in way or impossible?

the code webserver below:

package webservice.test.travelcomparing;  import java.io.bufferedwriter; import java.io.fileoutputstream; import java.io.outputstreamwriter; import java.io.writer;  import com.gargoylesoftware.htmlunit.webclient; import com.gargoylesoftware.htmlunit.html.htmlpage;  public class travelcomparingtest {  public string homepage(string place, string checkindate, string checkoutdate) throws exception {     final webclient webclient = new webclient();  string url = "http://hotels.travelcomparing.com/searchresults.aspx?languagecode=en&currencycode=eur&destination=place:" + place + "&radius=0km&checkin=" + checkindate +"&checkout=" + checkoutdate + "&rooms=1&adults_1=1&pagesize=15&pageindex=0&sort=minrate-asc&showsoldout=false&view=hc_sr_summary&scroll=0&mapstate=contracted";  htmlpage page = webclient.getpage(url); webclient.waitforbackgroundjavascript(10000); string htmlcontent = page.asxml(); writer out = new bufferedwriter(new outputstreamwriter(         new fileoutputstream("travelcomparing.html"), "utf-8"));     try {         out.write(htmlcontent);     } {         out.close();     }      string hotelname = "";     string pricefrom = "";      string result = "";      (int = 0; < 5; i++){          int index1 = htmlcontent.indexof ( "<div fn=");         int index2 = htmlcontent.indexof("<div fn=", index1 + 8);         string row = (string) htmlcontent.subsequence(index1 , index2);         htmlcontent = htmlcontent.substring(index2);         //system.out.println(row);          int index3 = row.indexof("class=\"hc_i_hotel\" p=\"2\">");         int index4 = row.indexof("</a>", index3);         hotelname = (string) row.subsequence(index3 + 61, index4 -34);         system.out.println(hotelname);         result = result + hotelname + " ";          int index5 = row.indexof("<dd class=\"hc_i_price\">");         int index6 = row.indexof("</dd>", index5);         string pricerow = (string) row.subsequence(index5, index6 + 5);          int index7 = pricerow.indexof("<span class=\"hc_pr_syb\">");         int index8 = pricerow.indexof("<span class=\"hc_pr_cur\">");         pricefrom = (string) pricerow.subsequence(index7 + 148, index8 - 38);         system.out.println(pricefrom);         result = result + pricefrom + "    ";     }     return result; }  } 

edit:

the full contents of tomcat console below. exception mentioned displayed in result view of client , couldn't find anywhere else.

may 20, 2013 7:17:15 org.apache.catalina.core.aprlifecyclelistener init info: apr based apache tomcat native library allows optimal performance in production environments not found on java.library.path: c:\program files\java\jre7\bin;c:\windows\sun\java\bin;c:\windows\system32;c:\windows;c:/program files/java/jre7/bin/client;c:/program files/java/jre7/bin;c:/program files/java/jre7/lib/i386;c:\windows\system32;c:\windows;c:\windows\system32\wbem;c:\windows\system32\windowspowershell\v1.0\;c:\program files\microsoft sql server\100\tools\binn\;c:\program files\microsoft sql server\100\dts\binn\;c:\program files\quicktime\qtsystem\;c:\program files\microsoft\web platform installer\;c:\program files\microsoft asp.net\asp.net web pages\v1.0\;c:\program files\windows kits\8.0\windows performance toolkit\;c:\program files\microsoft sql server\110\tools\binn\;c:\eclipse;;. may 20, 2013 7:17:15 org.apache.tomcat.util.digester.setpropertiesrule begin warning: [setpropertiesrule]{server/service/engine/host/context} setting property 'source' 'org.eclipse.jst.jee.server:travelcomparingtest' did not find matching property. may 20, 2013 7:17:15 org.apache.tomcat.util.digester.setpropertiesrule begin warning: [setpropertiesrule]{server/service/engine/host/context} setting property 'source' 'org.eclipse.jst.jee.server:travelcomparingtestclient' did not find matching property. may 20, 2013 7:17:15 org.apache.tomcat.util.digester.setpropertiesrule begin warning: [setpropertiesrule]{server/service/engine/host/context} setting property 'source' 'org.eclipse.jst.jee.server:travelcomparing2' did not find matching property. may 20, 2013 7:17:15 org.apache.tomcat.util.digester.setpropertiesrule begin warning: [setpropertiesrule]{server/service/engine/host/context} setting property 'source' 'org.eclipse.jst.jee.server:travelcomparing2client' did not find matching property. may 20, 2013 7:17:15 org.apache.tomcat.util.digester.setpropertiesrule begin warning: [setpropertiesrule]{server/service/engine/host/context} setting property 'source' 'org.eclipse.jst.jee.server:traveltest' did not find matching property. may 20, 2013 7:17:15 org.apache.tomcat.util.digester.setpropertiesrule begin warning: [setpropertiesrule]{server/service/engine/host/context} setting property 'source' 'org.eclipse.jst.jee.server:traveltestclient' did not find matching property. may 20, 2013 7:17:15 org.apache.coyote.abstractprotocol init info: initializing protocolhandler ["http-bio-8080"] may 20, 2013 7:17:15 org.apache.coyote.abstractprotocol init info: initializing protocolhandler ["ajp-bio-8009"] may 20, 2013 7:17:15 org.apache.catalina.startup.catalina load info: initialization processed in 410 ms may 20, 2013 7:17:15 org.apache.catalina.core.standardservice startinternal info: starting service catalina may 20, 2013 7:17:15 org.apache.catalina.core.standardengine startinternal info: starting servlet engine: apache tomcat/7.0.40 may 20, 2013 7:17:16 org.apache.axis.utils.javautils isattachmentsupported warning: unable find required classes (javax.activation.datahandler , javax.mail.internet.mimemultipart). attachment support disabled. may 20, 2013 7:17:17 org.apache.axis.utils.javautils isattachmentsupported warning: unable find required classes (javax.activation.datahandler , javax.mail.internet.mimemultipart). attachment support disabled. may 20, 2013 7:17:17 org.apache.axis.utils.javautils isattachmentsupported warning: unable find required classes (javax.activation.datahandler , javax.mail.internet.mimemultipart). attachment support disabled. may 20, 2013 7:17:17 org.apache.coyote.abstractprotocol start info: starting protocolhandler ["http-bio-8080"] may 20, 2013 7:17:17 org.apache.coyote.abstractprotocol start info: starting protocolhandler ["ajp-bio-8009"] may 20, 2013 7:17:17 org.apache.catalina.startup.catalina start info: server startup in 2044 ms may 20, 2013 7:17:19 org.apache.axis.utils.javautils isattachmentsupported warning: unable find required classes (javax.activation.datahandler , javax.mail.internet.mimemultipart). attachment support disabled. 

i solved issue deleting file writing code , surrounding necessary fields try catch block. reason exception thrown appears io exception thrown in function, when reflect used, shows exception in question instead of io exception.


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -