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

org.xson.web.handler.DefaultJSONResponseHandler Maven / Gradle / Ivy

Go to download

xco-web is an easy to use control layer framework, is part of the SOA system, using xml language to describe the controller.

The newest version!
package org.xson.web.handler;

import java.io.IOException;
import java.io.Writer;

import javax.servlet.http.HttpServletResponse;

import org.xson.web.RequestContext;
import org.xson.web.ResponseHandler;

import com.alibaba.fastjson.JSONObject;

public class DefaultJSONResponseHandler implements ResponseHandler {

	@Override
	public void onSuccess(RequestContext context) throws IOException {
		Object result = context.getResult();
		if (null != result) {
			HttpServletResponse response = context.getResponse();
			if (result instanceof JSONObject) {
				result = ((JSONObject) result).toJSONString();
			}
			response.setContentType("application/json;charset=utf-8");
			response.setCharacterEncoding("UTF-8");
			Writer write = response.getWriter();
			write.write(result.toString());
			write.close();
		}
	}

	@Override
	public void onError(RequestContext context) throws IOException {
		// TODO
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy