Pessoal, seguinte:
eu tenho uma aplicação que tem q acessar um “servidor” para atualizar uns dados…então eu fiz o seguinte método:
public static String insertProcedimento(String cnpj, String[] params) throws UnsupportedEncodingException{
String hash = UtilString.md5(...);
String url = "http://url?caso=insertProcedimento&cnpj="+cnpj+"&hash="+hash+"¶ms="+params[0]+";"+params[1]+";"+params[2]+";"+params[3]+";"+params[4]+";"+params[5]+";"+params[6]+";"+params[7]+";"+params[8]+";"+params[9]+";"+params[10]+";"+params[11]+";"+params[12]+";"+params[13]+";"+params[14]+";"+params[15]+";";
// Create an instance of HttpClient.
MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
HttpClient client = new HttpClient(connectionManager);
// Create a method instance.
PostMethod method = new PostMethod(url);
method.setParameter("hash", hash);
method.setParameter("cnpj", cnpj);
method.setParameter("params", params[0]+";"+params[1]+";"+params[2]+";"+params[3]+";"+params[4]+";"+params[5]+";"+params[6]+";"+params[7]+";"+params[8]+";"+params[9]+";"+params[10]+";"+params[11]+";"+params[12]+";"+params[13]+";"+params[14]+";"+params[15]+";");
// Provide custom retry handler is necessary
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false));
byte[] responseBody = null;
try {
// Execute the method.
int statusCode = client.executeMethod(method);
if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: " + method.getStatusLine());
}
// Read the response body.
responseBody = method.getResponseBody();
// Deal with the response.
// Use caution: ensure correct character encoding and is not binary data
} catch (HttpException e) {
System.err.println("Fatal protocol violation: " + e.getMessage());
e.printStackTrace();
} catch (IOException e) {
System.err.println("Fatal transport error: " + e.getMessage());
e.printStackTrace();
} finally {
// Release the connection.
method.releaseConnection();
}
return new String(responseBody);
}
Problema: se eu rodo essa aplicação via Eclipse, ela funciona perfeitamente.
Ai eu criei uma aplicação WEB com struts. Quando eu rodo, dá o seguinte erro:
org.apache.commons.httpclient.HttpMethodBase.(HttpMethodBase.java:222)
org.apache.commons.httpclient.methods.ExpectContinueMethod.(ExpectContinueMethod.java:93)
org.apache.commons.httpclient.methods.EntityEnclosingMethod.(EntityEnclosingMethod.java:119)
org.apache.commons.httpclient.methods.PostMethod.(PostMethod.java:106)
br.com.oside.AdminSaudePro.osidehttpclient.OsideHttpClient.insertProcedimento(Unknown Source)
br.com.oside.AdminSaudePro.service.ServiceProcedimentos.rodarProcedimentosRemotos(Unknown Source)
br.com.oside.AdminSaudePro.service.ServiceProcedimentos.rodarProcedimentosComeco(Unknown Source)
br.com.oside.adminweb.model.LancaProcedimento.run(Unknown Source)
br.com.oside.adminweb.action.RelatorioAction.execute(Unknown Source)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
java.lang.Thread.run(Unknown Source)
De acordo com os meus testes, ele dá erro nesta linha : PostMethod method = new PostMethod(url);
Alguém tem idéia do que poderia ser esse erro ??
vlw
abraços