You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ArchivaRestServiceExceptionMapper.java 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package org.apache.archiva.rest.services.interceptors.v2;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. import org.apache.archiva.rest.api.services.v2.ArchivaRestError;
  21. import org.apache.archiva.rest.api.services.v2.ArchivaRestServiceException;
  22. import org.springframework.stereotype.Service;
  23. import javax.ws.rs.core.Response;
  24. import javax.ws.rs.ext.ExceptionMapper;
  25. import javax.ws.rs.ext.Provider;
  26. /**
  27. * Maps exceptions to REST responses.
  28. *
  29. * @author Martin Stockhammer
  30. * @since 3.0
  31. */
  32. @Provider
  33. @Service( "v2.archivaRestServiceExceptionMapper" )
  34. public class ArchivaRestServiceExceptionMapper
  35. implements ExceptionMapper<ArchivaRestServiceException>
  36. {
  37. @Override
  38. public Response toResponse( final ArchivaRestServiceException e )
  39. {
  40. ArchivaRestError restError = new ArchivaRestError( e );
  41. Response.ResponseBuilder responseBuilder = Response.status( e.getHttpErrorCode() ).entity( restError );
  42. if ( e.getMessage() != null )
  43. {
  44. responseBuilder = responseBuilder.status( new Response.StatusType()
  45. {
  46. public int getStatusCode()
  47. {
  48. return e.getHttpErrorCode();
  49. }
  50. public Response.Status.Family getFamily()
  51. {
  52. return Response.Status.Family.SERVER_ERROR;
  53. }
  54. public String getReasonPhrase()
  55. {
  56. return e.getMessage();
  57. }
  58. } );
  59. }
  60. return responseBuilder.build();
  61. }
  62. }