Using HttpClient inside JSF action method.
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Andrzej_Folga
Posted On:   Wednesday, December 5, 2007 05:55 AM

Configuration: jboss 4.2.0 GA, MyFaces 1.5.0. I`m trying to call executeMethod(GetMethod) on my HttpClient class to receive xml file and then parse it using JAXB. The exception i`m recieving is: 11:36:12,859 ERROR [[Faces Servlet]] Servlet.service() for servlet Faces Servlet threw exception javax.servlet.ServletException: Exception while invoking expression #{Task.save} at javax.faces.webapp.FacesServlet.service(FacesServlet.java:154) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at com.bluemedia.topupInvoice.util.CharacterEncodingFilter.doFi   More>>

Configuration: jboss 4.2.0 GA, MyFaces 1.5.0.

I`m trying to call executeMethod(GetMethod) on my HttpClient class to receive xml file and then parse it using JAXB. The exception i`m recieving is:


11:36:12,859 ERROR [[Faces Servlet]] Servlet.service() for servlet Faces Servlet threw exception
javax.servlet.ServletException: Exception while invoking expression #{Task.save}
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:154)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.bluemedia.topupInvoice.util.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:46)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:147)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:525)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:595)



My action method code is:
			
public void save() throws NamingException, IOException, JAXBException {

Invoice invoice;

HttpClient httpClient = new HttpClient();

httpClient.getState().setCredentials(
new AuthScope(Common.TOPUP_REPORT_URL,Common.TOPUP_REPORT_PORT),
new UsernamePasswordCredentials(Common.TOPUP_REPORT_USERNAME, Common.TOPUP_REPORT_PASSWORD)
);

GetMethod method = new GetMethod("http://"+ Common.TOPUP_REPORT_URL + "files/example.xml");
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler(3, false));

method.setDoAuthentication( true );

try {
// Execute the method.
int statusCode = httpClient.executeMethod(method);

if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: " + method.getStatusLine());
}

String xmlString = method.getResponseBodyAsString();
DocumentFactory idf = new DocumentFactory();
invoice = (Invoice) idf.unmarshal(xmlString);
}
finally {
// Release the connection.
method.releaseConnection();
}

return "saveTask";
}
   <<Less
About | Sitemap | Contact