org.macrocloud.kernel.security.provider.ResponseProvider Maven / Gradle / Ivy
package org.macrocloud.kernel.security.provider;
import lombok.extern.slf4j.Slf4j;
import org.macrocloud.kernel.toolkit.api.ResultCode;
import org.macrocloud.kernel.toolkit.constant.MacroConstant;
import org.macrocloud.kernel.toolkit.jackson.JsonUtil;
import org.macrocloud.kernel.toolkit.response.ResponseData;
import org.springframework.http.MediaType;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Objects;
/**
* ResponseProvider
*
*/
@Slf4j
public class ResponseProvider {
public static void write(HttpServletResponse response) {
ResponseData result = ResponseData.error(ResultCode.UN_AUTHORIZED.getCode(), "");
response.setCharacterEncoding(MacroConstant.UTF_8);
response.setHeader(MacroConstant.CONTENT_TYPE_NAME, MediaType.APPLICATION_JSON_UTF8_VALUE);
response.setStatus(HttpServletResponse.SC_OK);
try {
response.getWriter().write(Objects.requireNonNull(JsonUtil.toJson(result)));
} catch (IOException ex) {
log.error(ex.getMessage());
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy