本文整理汇总了Java中net.worktrail.appapi.response.RequestErrorException类的典型用法代码示例。如果您正苦于以下问题:Java RequestErrorException类的具体用法?Java RequestErrorException怎么用?Java RequestErrorException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RequestErrorException类属于net.worktrail.appapi.response包,在下文中一共展示了RequestErrorException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: syncWorkEntries
import net.worktrail.appapi.response.RequestErrorException; //导入依赖的package包/类
private void syncWorkEntries(WorkEntryStore workEntryStore)
throws RequestErrorException {
long lastSync = workEntryStore.lastSync;
long pageCount = 1;
long newLastSync = lastSync;
for (int i = 0 ; i < pageCount ; i++) {
WorkEntryListResponse ret = auth.fetchWorkEntries(lastSync, i+1);
pageCount = ret.getNumPages();
logger.info("page " + (i+1) + " / " + ret.getNumPages() + " results:" + ret.getWorkEntryList().size());
for (WorkEntry workEntry : ret.getWorkEntryList()) {
// logger.info(" - " + workEntry.getDescription());
newLastSync = Math.max(newLastSync, workEntry.getModifyDate());
workEntryStore.workEntries.put(workEntry.getId(), (WorkEntryImpl) workEntry);
}
// workEntryStore.workEntries.addAll(ret.getWorkEntryList());
}
workEntryStore.lastSync = newLastSync;
}
示例2: createHubEntries
import net.worktrail.appapi.response.RequestErrorException; //导入依赖的package包/类
public CreateHubEntriesResponse createHubEntries(Collection<HubEntry> hubEntries) throws RequestErrorException {
try {
JSONArray create = new JSONArray();
for (HubEntry hubEntry : hubEntries) {
create.put(hubEntry.toJSONObject());
}
JSONObject req = new JSONObject();
req.put("create", create);
JSONObject ret = requestPage("rest/hub/entries/create/", req);
JSONArray created = ret.getJSONArray("created");
List<Long> createdList = new ArrayList<>();
for (int i = 0 ; i < created.length() ; i++) {
createdList.add(created.getLong(i));
}
return new CreateHubEntriesResponse(createdList);
} catch (JSONException e) {
throw new RequestErrorException("Error while creating hub entries.", e);
}
}
示例3: verifyAuthorization
import net.worktrail.appapi.response.RequestErrorException; //导入依赖的package包/类
/**
* Checks whether the auth token which is represented by the request key was already authorized.
* @param requestKey
* @return
* @throws RequestErrorException
*/
public boolean verifyAuthorization(String requestKey) throws RequestErrorException {
Map<String, String> args = new HashMap<>();
args.put("requestkey", requestKey);
JSONObject ret = requestPage("rest/token/confirm/", args);
try {
String status = ret.getString("status");
if ("active".equals(status)) {
return true;
} else if ("rejected".equals(status)) {
throw new RequestErrorException("authorization was rejected.", null);
}
return false;
} catch (JSONException e) {
throw new RequestErrorException("Error while retrieving status.", e);
}
}
示例4: requestPage
import net.worktrail.appapi.response.RequestErrorException; //导入依赖的package包/类
private JSONObject requestPage(String path, Map<String, String> args) throws RequestErrorException {
try {
if (args == null) {
args = new HashMap<>();
}
args.put("appkey", appKey);
args.put("secretapikey", secretApiKey);
if (authToken != null) {
args.put("authtoken", authToken);
}
URL url = new URL(workTrailServer + "/" + path);
String query = WorkTrailConnectionUtils.getQuery(args.entrySet());
StringBuilder ret = WorkTrailConnectionUtils.requestDataFromUrl(url, query.getBytes("UTF-8"), "WorkTrail Hub");
JSONObject response = new JSONObject(ret.toString());
if (response.has("error")) {
logger.severe("Server returned error from request." + response.toString(4));
throw new RequestErrorException("Server responded with an error message: " + response.getString("error"), null, response);
}
return response;
} catch (IOException | JSONException e) {
throw new RequestErrorException("Error when requesting page {" + path + "}", e);
}
}
示例5: generateTestUser
import net.worktrail.appapi.response.RequestErrorException; //导入依赖的package包/类
/**
* generates a test user - will NOT work on https://worktrail.net !
* @return auth token.
* @throws RequestErrorException
*/
public String generateTestUser(WorkTrailAccessType accessType, WorkTrailScope[] scopes) throws RequestErrorException {
Map<String, String> args = createAuthArgs(accessType, scopes);
JSONObject ret = requestPage("rest/token/generatetestuser/", args);
try {
String authToken = ret.getString("authtoken");
this.authToken = authToken;
return authToken;
} catch (JSONException e) {
try {
logger.log(Level.SEVERE, "Error while generating test user: " + ret.toString(4));
} catch (JSONException e1) {
// never mind..
}
throw new RequestErrorException("Error while generating test user.", e);
}
}
示例6: testCreateBrokenProject
import net.worktrail.appapi.response.RequestErrorException; //导入依赖的package包/类
@Test
public void testCreateBrokenProject() throws Exception {
JSONObject prj = new JSONObject();
prj.put("name", "Example Project");
prj.put("state", "blubber");
Map<String, String> args = new HashMap<String, String>();
args.put("project", prj.toString());
try {
requestPage("rest/projects/create/", args);
Assert.fail("request was successful?!");
} catch (RequestErrorException e) {
JSONObject res = e.getResponseObject();
logger.info("result: " + res.toString());
Assert.assertEquals("invalid-model", res.optString("errortype"));
JSONObject errorObj = res.getJSONObject("errorobj");
@SuppressWarnings("unchecked")
ArrayList<String> keys = Lists.newArrayList(errorObj.keys());
Assert.assertEquals(Lists.newArrayList("state"), keys);
}
}
示例7: testCreateBrokenTask
import net.worktrail.appapi.response.RequestErrorException; //导入依赖的package包/类
@Test
public void testCreateBrokenTask() throws Exception {
Company company = workTrail.fetchCompany();
JSONObject task = new JSONObject();
task.put("project_id", company.getUnassignedProjectId());
task.put("summary", "Example Summary");
// task.put("description", "some sample description.");
task.put("state", "blubber");
try {
requestPage("rest/tasks/create/", Maps.newHashMap(Collections.singletonMap("task", task.toString())));
Assert.fail("task create request was successful?!");
} catch (RequestErrorException e) {
JSONObject res = e.getResponseObject();
Assert.assertEquals("invalid-model", res.optString("errortype"));
JSONObject errorObj = res.getJSONObject("errorobj");
@SuppressWarnings("unchecked")
ArrayList<String> keys = Lists.newArrayList(errorObj.keys());
Assert.assertEquals(Lists.newArrayList("state"), keys);
}
}
示例8: prepareHubSync
import net.worktrail.appapi.response.RequestErrorException; //导入依赖的package包/类
public final void prepareHubSync() throws RequestErrorException {
EmployeeListResponse employeeListResponse = auth.fetchEmployees();
employeeEmailMap = new HashMap<>();
for (EmployeeImpl employee : employeeListResponse.getEmployeeList()) {
employeeEmailMap.put(employee.getPrimaryEmail(), employee);
String emailAliases = storage.getString("employee.emailaddresses." + employee.getEmployeeId());
if (emailAliases == null) {
storage.setString("employee.emailaddresses." + employee.getEmployeeId(), employee.getPrimaryEmail());
} else {
for (String alias : emailAliases.split(",")) {
alias = alias.trim();
if (alias.length() > 0) {
employeeEmailMap.put(alias, employee);
}
}
}
}
}
示例9: runSync
import net.worktrail.appapi.response.RequestErrorException; //导入依赖的package包/类
public void runSync() {
logger.info("We have to run sync.");
readJiraConfig();
File f = new File(prefixName + "_workentrystore.json");
File workLogFile = new File(prefixName + "_worklogstore.json");
WorkEntryStore workEntryStore = null;
WorkLogSyncStore workLogSyncStore = null;
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
boolean doWorkTrailSync = true;
try {
if (f.exists()) {
workEntryStore = mapper.readValue(f, WorkEntryStore.class);
} else {
workEntryStore = new WorkEntryStore();
}
if (workLogFile.exists()) {
workLogSyncStore = mapper.readValue(workLogFile, WorkLogSyncStore.class);
} else {
workLogSyncStore = new WorkLogSyncStore();
}
syncEmployees(workEntryStore);
if (doWorkTrailSync) {
syncWorkEntries(workEntryStore);
mapper.writeValue(f, workEntryStore);
}
try {
syncWorkLog(workEntryStore, workLogSyncStore);
} finally {
mapper.writeValue(workLogFile, workLogSyncStore);
}
} catch (RequestErrorException | IOException e) {
logger.log(Level.SEVERE, "Error while fetching work entries.", e);
}
}
示例10: syncEmployees
import net.worktrail.appapi.response.RequestErrorException; //导入依赖的package包/类
private void syncEmployees(WorkEntryStore workEntryStore) {
EmployeeListResponse employeeList;
try {
employeeList = auth.fetchEmployees();
workEntryStore.employees = new ArrayList<>(employeeList.getEmployeeList());
} catch (RequestErrorException e) {
throw new RuntimeException("Error fetching employees.", e);
}
}
示例11: fetchCompany
import net.worktrail.appapi.response.RequestErrorException; //导入依赖的package包/类
public Company fetchCompany() throws RequestErrorException {
JSONObject ret = requestPage("rest/company/");
try {
Company company = new CompanyImpl(ret.getLong("id"),
ret.getString("name"), ret.getString("slug"),
ret.getLong("break_task_id"),
ret.getLong("org_project_id"),
ret.getLong("unassigned_project_id"));
return company;
} catch (JSONException e) {
throw new RequestErrorException("Error while parsing response.", e);
}
}
示例12: invalidScopeTest
import net.worktrail.appapi.response.RequestErrorException; //导入依赖的package包/类
@Test
public void invalidScopeTest() {
try {
workTrail.generateTestUser(WorkTrailAccessType.EMPLOYEE, new WorkTrailScope[] { WorkTrailScope.WRITE_TASKS });
Assert.fail("request must fail.");
} catch (RequestErrorException e) {
Assert.assertEquals("Expected invalid scope response.", "invalid-scope", e.getResponseObject().optString("errortype"));
}
}
示例13: requestPage
import net.worktrail.appapi.response.RequestErrorException; //导入依赖的package包/类
/**
* can be used by tests to directly access the requestPage method and handle json parameters.
*/
protected JSONObject requestPage(String path, Map<String, String> args) throws RequestErrorException {
try {
Method requestPageMethod = workTrail.getClass().getDeclaredMethod("requestPage", new Class[] { String.class, Map.class });
requestPageMethod.setAccessible(true);
JSONObject response = (JSONObject) requestPageMethod.invoke(workTrail, path, args);
return response;
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
if (e.getCause() instanceof RequestErrorException) {
throw (RequestErrorException) e.getCause();
}
throw new RuntimeException("Error while calling requestPage.", e);
}
}
示例14: finishHubSync
import net.worktrail.appapi.response.RequestErrorException; //导入依赖的package包/类
public void finishHubSync(List<HubEntry> toCreate) throws RequestErrorException {
CreateHubEntriesResponse res = auth.createHubEntries(toCreate);
List<Long> createdList = res.getCreatedList();
for (int i = 0 ; i < createdList.size() ; i++) {
Long id = createdList.get(i);
if (id != null) {
storage.syncedObject(toCreate.get(i).getIdentifier(), id);
}
}
System.out.println("Created " + toCreate.size() + " entries.");
if (missingUsers.size() > 0) {
System.out.println("Missing Users: " + missingUsers);
}
}
示例15: clean
import net.worktrail.appapi.response.RequestErrorException; //导入依赖的package包/类
private void clean() {
try {
auth.cleanHubEntries();
storage.cleanSyncedObjects();
} catch (RequestErrorException e) {
throw new RuntimeException("Error cleaning hub entries.", e);
}
}