All Downloads are FREE. Search and download functionalities are using the official Maven repository.

top.osjf.sdk.http.AbstractHttpResponse Maven / Gradle / Ivy

/*
 * Copyright 2024-? the original author or authors.
 *
 * 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
 *
 *      https://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 top.osjf.sdk.http;

import top.osjf.sdk.core.process.AbstractResponse;
import top.osjf.sdk.core.process.DefaultErrorResponse;

import java.util.Objects;

/**
 * Http response abstract node class, used to define common states,
 * unknown error messages, success plans, etc.
 *
 * 

You can check the example code: *

 * {@code
 * public class TestR extends AbstractHttpResponse {
 *
 *     private Boolean success;
 *
 *     private Integer code;
 *
 *     private String message;
 *
 *     private Object errors;
 *
 *     private List data;
 * }}
 * 
* *

Due to differences in encapsulation interfaces, public fields are not provided here. * If you need to default, please refer to {@link DefaultErrorResponse}. *

*
{@link DefaultErrorResponse#buildSdkExceptionResponse(String)}
*
{@link DefaultErrorResponse#buildUnknownResponse(String)}
*
{@link DefaultErrorResponse#buildDataErrorResponse(String)}
*
* *

The prerequisite for use is to check if the field name is consistent * with yours, otherwise the default information in {@link AbstractResponse} * will be obtained. * * @author zhangpengfei * @since 1.0.0 */ public abstract class AbstractHttpResponse extends AbstractResponse implements HttpResponse { private static final long serialVersionUID = 5815281226315499244L; public static final String SUCCESS_MESSAGE = "Congratulations"; public static final String FAILED_MESSAGE = "Internal system error"; /** {@code isSuccess} and {@code getMessage} define http success situation.*/ @Override public boolean isSuccess() { return Objects.equals(getCode(), SC_OK) || Objects.equals(getCode(),SC_OK0); } @Override public String getMessage() { return SUCCESS_MESSAGE; } /** {@inheritDoc}*/ @Override public Object getCode() { return SC_OK; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy