com.microsoft.windowsazure.services.media.implementation.MediaExceptionProcessor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of microsoft-windowsazure-api Show documentation
Show all versions of microsoft-windowsazure-api Show documentation
API for Microsoft Windows Azure Clients
/**
* Copyright Microsoft Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.microsoft.windowsazure.services.media.implementation;
import javax.inject.Inject;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.microsoft.windowsazure.services.core.ServiceException;
import com.microsoft.windowsazure.services.core.ServiceFilter;
import com.microsoft.windowsazure.services.core.utils.ServiceExceptionFactory;
import com.microsoft.windowsazure.services.media.MediaContract;
import com.microsoft.windowsazure.services.media.WritableBlobContainerContract;
import com.microsoft.windowsazure.services.media.entityoperations.EntityActionOperation;
import com.microsoft.windowsazure.services.media.entityoperations.EntityCreateOperation;
import com.microsoft.windowsazure.services.media.entityoperations.EntityDeleteOperation;
import com.microsoft.windowsazure.services.media.entityoperations.EntityGetOperation;
import com.microsoft.windowsazure.services.media.entityoperations.EntityListOperation;
import com.microsoft.windowsazure.services.media.entityoperations.EntityTypeActionOperation;
import com.microsoft.windowsazure.services.media.entityoperations.EntityUpdateOperation;
import com.microsoft.windowsazure.services.media.models.ListResult;
import com.microsoft.windowsazure.services.media.models.LocatorInfo;
import com.sun.jersey.api.client.ClientHandlerException;
import com.sun.jersey.api.client.UniformInterfaceException;
/**
* /**
* Wrapper implementation of MediaEntityContract
that
* translates exceptions into ServiceExceptions.
*
*/
public class MediaExceptionProcessor implements MediaContract {
/** The service. */
private final MediaContract service;
/** The log. */
private static Log log = LogFactory.getLog(MediaContract.class);
/**
* Instantiates a new media exception processor.
*
* @param service
* the service
*/
public MediaExceptionProcessor(MediaContract service) {
this.service = service;
}
/**
* Instantiates a new media exception processor.
*
* @param service
* the service
*/
@Inject
public MediaExceptionProcessor(MediaRestProxy service) {
this.service = service;
}
/* (non-Javadoc)
* @see com.microsoft.windowsazure.services.core.FilterableService#withFilter(com.microsoft.windowsazure.services.core.ServiceFilter)
*/
@Override
public MediaContract withFilter(ServiceFilter filter) {
return new MediaExceptionProcessor(service.withFilter(filter));
}
/**
* Process a catch.
*
* @param e
* the e
* @return the service exception
*/
private ServiceException processCatch(ServiceException e) {
log.warn(e.getMessage(), e.getCause());
return ServiceExceptionFactory.process("MediaServices", e);
}
/* (non-Javadoc)
* @see com.microsoft.windowsazure.services.media.entityoperations.EntityContract#create(com.microsoft.windowsazure.services.media.entityoperations.EntityCreateOperation)
*/
@Override
public T create(EntityCreateOperation creator) throws ServiceException {
try {
return service.create(creator);
}
catch (UniformInterfaceException e) {
throw processCatch(new ServiceException(e));
}
catch (ClientHandlerException e) {
throw processCatch(new ServiceException(e));
}
}
/* (non-Javadoc)
* @see com.microsoft.windowsazure.services.media.entityoperations.EntityContract#get(com.microsoft.windowsazure.services.media.entityoperations.EntityGetOperation)
*/
@Override
public T get(EntityGetOperation getter) throws ServiceException {
try {
return service.get(getter);
}
catch (UniformInterfaceException e) {
throw processCatch(new ServiceException(e));
}
catch (ClientHandlerException e) {
throw processCatch(new ServiceException(e));
}
}
/* (non-Javadoc)
* @see com.microsoft.windowsazure.services.media.entityoperations.EntityContract#list(com.microsoft.windowsazure.services.media.entityoperations.EntityListOperation)
*/
@Override
public ListResult list(EntityListOperation lister) throws ServiceException {
try {
return service.list(lister);
}
catch (UniformInterfaceException e) {
throw processCatch(new ServiceException(e));
}
catch (ClientHandlerException e) {
throw processCatch(new ServiceException(e));
}
}
/* (non-Javadoc)
* @see com.microsoft.windowsazure.services.media.entityoperations.EntityContract#update(com.microsoft.windowsazure.services.media.entityoperations.EntityUpdateOperation)
*/
@Override
public void update(EntityUpdateOperation updater) throws ServiceException {
try {
service.update(updater);
}
catch (UniformInterfaceException e) {
throw processCatch(new ServiceException(e));
}
catch (ClientHandlerException e) {
throw processCatch(new ServiceException(e));
}
}
/* (non-Javadoc)
* @see com.microsoft.windowsazure.services.media.entityoperations.EntityContract#delete(com.microsoft.windowsazure.services.media.entityoperations.EntityDeleteOperation)
*/
@Override
public void delete(EntityDeleteOperation deleter) throws ServiceException {
try {
service.delete(deleter);
}
catch (UniformInterfaceException e) {
throw processCatch(new ServiceException(e));
}
catch (ClientHandlerException e) {
throw processCatch(new ServiceException(e));
}
}
/* (non-Javadoc)
* @see com.microsoft.windowsazure.services.media.entityoperations.EntityContract#action(com.microsoft.windowsazure.services.media.entityoperations.EntityActionOperation)
*/
@Override
public void action(EntityActionOperation entityActionOperation) throws ServiceException {
try {
service.action(entityActionOperation);
}
catch (UniformInterfaceException e) {
throw processCatch(new ServiceException(e));
}
catch (ClientHandlerException e) {
throw processCatch(new ServiceException(e));
}
}
/* (non-Javadoc)
* @see com.microsoft.windowsazure.services.media.entityoperations.EntityContract#action(com.microsoft.windowsazure.services.media.entityoperations.EntityTypeActionOperation)
*/
@Override
public T action(EntityTypeActionOperation entityTypeActionOperation) throws ServiceException {
try {
return service.action(entityTypeActionOperation);
}
catch (UniformInterfaceException e) {
throw processCatch(new ServiceException(e));
}
catch (ClientHandlerException e) {
throw processCatch(new ServiceException(e));
}
}
/* (non-Javadoc)
* @see com.microsoft.windowsazure.services.media.MediaContract#createBlobWriter(com.microsoft.windowsazure.services.media.models.LocatorInfo)
*/
@Override
public WritableBlobContainerContract createBlobWriter(LocatorInfo locator) {
return service.createBlobWriter(locator);
}
}