2010년 6월 23일 수요일

CXF 에서 HttpProxy 설정

프로그래밍으로 설정



package com.sds.shp.cxf.util;

import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;

import com.sds.shp.cxf.interceptor.SevenClientHandler;

public class ServiceClientUtil {
  @SuppressWarnings("unchecked")
  public static <T> T createClientProxy(Class<T> serviceEndpointInterface, String endpointUri) {
    
    JaxWsProxyFactoryBean proxyFactoryBean = new JaxWsProxyFactoryBean();
    
    proxyFactoryBean.setServiceClass(serviceEndpointInterface);
    proxyFactoryBean.setAddress(endpointUri);

    T service = (T) proxyFactoryBean.create();
    Client client = ClientProxy.getClient(service);
    
    String proxyServer = "serverip";
    int proxyServerPort = 10000;
    
    HTTPConduit http = (HTTPConduit) client.getConduit();
    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    httpClientPolicy.setConnectionTimeout(36000);
    httpClientPolicy.setAllowChunking(false);
    httpClientPolicy.setProxyServer(proxyServer);
    httpClientPolicy.setProxyServerPort(proxyServerPort);
    http.setClient(httpClientPolicy);


    return service;
  }
}




Resources:
http://markmail.org/message/fir6oi62eivaoxuu

댓글 없음:

댓글 쓰기