001/**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.camel.model.rest;
018
019import javax.xml.bind.annotation.XmlAccessType;
020import javax.xml.bind.annotation.XmlAccessorType;
021import javax.xml.bind.annotation.XmlAttribute;
022import javax.xml.bind.annotation.XmlRootElement;
023import javax.xml.bind.annotation.XmlTransient;
024
025import org.apache.camel.spi.Metadata;
026
027/**
028 * To specify the rest operation response messages using Swagger.
029 * <p/>
030 * This maps to the Swagger Response Message Object.
031 */
032@Metadata(label = "rest")
033@XmlRootElement(name = "responseMessage")
034@XmlAccessorType(XmlAccessType.FIELD)
035public class RestOperationResponseMsgDefinition {
036
037    @XmlTransient
038    private VerbDefinition verb;
039
040    @XmlAttribute
041    @Metadata(defaultValue = "200")
042    private String code;
043
044    @XmlAttribute(required = true)
045    private String message;
046
047    @XmlAttribute
048    @Metadata(defaultValue = "")
049    private String responseModel;
050
051    public RestOperationResponseMsgDefinition(VerbDefinition verb) {
052        this.verb = verb;
053    }
054
055    public RestOperationResponseMsgDefinition() {
056    }
057
058    public String getCode() {
059        return code != null ? code : "200";
060    }
061
062    public void setCode(String code) {
063        this.code = code;
064    }
065
066    public String getResponseModel() {
067        return responseModel != null ? responseModel : "";
068    }
069
070    public void setResponseModel(String responseModel) {
071        this.responseModel = responseModel;
072    }
073
074    public String getMessage() {
075        return message != null ? message : "success";
076    }
077
078    public void setMessage(String message) {
079        this.message = message;
080    }
081
082    /**
083     * The response code such as a HTTP status code.
084     */
085    public RestOperationResponseMsgDefinition code(int code) {
086        setCode("" + code);
087        return this;
088    }
089
090    /**
091     * The response code such as a HTTP status code. Can use <tt>general</tt>, or other words
092     * to indicate general error responses that do not map to a specific HTTP status code.
093     */
094    public RestOperationResponseMsgDefinition code(String code) {
095        setCode(code);
096        return this;
097    }
098
099    /**
100     * The response message (description)
101     */
102    public RestOperationResponseMsgDefinition message(String msg) {
103        setMessage(msg);
104        return this;
105    }
106
107    /**
108     * The response model
109     */
110    public RestOperationResponseMsgDefinition responseModel(Class<?> type) {
111        setResponseModel(type.getCanonicalName());
112        return this;
113    }
114
115    /**
116     * Ends the configuration of this response message
117     */
118    public RestDefinition endResponseMessage() {
119        verb.getResponseMsgs().add(this);
120        return verb.getRest();
121    }
122
123}