@@ -1607,6 +1607,133 @@ else if (response.getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
16071607 throw new FilesAuthorizationException ("You must be logged in" , null , null );
16081608 }
16091609 }
1610+
1611+ /**
1612+ * Purges all items from a given container from the CDN
1613+ *
1614+ * @param container The name of the container
1615+ * @param emailAddresses An optional comma separated list of email addresses to be notified when the purge is complete.
1616+ * <code>null</code> if desired.
1617+ * @throws IOException Error talking to the cdn management server
1618+ * @throws HttpException Error with HTTP
1619+ * @throws FilesAuthorizationException Log in was not successful, or account is suspended
1620+ * @throws FilesException Other error
1621+ */
1622+ public void purgeCDNContainer (String container , String emailAddresses ) throws IOException , HttpException , FilesAuthorizationException , FilesException {
1623+ if (! isLoggedin ) {
1624+ throw new FilesAuthorizationException ("You must be logged in" , null , null );
1625+ }
1626+ if (!isValidContainerName (container )) {
1627+ throw new FilesInvalidNameException (container );
1628+ }
1629+ HttpDelete method = null ;
1630+ try {
1631+ String deleteUri = cdnManagementURL + "/" + sanitizeForURI (container );
1632+ method = new HttpDelete (deleteUri );
1633+ method .getParams ().setIntParameter ("http.socket.timeout" , connectionTimeOut );
1634+ method .setHeader (FilesConstants .X_AUTH_TOKEN , authToken );
1635+ if (emailAddresses != null ) {
1636+ method .setHeader (FilesConstants .X_PURGE_EMAIL , emailAddresses );
1637+ }
1638+
1639+ FilesResponse response = new FilesResponse (client .execute (method ));
1640+
1641+ if (response .getStatusCode () == HttpStatus .SC_UNAUTHORIZED ) {
1642+ method .abort ();
1643+ if (login ()) {
1644+ method = new HttpDelete (deleteUri );
1645+ method .getParams ().setIntParameter ("http.socket.timeout" , connectionTimeOut );
1646+ method .setHeader (FilesConstants .X_AUTH_TOKEN , authToken );
1647+ if (emailAddresses != null ) {
1648+ method .setHeader (FilesConstants .X_PURGE_EMAIL , emailAddresses );
1649+ }
1650+ response = new FilesResponse (client .execute (method ));
1651+ }
1652+ else {
1653+ throw new FilesAuthorizationException ("Re-login failed" , response .getResponseHeaders (), response .getStatusLine ());
1654+ }
1655+ }
1656+
1657+ if (response .getStatusCode () == HttpStatus .SC_NO_CONTENT )
1658+ {
1659+ return ;
1660+ }
1661+ else if (response .getStatusCode () == HttpStatus .SC_UNAUTHORIZED ) {
1662+ throw new FilesAuthorizationException ("User not Authorized!" ,response .getResponseHeaders (), response .getStatusLine ());
1663+ }
1664+ else {
1665+ throw new FilesException ("Unexpected server response" ,response .getResponseHeaders (), response .getStatusLine ());
1666+ }
1667+ }
1668+ finally {
1669+ if (method != null ) method .abort ();
1670+ }
1671+
1672+ }
1673+
1674+ /**
1675+ * Purges all items from a given container from the CDN
1676+ *
1677+ * @param container The name of the container
1678+ * @param object The name of the object
1679+ * @param emailAddresses An optional comma separated list of email addresses to be notified when the purge is complete.
1680+ * <code>null</code> if desired.
1681+ * @throws IOException Error talking to the cdn management server
1682+ * @throws HttpException Error with HTTP
1683+ * @throws FilesAuthorizationException Log in was not successful, or account is suspended
1684+ * @throws FilesException Other error
1685+ */
1686+ public void purgeCDNObject (String container , String object , String emailAddresses ) throws IOException , HttpException , FilesAuthorizationException , FilesException {
1687+ if (! isLoggedin ) {
1688+ throw new FilesAuthorizationException ("You must be logged in" , null , null );
1689+ }
1690+ if (!isValidContainerName (container )) {
1691+ throw new FilesInvalidNameException (container );
1692+ }
1693+ HttpDelete method = null ;
1694+ try {
1695+ String deleteUri = cdnManagementURL + "/" + sanitizeForURI (container ) +"/" +sanitizeForURI (object );
1696+ method = new HttpDelete (deleteUri );
1697+ method .getParams ().setIntParameter ("http.socket.timeout" , connectionTimeOut );
1698+ method .setHeader (FilesConstants .X_AUTH_TOKEN , authToken );
1699+ if (emailAddresses != null ) {
1700+ method .setHeader (FilesConstants .X_PURGE_EMAIL , emailAddresses );
1701+ }
1702+
1703+ FilesResponse response = new FilesResponse (client .execute (method ));
1704+
1705+ if (response .getStatusCode () == HttpStatus .SC_UNAUTHORIZED ) {
1706+ method .abort ();
1707+ if (login ()) {
1708+ method = new HttpDelete (deleteUri );
1709+ method .getParams ().setIntParameter ("http.socket.timeout" , connectionTimeOut );
1710+ method .setHeader (FilesConstants .X_AUTH_TOKEN , authToken );
1711+ if (emailAddresses != null ) {
1712+ method .setHeader (FilesConstants .X_PURGE_EMAIL , emailAddresses );
1713+ }
1714+ response = new FilesResponse (client .execute (method ));
1715+ }
1716+ else {
1717+ throw new FilesAuthorizationException ("Re-login failed" , response .getResponseHeaders (), response .getStatusLine ());
1718+ }
1719+ }
1720+
1721+ if (response .getStatusCode () == HttpStatus .SC_NO_CONTENT )
1722+ {
1723+ return ;
1724+ }
1725+ else if (response .getStatusCode () == HttpStatus .SC_UNAUTHORIZED ) {
1726+ throw new FilesAuthorizationException ("User not Authorized!" ,response .getResponseHeaders (), response .getStatusLine ());
1727+ }
1728+ else {
1729+ throw new FilesException ("Unexpected server response" ,response .getResponseHeaders (), response .getStatusLine ());
1730+ }
1731+ }
1732+ finally {
1733+ if (method != null ) method .abort ();
1734+ }
1735+
1736+ }
16101737
16111738 /**
16121739 * Gets list of all of the containers associated with this account.
0 commit comments