View Javadoc
1   package ca.uhn.fhir.rest.server.exceptions;
2   
3   /*
4    * #%L
5    * HAPI FHIR - Core Library
6    * %%
7    * Copyright (C) 2014 - 2018 University Health Network
8    * %%
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   * 
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   * 
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   * #L%
21   */
22  
23  import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
24  
25  import ca.uhn.fhir.context.FhirContext;
26  import ca.uhn.fhir.rest.api.Constants;
27  import ca.uhn.fhir.util.CoverageIgnore;
28  import ca.uhn.fhir.util.OperationOutcomeUtil;
29  
30  /**
31   * Represents an <b>HTTP 422 Unprocessable Entity</b> response, which means that a resource was rejected by the server because it "violated applicable FHIR profiles or server business rules".
32   * 
33   * <p>
34   * This exception will generally contain an {@link IBaseOperationOutcome} instance which details the failure.
35   * </p>
36   * 
37   * @see InvalidRequestException Which corresponds to an <b>HTTP 400 Bad Request</b> failure
38   */
39  @CoverageIgnore
40  public class UnprocessableEntityException extends BaseServerResponseException {
41  
42  	private static final String DEFAULT_MESSAGE = "Unprocessable Entity";
43  	private static final long serialVersionUID = 1L;
44  	public static final int STATUS_CODE = Constants.STATUS_HTTP_422_UNPROCESSABLE_ENTITY;
45  
46  	/**
47  	 * Constructor
48  	 * 
49  	 * @param theMessage
50  	 *            The message to add to the status line
51  	 *  @param theOperationOutcome The {@link IBaseOperationOutcome} resource to return to the client
52  	 */
53  	public UnprocessableEntityException(String theMessage, IBaseOperationOutcome theOperationOutcome) {
54  		super(STATUS_CODE, theMessage, theOperationOutcome);
55  	}
56  
57  	
58  	/**
59  	 * Constructor which accepts an {@link IBaseOperationOutcome} resource which will be supplied in the response
60  	 * 
61  	 * @deprecated Use constructor with FhirContext argument
62  	 */
63  	@Deprecated
64  	public UnprocessableEntityException(IBaseOperationOutcome theOperationOutcome) {
65  		super(STATUS_CODE, DEFAULT_MESSAGE, theOperationOutcome);
66  	}
67  
68  	/**
69  	 * Constructor which accepts an {@link IBaseOperationOutcome} resource which will be supplied in the response
70  	 */
71  	public UnprocessableEntityException(FhirContext theCtx, IBaseOperationOutcome theOperationOutcome) {
72  		super(STATUS_CODE, OperationOutcomeUtil.getFirstIssueDetails(theCtx, theOperationOutcome), theOperationOutcome);
73  	}
74  
75  	/**
76  	 * Constructor which accepts a String describing the issue. This string will be translated into an {@link IBaseOperationOutcome} resource which will be supplied in the response.
77  	 */
78  	public UnprocessableEntityException(String theMessage) {
79  		super(STATUS_CODE, theMessage);
80  	}
81  
82  	/**
83  	 * Constructor which accepts an array of Strings describing the issue. This strings will be translated into an {@link IBaseOperationOutcome} resource which will be supplied in the response.
84  	 */
85  	public UnprocessableEntityException(String... theMessage) {
86  		super(STATUS_CODE, theMessage);
87  	}
88  
89  }