use of org.talend.components.marketo.runtime.client.type.MarketoError in project components by Talend.
the class MarketoRuntimeTestBase method getFailedSyncResult.
public MarketoSyncResult getFailedSyncResult(String api, String code, String message) {
MarketoSyncResult mkto = new MarketoSyncResult();
mkto.setSuccess(false);
mkto.setRecordCount(0);
List<MarketoError> errors = new ArrayList<>();
MarketoError error = new MarketoError(api, code, message);
errors.add(error);
mkto.setErrors(errors);
return mkto;
}
use of org.talend.components.marketo.runtime.client.type.MarketoError in project components by Talend.
the class MarketoBaseRESTClient method executeGetRequest.
public MarketoRecordResult executeGetRequest(Schema schema) throws MarketoException {
try {
URL url = new URL(current_uri.toString());
HttpsURLConnection urlConn = (HttpsURLConnection) url.openConnection();
urlConn.setRequestMethod("GET");
urlConn.setDoOutput(true);
urlConn.setRequestProperty(REQUEST_PROPERTY_ACCEPT, REQUEST_VALUE_TEXT_JSON);
int responseCode = urlConn.getResponseCode();
if (responseCode == 200) {
InputStream inStream = urlConn.getInputStream();
Reader reader = new InputStreamReader(inStream);
Gson gson = new Gson();
MarketoRecordResult mkr = new MarketoRecordResult();
LinkedTreeMap ltm = (LinkedTreeMap) gson.fromJson(reader, Object.class);
mkr.setRequestId(REST + "::" + ltm.get("requestId"));
mkr.setSuccess(Boolean.parseBoolean(ltm.get("success").toString()));
mkr.setStreamPosition((String) ltm.get(FIELD_NEXT_PAGE_TOKEN));
if (!mkr.isSuccess() && ltm.get(FIELD_ERRORS) != null) {
List<LinkedTreeMap> errors = (List<LinkedTreeMap>) ltm.get(FIELD_ERRORS);
for (LinkedTreeMap err : errors) {
MarketoError error = new MarketoError(REST, (String) err.get("code"), (String) err.get("message"));
mkr.setErrors(Arrays.asList(error));
}
}
if (mkr.isSuccess()) {
List<LinkedTreeMap> tmp = (List<LinkedTreeMap>) ltm.get("result");
if (tmp != null) {
mkr.setRecordCount(tmp.size());
mkr.setRecords(parseRecords(tmp, schema));
}
if (mkr.getStreamPosition() != null) {
mkr.setRemainCount(mkr.getRecordCount());
}
}
return mkr;
} else {
LOG.error("GET request failed: {}", responseCode);
throw new MarketoException(REST, responseCode, "Request failed! Please check your request setting!");
}
} catch (IOException e) {
LOG.error("GET request failed: {}", e.getMessage());
throw new MarketoException(REST, e.getMessage());
}
}
use of org.talend.components.marketo.runtime.client.type.MarketoError in project components by Talend.
the class MarketoBulkExecReaderTest method testRetryOperationFailDieOnError.
@Test
public void testRetryOperationFailDieOnError() throws Exception {
MarketoRecordResult mkto = new MarketoRecordResult();
mkto.setErrors(Arrays.asList(new MarketoError("REST", "902", "Invalid operation")));
when(client.bulkImport(any(TMarketoBulkExecProperties.class))).thenReturn(mkto);
try {
reader.start();
fail("Should not be here");
} catch (Exception e) {
assertTrue(e.getMessage().contains("902"));
}
}
use of org.talend.components.marketo.runtime.client.type.MarketoError in project components by Talend.
the class MarketoBulkExecReaderTest method testRetryOperationFailRecoverableErrror.
@Test
public void testRetryOperationFailRecoverableErrror() throws Exception {
MarketoRecordResult mkto = new MarketoRecordResult();
mkto.setErrors(Arrays.asList(new MarketoError("REST", "602", "expired header")));
when(client.bulkImport(any(TMarketoBulkExecProperties.class))).thenReturn(mkto);
doReturn(true).when(client).isErrorRecoverable(any(List.class));
reader.properties.dieOnError.setValue(false);
int minDelay = reader.getRetryAttemps() * reader.getRetryInterval();
long start = System.currentTimeMillis();
assertFalse(reader.start());
long end = System.currentTimeMillis();
int result = (int) reader.getReturnValues().get(RETURN_NB_CALL);
assertEquals((long) reader.getRetryAttemps(), result);
assertTrue(minDelay <= (end - start));
}
use of org.talend.components.marketo.runtime.client.type.MarketoError in project components by Talend.
the class MarketoBulkExecReaderTest method testStart.
@Test
public void testStart() throws Exception {
try {
assertFalse(reader.start());
fail("Should not be here");
} catch (Exception e) {
}
reader.properties.dieOnError.setValue(false);
MarketoRecordResult mkto = new MarketoRecordResult();
mkto.setErrors(Arrays.asList(new MarketoError("REST", "error")));
when(client.bulkImport(any(TMarketoBulkExecProperties.class))).thenReturn(mkto);
assertFalse(reader.start());
IndexedRecord record = new GenericData.Record(MarketoConstants.getEmptySchema());
mkto.setSuccess(true);
mkto.setRecords(Arrays.asList(record));
when(client.bulkImport(any(TMarketoBulkExecProperties.class))).thenReturn(mkto);
assertTrue(reader.start());
}
Aggregations