如何使用Java用户定义的类在Pentaho上解决“导入的类” org.apache.http.HttpResponse”无法加载的问题

时间:2019-04-09 05:49:36

标签: pentaho httpresponse

我必须使用Pentaho将PDF文件发送到API。我使用了“ Java用户定义的类”来获取PDF文件并将其发送到API。所有这些都是使用HttpPost方法完成的,并将其作为Content_Type进行多部分处理。 但是我收到错误消息“ 无法加载导入的类“ org.apache.http.HttpResponse” “。在此之前,我还遇到了有关httpClient的错误,但是当我将httpclient jar文件复制到Pentaho / Java / lib / ext时,此问题已解决。现在,我无法在任何地方找到httpResponse jar文件。

请帮助...

谢谢

import java.io.File;

import org.apache.http.HttpResponse;     // This line Produces error

import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.*;
import org.apache.http.impl.client.HttpClients;

public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException
{
 Object[] r = getRow();

    if (r == null) {
        setOutputDone();
        return false;
    }

 r = createOutputRow(r, data.outputRowMeta.size());

  // Get the value from url
    String urlString = get(Fields.In, "url").getString(r);
 // Get the file name 
 String longFileNameString = get(Fields.In, "filename").getString(r);
 // Load the file
 File file = new File(attachmentFilePath);

 HttpPost post = new HttpPost(urlString);
 MultipartEntityBuilder entity = MultipartEntityBuilder.create();
 entity.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
 entity.addBinaryBody("file", file);
 entity.addTextBody("fileName", file.getName());
 post.setEntity(entity.build());

 HttpClient httpClient = HttpClients.createDefault();

 try{ 
  //Make HTTP Call 
  HttpResponse response = httpClient.execute(post);
  // Check if response code is as expected
  if (response.getStatusLine().getStatusCode() != 200) {
   putError(data.outputRowMeta, r, 1, "Error returned", "HTTP Status Code", "HTTP Status: " + response.getStatusLine().getStatusCode());
   return true;
  } 
  // Set value of HTTP Status, integer values need conversion
  get(Fields.Out, "http_status").setValue(r,  Long.valueOf(response.getStatusLine().getStatusCode()));
 } catch (Exception e) {
  // Set value of HTTP Status to -1 since HTTP Post caused exception
  get(Fields.Out, "http_status").setValue(r,  Long.valueOf(-1));
  return true;
 }

 // Send the row on to the next step.
    putRow(data.outputRowMeta, r);

 return true;
}

0 个答案:

没有答案