package com.hzs.filter;

import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;
import org.springframework.context.i18n.LocaleContextHolder;

import java.util.Locale;

/**
 * @Description:
 * @Author: jiang chao
 * @Time: 2023/9/5 11:42
 * @Classname: RpcFilter
 * @PackageName: com.hzs.filter
 */
@Activate(group = CommonConstants.PROVIDER)
@Slf4j
public class SystemProviderFilter implements Filter {

    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        Object locale = RpcContext.getContext().getAttachment("locale");
        if (null != locale) {
            String[] str = locale.toString().split("-");
            LocaleContextHolder.setLocale(new Locale(str[0], str[1]));
        }
        return invoker.invoke(invocation);
    }

}
