Пример #1
0
  private JobInfo createOrUpdateJob(JobInfo job, String endpoint) throws AsyncApiException {
    try {
      Transport transport = config.createTransport();
      OutputStream out = transport.connect(endpoint, getHeaders(XML_CONTENT_TYPE), true);
      XmlOutputStream xout = new AsyncXmlOutputStream(out, true);
      job.write(JOB_QNAME, xout, typeMapper);
      xout.close();

      InputStream in = transport.getContent();

      if (transport.isSuccessful()) {
        XmlInputStream xin = new XmlInputStream();
        xin.setInput(in, "UTF-8");
        JobInfo result = new JobInfo();
        result.load(xin, typeMapper);
        return result;
      } else {
        parseAndThrowException(in);
      }
    } catch (PullParserException e) {
      throw new AsyncApiException("Failed to create job ", AsyncExceptionCode.ClientInputError, e);
    } catch (IOException e) {
      throw new AsyncApiException("Failed to create job ", AsyncExceptionCode.ClientInputError, e);
    } catch (ConnectionException e) {
      throw new AsyncApiException("Failed to create job ", AsyncExceptionCode.ClientInputError, e);
    }
    return null;
  }
Пример #2
0
 static BatchInfo loadBatchInfo(InputStream in)
     throws PullParserException, IOException, ConnectionException {
   BatchInfo info = new BatchInfo();
   XmlInputStream xin = new XmlInputStream();
   xin.setInput(in, "UTF-8");
   info.load(xin, BulkConnection.typeMapper);
   return info;
 }
Пример #3
0
  public BatchResult getBatchResult(String jobId, String batchId) throws AsyncApiException {
    try {
      InputStream stream = doHttpGet(buildBatchResultURL(jobId, batchId));

      XmlInputStream xin = new XmlInputStream();
      xin.setInput(stream, "UTF-8");
      BatchResult result = new BatchResult();
      result.load(xin, typeMapper);
      return result;
    } catch (PullParserException e) {
      throw new AsyncApiException(
          "Failed to parse result ", AsyncExceptionCode.ClientInputError, e);
    } catch (IOException e) {
      throw new AsyncApiException("Failed to get result ", AsyncExceptionCode.ClientInputError, e);
    } catch (ConnectionException e) {
      throw new AsyncApiException("Failed to get result ", AsyncExceptionCode.ClientInputError, e);
    }
  }
Пример #4
0
 static void parseAndThrowException(InputStream in) throws AsyncApiException {
   try {
     XmlInputStream xin = new XmlInputStream();
     xin.setInput(in, "UTF-8");
     AsyncApiException exception = new AsyncApiException();
     exception.load(xin, typeMapper);
     throw exception;
   } catch (PullParserException e) {
     throw new AsyncApiException(
         "Failed to parse exception ", AsyncExceptionCode.ClientInputError, e);
   } catch (IOException e) {
     throw new AsyncApiException(
         "Failed to parse exception", AsyncExceptionCode.ClientInputError, e);
   } catch (ConnectionException e) {
     throw new AsyncApiException(
         "Failed to parse exception ", AsyncExceptionCode.ClientInputError, e);
   }
 }
Пример #5
0
  public QueryResultList getQueryResultList(String jobId, String batchId) throws AsyncApiException {
    InputStream stream = getBatchResultStream(jobId, batchId);

    try {
      XmlInputStream xin = new XmlInputStream();
      xin.setInput(stream, "UTF-8");
      QueryResultList result = new QueryResultList();
      result.load(xin, typeMapper);
      return result;
    } catch (ConnectionException e) {
      throw new AsyncApiException(
          "Failed to parse query result list ", AsyncExceptionCode.ClientInputError, e);
    } catch (PullParserException e) {
      throw new AsyncApiException(
          "Failed to parse query result list ", AsyncExceptionCode.ClientInputError, e);
    } catch (IOException e) {
      throw new AsyncApiException(
          "Failed to parse query result list ", AsyncExceptionCode.ClientInputError, e);
    }
  }
Пример #6
0
  public BatchInfo getBatchInfo(String jobId, String batchId) throws AsyncApiException {
    try {
      String endpoint = getRestEndpoint() + "job/" + jobId + "/batch/" + batchId;
      URL url = new URL(endpoint);
      InputStream stream = doHttpGet(url);

      XmlInputStream xin = new XmlInputStream();
      xin.setInput(stream, "UTF-8");
      BatchInfo result = new BatchInfo();
      result.load(xin, typeMapper);
      return result;
    } catch (IOException e) {
      throw new AsyncApiException(
          "Failed to parse batch info ", AsyncExceptionCode.ClientInputError, e);
    } catch (PullParserException e) {
      throw new AsyncApiException(
          "Failed to parse batch info ", AsyncExceptionCode.ClientInputError, e);
    } catch (ConnectionException e) {
      throw new AsyncApiException(
          "Failed to parse batch info ", AsyncExceptionCode.ClientInputError, e);
    }
  }
Пример #7
0
  public JobInfo getJobStatus(String jobId) throws AsyncApiException {
    try {
      String endpoint = getRestEndpoint();
      endpoint += "job/" + jobId;
      URL url = new URL(endpoint);

      InputStream in = doHttpGet(url);
      JobInfo result = new JobInfo();
      XmlInputStream xin = new XmlInputStream();
      xin.setInput(in, "UTF-8");
      result.load(xin, typeMapper);
      return result;
    } catch (PullParserException e) {
      throw new AsyncApiException(
          "Failed to get job status ", AsyncExceptionCode.ClientInputError, e);
    } catch (IOException e) {
      throw new AsyncApiException(
          "Failed to get job status ", AsyncExceptionCode.ClientInputError, e);
    } catch (ConnectionException e) {
      throw new AsyncApiException(
          "Failed to get job status ", AsyncExceptionCode.ClientInputError, e);
    }
  }
Пример #8
0
  private XMLizable receive(
      Transport transport, QName responseElement, Class responseType, InputStream in)
      throws IOException, ConnectionException {

    XMLizable result;

    try {

      XmlInputStream xin = new XmlInputStream();
      xin.setInput(in, "UTF-8");

      if (transport.isSuccessful()) {
        result = bind(xin, responseElement, responseType);
      } else {
        throw createException(xin);
      }
    } catch (PullParserException e) {
      throw new ConnectionException("Failed to create/parse xml input stream ", e);
    } finally {
      in.close();
    }

    return result;
  }