This is an automated email from the ASF dual-hosted git repository.
grv pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ofbiz-plugins.git The following commit(s) were added to refs/heads/trunk by this push: new fc0a447 Improved: Added response status for UNPROCESSABLE_ENTITY to conform to rfc4918(OFBIZ-11328) fc0a447 is described below commit fc0a447a2e1726de572296b0676b6eda1aed3191 Author: Girish Vasmatkar <[hidden email]> AuthorDate: Sat Sep 19 10:10:45 2020 +0530 Improved: Added response status for UNPROCESSABLE_ENTITY to conform to rfc4918(OFBIZ-11328) --- ...biz-rest-jerseyUiLabels.xml => ApiUiLabels.xml} | 0 .../apache/ofbiz/ws/rs/core/ResponseStatus.java | 98 ++++++++++++++++++++++ 2 files changed, 98 insertions(+) diff --git a/ofbiz-rest-impl/config/Ofbiz-rest-jerseyUiLabels.xml b/ofbiz-rest-impl/config/ApiUiLabels.xml similarity index 100% rename from ofbiz-rest-impl/config/Ofbiz-rest-jerseyUiLabels.xml rename to ofbiz-rest-impl/config/ApiUiLabels.xml diff --git a/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/core/ResponseStatus.java b/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/core/ResponseStatus.java new file mode 100644 index 0000000..b80c4ef --- /dev/null +++ b/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/core/ResponseStatus.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.ofbiz.ws.rs.core; + +import javax.ws.rs.core.Response.Status.Family; +import javax.ws.rs.core.Response.StatusType; + +public final class ResponseStatus { + + public enum Custom implements StatusType { + /** + * 422 Unprocessable Entity, see <a href= + * "https://tools.ietf.org/html/rfc4918#section-11.2">https://tools.ietf.org/html/rfc4918#section-11.2</a> + */ + UNPROCESSABLE_ENTITY(422, "Unprocessable Entity"); + + private final int code; + private final String reason; + private final Family family; + + Custom(final int statusCode, final String reasonPhrase) { + this.code = statusCode; + this.reason = reasonPhrase; + this.family = Family.familyOf(statusCode); + } + + /** + * Get the class of status code. + * + * @return the class of status code. + */ + @Override + public Family getFamily() { + return family; + } + + /** + * Get the associated status code. + * + * @return the status code. + */ + @Override + public int getStatusCode() { + return code; + } + + /** + * Get the reason phrase. + * + * @return the reason phrase. + */ + @Override + public String getReasonPhrase() { + return toString(); + } + + /** + * Get the reason phrase. + * + * @return the reason phrase. + */ + @Override + public String toString() { + return reason; + } + + /** + * Convert a numerical status code into the corresponding Status. + * + * @param statusCode the numerical status code. + * @return the matching Status or null is no matching Status is defined. + */ + public static ResponseStatus.Custom fromStatusCode(int code) { + for (Custom s : Custom.values()) { + if (s.code == code) { + return s; + } + } + return null; + } + } +} |
Free forum by Nabble | Edit this page |