Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

Commit

Permalink
Merge pull request #36 from halusstefan/master
Browse files Browse the repository at this point in the history
Latest changes HTTP status code propagation + changed comments.
  • Loading branch information
csciuto committed Oct 3, 2014
2 parents 0ad2826 + 8332929 commit 66dfd4e
Show file tree
Hide file tree
Showing 17 changed files with 177 additions and 455 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.constantcontact</groupId>
<artifactId>constantcontact</artifactId>
<version>2.1.3</version>
<version>2.1.4</version>

<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.constantcontact.exceptions;

import com.constantcontact.util.CUrlRequestError;

import java.util.ArrayList;
import java.util.List;

import com.constantcontact.util.CUrlRequestError;

/**
* Base class for custom exceptions in ConstantContact.<br/>
* Each layer will extend this to add needed extras.<br/>
Expand All @@ -24,7 +24,12 @@ public class ConstantContactException extends Exception {
*/
private List<CUrlRequestError> errorInfo;

/**
/**
* HTTP status code retrieved from Constant Contact.
*/
private int httpStatusCode;

/**
* Default constructor.<br/>
* Sets the Error Info to an empty ArrayList.
*/
Expand Down Expand Up @@ -71,6 +76,7 @@ public ConstantContactException(Throwable cause) {
public ConstantContactException( ConstantContactException constantContactException) {
super(constantContactException);
this.setErrorInfo(constantContactException.getErrorInfo());
this.setHttpStatusCode(constantContactException.getHttpStatusCode());
}

/**
Expand Down Expand Up @@ -100,4 +106,21 @@ public List<CUrlRequestError> getErrorInfo() {
public boolean hasErrorInfo() {
return errorInfo != null && errorInfo.size() > 0;
}


/**
* Get the HTTP status code.
* @return httpsStatusCode
*/
public int getHttpStatusCode() {
return httpStatusCode;
}

/**
* Set the HTTP status code.
* @param httpStatusCode
*/
public void setHttpStatusCode(int httpStatusCode) {
this.httpStatusCode = httpStatusCode;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public ConstantContactServiceException(Throwable cause) {
public ConstantContactServiceException(ConstantContactException constantContactException) {
super(constantContactException);
this.setErrorInfo(constantContactException.getErrorInfo());
this.setHttpStatusCode(constantContactException.getHttpStatusCode());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import com.constantcontact.components.generic.response.ResultSet;
import com.constantcontact.exceptions.service.ConstantContactServiceException;
import com.constantcontact.services.base.BaseService;
import com.constantcontact.util.CUrlRequestError;
import com.constantcontact.util.CUrlResponse;
import com.constantcontact.util.Config;
import com.constantcontact.util.ConstantContactExceptionFactory;

/**
* Service Layer Implementation for pagination in Constant Contact.
Expand Down Expand Up @@ -46,11 +46,7 @@ public <T> ResultSet<T> getPage(String accessToken, Pagination pagination, Class
pageResultSet = Component.resultSetFromJSON(response.getBody(), objectClass);
}
if (response.isError()) {
ConstantContactServiceException constantContactException = new ConstantContactServiceException(
ConstantContactServiceException.RESPONSE_ERR_SERVICE);
response.getInfo().add(new CUrlRequestError("url", url));
constantContactException.setErrorInfo(response.getInfo());
throw constantContactException;
throw ConstantContactExceptionFactory.createServiceException(response, url);
}
} catch (ConstantContactServiceException e) {
throw new ConstantContactServiceException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import com.constantcontact.components.accounts.VerifiedEmailAddress.Status;
import com.constantcontact.exceptions.service.ConstantContactServiceException;
import com.constantcontact.services.base.BaseService;
import com.constantcontact.util.CUrlRequestError;
import com.constantcontact.util.CUrlResponse;
import com.constantcontact.util.Config;
import com.constantcontact.util.ConstantContactExceptionFactory;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -42,11 +42,7 @@ public List<VerifiedEmailAddress> getVerifiedEmailAddresses(String accessToken,
addresses = Component.listFromJSON(response.getBody(), VerifiedEmailAddress.class);
}
if (response.isError()) {
ConstantContactServiceException constantContactException = new ConstantContactServiceException(
ConstantContactServiceException.RESPONSE_ERR_SERVICE);
response.getInfo().add(new CUrlRequestError("url", url));
constantContactException.setErrorInfo(response.getInfo());
throw constantContactException;
throw ConstantContactExceptionFactory.createServiceException(response, url);
}
} catch (ConstantContactServiceException e) {
throw new ConstantContactServiceException(e);
Expand Down Expand Up @@ -77,11 +73,7 @@ public AccountInfo getAccountInfo(String accessToken) throws ConstantContactServ
accountInfo = Component.fromJSON(response.getBody(), AccountInfo.class);
}
if (response.isError()) {
ConstantContactServiceException constantContactException = new ConstantContactServiceException(
ConstantContactServiceException.RESPONSE_ERR_SERVICE);
response.getInfo().add(new CUrlRequestError("url", url));
constantContactException.setErrorInfo(response.getInfo());
throw constantContactException;
throw ConstantContactExceptionFactory.createServiceException(response, url);
}
} catch (ConstantContactServiceException e) {
throw new ConstantContactServiceException(e);
Expand Down Expand Up @@ -112,11 +104,7 @@ public AccountInfo updateAccountInfo(String accessToken, AccountInfo accountInfo
updatedAccountInfo = Component.fromJSON(response.getBody(), AccountInfo.class);
}
if (response.isError()) {
ConstantContactServiceException constantContactException = new ConstantContactServiceException(
ConstantContactServiceException.RESPONSE_ERR_SERVICE);
response.getInfo().add(new CUrlRequestError("url", url));
constantContactException.setErrorInfo(response.getInfo());
throw constantContactException;
throw ConstantContactExceptionFactory.createServiceException(response, url);
}
} catch (ConstantContactServiceException e) {
throw new ConstantContactServiceException(e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.constantcontact.services.activities;

import java.util.List;

import com.constantcontact.components.Component;
import com.constantcontact.components.activities.contacts.request.AddContactsRequest;
import com.constantcontact.components.activities.contacts.request.ClearListsRequest;
Expand All @@ -14,11 +12,13 @@
import com.constantcontact.components.activities.contacts.types.BulkActivityType;
import com.constantcontact.exceptions.service.ConstantContactServiceException;
import com.constantcontact.services.base.BaseService;
import com.constantcontact.util.CUrlRequestError;
import com.constantcontact.util.CUrlResponse;
import com.constantcontact.util.Config;
import com.constantcontact.util.ConstantContactExceptionFactory;
import com.constantcontact.util.http.MultipartBody;

import java.util.List;

/**
* Service Layer Implementation for the Bulk Activities in Constant Contact.
*
Expand Down Expand Up @@ -50,11 +50,7 @@ public ContactsResponse addContacts(String accessToken, AddContactsRequest reque
}

if (response.isError()) {
ConstantContactServiceException constantContactException = new ConstantContactServiceException(
ConstantContactServiceException.RESPONSE_ERR_SERVICE);
response.getInfo().add(new CUrlRequestError("url", url));
constantContactException.setErrorInfo(response.getInfo());
throw constantContactException;
throw ConstantContactExceptionFactory.createServiceException(response, url);
}
} catch (ConstantContactServiceException e) {
throw new ConstantContactServiceException(e);
Expand All @@ -76,11 +72,7 @@ public ContactsResponse addContacts(String accessToken, MultipartBody multipartR
}

if (response.isError()) {
ConstantContactServiceException constantContactException = new ConstantContactServiceException(
ConstantContactServiceException.RESPONSE_ERR_SERVICE);
response.getInfo().add(new CUrlRequestError("url", url));
constantContactException.setErrorInfo(response.getInfo());
throw constantContactException;
throw ConstantContactExceptionFactory.createServiceException(response, url);
}
} catch (Exception e) {
throw new ConstantContactServiceException(e);
Expand Down Expand Up @@ -109,11 +101,7 @@ public ContactsResponse removeContactsFromLists(String accessToken, RemoveContac
contactsResponse = Component.fromJSON(response.getBody(), ContactsResponse.class);
}
if (response.isError()) {
ConstantContactServiceException constantContactException = new ConstantContactServiceException(
ConstantContactServiceException.RESPONSE_ERR_SERVICE);
response.getInfo().add(new CUrlRequestError("url", url));
constantContactException.setErrorInfo(response.getInfo());
throw constantContactException;
throw ConstantContactExceptionFactory.createServiceException(response, url);
}
} catch (ConstantContactServiceException e) {
throw new ConstantContactServiceException(e);
Expand All @@ -134,11 +122,7 @@ public ContactsResponse removeContactsFromLists(String accessToken, MultipartBod
contactsResponse = Component.fromJSON(response.getBody(), ContactsResponse.class);
}
if (response.isError()) {
ConstantContactServiceException constantContactException = new ConstantContactServiceException(
ConstantContactServiceException.RESPONSE_ERR_SERVICE);
response.getInfo().add(new CUrlRequestError("url", url));
constantContactException.setErrorInfo(response.getInfo());
throw constantContactException;
throw ConstantContactExceptionFactory.createServiceException(response, url);
}
}
catch (ConstantContactServiceException e) {
Expand Down Expand Up @@ -170,11 +154,7 @@ public ContactsResponse clearLists(String accessToken, ClearListsRequest request
contactsResponse = Component.fromJSON(response.getBody(), ContactsResponse.class);
}
if (response.isError()) {
ConstantContactServiceException constantContactException = new ConstantContactServiceException(
ConstantContactServiceException.RESPONSE_ERR_SERVICE);
response.getInfo().add(new CUrlRequestError("url", url));
constantContactException.setErrorInfo(response.getInfo());
throw constantContactException;
throw ConstantContactExceptionFactory.createServiceException(response, url);
}
} catch (ConstantContactServiceException e) {
throw new ConstantContactServiceException(e);
Expand Down Expand Up @@ -204,11 +184,7 @@ public ContactsResponse exportContacts(String accessToken, ExportContactsRequest
contactsResponse = Component.fromJSON(response.getBody(), ContactsResponse.class);
}
if (response.isError()) {
ConstantContactServiceException constantContactException = new ConstantContactServiceException(
ConstantContactServiceException.RESPONSE_ERR_SERVICE);
response.getInfo().add(new CUrlRequestError("url", url));
constantContactException.setErrorInfo(response.getInfo());
throw constantContactException;
throw ConstantContactExceptionFactory.createServiceException(response, url);
}
} catch (ConstantContactServiceException e) {
throw new ConstantContactServiceException(e);
Expand Down Expand Up @@ -237,11 +213,7 @@ public List<SummaryReport> getSummaryReport(String accessToken) throws ConstantC
activitiesResponse = Component.listFromJSON(response.getBody(), SummaryReport.class);
}
if (response.isError()) {
ConstantContactServiceException constantContactException = new ConstantContactServiceException(
ConstantContactServiceException.RESPONSE_ERR_SERVICE);
response.getInfo().add(new CUrlRequestError("url", url));
constantContactException.setErrorInfo(response.getInfo());
throw constantContactException;
throw ConstantContactExceptionFactory.createServiceException(response, url);
}
} catch (ConstantContactServiceException e) {
throw new ConstantContactServiceException(e);
Expand Down Expand Up @@ -284,11 +256,7 @@ public List<DetailedStatusReport> getDetailedStatusReport(String accessToken, St
detailedStatusReports = Component.listFromJSON(response.getBody(), DetailedStatusReport.class);
}
if (response.isError()) {
ConstantContactServiceException constantContactException = new ConstantContactServiceException(
ConstantContactServiceException.RESPONSE_ERR_SERVICE);
response.getInfo().add(new CUrlRequestError("url", url));
constantContactException.setErrorInfo(response.getInfo());
throw constantContactException;
throw ConstantContactExceptionFactory.createServiceException(response, url);
}
} catch (ConstantContactServiceException e) {
throw new ConstantContactServiceException(e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.constantcontact.services.contactlists;

import java.net.HttpURLConnection;
import java.util.List;

import com.constantcontact.components.Component;
import com.constantcontact.components.contacts.Contact;
import com.constantcontact.components.contacts.ContactList;
import com.constantcontact.components.generic.response.ResultSet;
import com.constantcontact.exceptions.service.ConstantContactServiceException;
import com.constantcontact.services.base.BaseService;
import com.constantcontact.util.CUrlRequestError;
import com.constantcontact.util.CUrlResponse;
import com.constantcontact.util.Config;
import com.constantcontact.util.ConstantContactExceptionFactory;

import java.net.HttpURLConnection;
import java.util.List;

/**
* Service Layer Implementation for the Contact Lists operations in Constant Contact.
Expand Down Expand Up @@ -45,11 +45,7 @@ public List<ContactList> getLists(String accessToken, String modifiedSinceTimest
lists = Component.listFromJSON(response.getBody(), ContactList.class);
}
if (response.isError()) {
ConstantContactServiceException constantContactException = new ConstantContactServiceException(
ConstantContactServiceException.RESPONSE_ERR_SERVICE);
response.getInfo().add(new CUrlRequestError("url", url));
constantContactException.setErrorInfo(response.getInfo());
throw constantContactException;
throw ConstantContactExceptionFactory.createServiceException(response, url);
}
} catch (ConstantContactServiceException e) {
throw new ConstantContactServiceException(e);
Expand Down Expand Up @@ -80,11 +76,7 @@ public ContactList addList(String accessToken, ContactList list) throws Constant
newList = Component.fromJSON(response.getBody(), ContactList.class);
}
if (response.isError()) {
ConstantContactServiceException constantContactException = new ConstantContactServiceException(
ConstantContactServiceException.RESPONSE_ERR_SERVICE);
response.getInfo().add(new CUrlRequestError("url", url));
constantContactException.setErrorInfo(response.getInfo());
throw constantContactException;
throw ConstantContactExceptionFactory.createServiceException(response, url);
}
} catch (ConstantContactServiceException e) {
throw new ConstantContactServiceException(e);
Expand Down Expand Up @@ -114,11 +106,7 @@ public ContactList getList(String accessToken, String listId) throws ConstantCon
list = Component.fromJSON(response.getBody(), ContactList.class);
}
if (response.isError()) {
ConstantContactServiceException constantContactException = new ConstantContactServiceException(
ConstantContactServiceException.RESPONSE_ERR_SERVICE);
response.getInfo().add(new CUrlRequestError("url", url));
constantContactException.setErrorInfo(response.getInfo());
throw constantContactException;
throw ConstantContactExceptionFactory.createServiceException(response, url);
}
} catch (ConstantContactServiceException e) {
throw new ConstantContactServiceException(e);
Expand Down Expand Up @@ -152,11 +140,7 @@ public ContactList updateList(String accessToken, ContactList list) throws Const
resultingList = Component.fromJSON(response.getBody(), ContactList.class);
}
if (response.isError()) {
ConstantContactServiceException constantContactException = new ConstantContactServiceException(
ConstantContactServiceException.RESPONSE_ERR_SERVICE);
response.getInfo().add(new CUrlRequestError("url", url));
constantContactException.setErrorInfo(response.getInfo());
throw constantContactException;
throw ConstantContactExceptionFactory.createServiceException(response, url);
}
} catch (ConstantContactServiceException e) {
throw new ConstantContactServiceException(e);
Expand Down Expand Up @@ -195,11 +179,7 @@ public ResultSet<Contact> getContactsFromList(String accessToken, String listId,
contacts = Component.resultSetFromJSON(response.getBody(), Contact.class);
}
if (response.isError()) {
ConstantContactServiceException constantContactException = new ConstantContactServiceException(
ConstantContactServiceException.RESPONSE_ERR_SERVICE);
response.getInfo().add(new CUrlRequestError("url", url));
constantContactException.setErrorInfo(response.getInfo());
throw constantContactException;
throw ConstantContactExceptionFactory.createServiceException(response, url);
}
} catch (ConstantContactServiceException e) {
throw new ConstantContactServiceException(e);
Expand All @@ -225,11 +205,7 @@ public boolean deleteList(String accessToken, String listId) throws ConstantCont

CUrlResponse response = getRestClient().delete(url, accessToken);
if (response.isError()) {
ConstantContactServiceException constantContactException = new ConstantContactServiceException(
ConstantContactServiceException.RESPONSE_ERR_SERVICE);
response.getInfo().add(new CUrlRequestError("url", url));
constantContactException.setErrorInfo(response.getInfo());
throw constantContactException;
throw ConstantContactExceptionFactory.createServiceException(response, url);
}
return response.getStatusCode() == HttpURLConnection.HTTP_NO_CONTENT;
} catch (ConstantContactServiceException e) {
Expand Down
Loading

0 comments on commit 66dfd4e

Please sign in to comment.