Package org.jrest4guice.rest.helper

Source Code of org.jrest4guice.rest.helper.JRest4GuiceHelper

package org.jrest4guice.rest.helper;

import org.apache.commons.beanutils.BeanUtilsBean;
import org.apache.commons.beanutils.Converter;
import org.jrest4guice.guice.PersistenceGuiceContext;
import org.jrest4guice.jndi.JndiGuiceModuleProvider;
import org.jrest4guice.rest.JRest4GuiceModuleProvider;
import org.jrest4guice.rest.commons.converter.DatePatternConverter;

/**
*
* @author <a href="mailto:zhangyouqun@gmail.com">cnoss (QQ:86895156)</a>
*
*/
public class JRest4GuiceHelper {
  private static long maxBodyPayloadSize = 1024*1024;
  /**
   * 打开JRest的支持
   *
   * @param scanPaths
   *            需要动态扫瞄的资源路径
   * @return
   */
  public static PersistenceGuiceContext useJRest(String... scanPaths) {
    //注册缺省的日期转换器(用于BeanUtilsBean)
    new DatePatternConverter().addDefaultDateConverter();
    //打开JRest的支持
    PersistenceGuiceContext.getInstance().addModuleProvider(
        new JRest4GuiceModuleProvider(scanPaths)).addModuleProvider(
        new JndiGuiceModuleProvider(scanPaths));
    return PersistenceGuiceContext.getInstance();
  }

  /**
   * 注册BeanUtils的对应的转换器
   *
   * @param converter
   * @param clazz
   */
  public static void addBeanConvert(Converter converter, Class<?> clazz) {
    BeanUtilsBean.getInstance().getConvertUtils()
        .register(converter, clazz);
  }
 
  /**
   * 设置客户端向服务端发送的http body的最大有效负载字节数
   * @param size
   */
  public static void setMaxBodyPayloadSize(long size){
    maxBodyPayloadSize = size;
  }
 
  public static long getMaxBodyPayloadSize(){
    return maxBodyPayloadSize;
  }
}
TOP

Related Classes of org.jrest4guice.rest.helper.JRest4GuiceHelper

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.