guo19870422
过特斯
2015-04-20 02:06

java cxf webservices 动态调用sap的一个服务地址,地址是带用户名和密码的权限。

  • ava webservices

import java.net.URL;

import javax.xml.namespace.QName;

import org.apache.cxf.configuration.security.AuthorizationPolicy;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;

public class testwebservices {

public static void main(String[] args) {
String url = "http://xxx?sap-client=100";//地址为一个sap的服务,带有用户名和密码权限。
    JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory
            .newInstance();

    //此处应该增加什么代码以便通过用户名密码权限,现在没设置回报401访问不通过

    Client client = factory.createClient(url);




    try {
        Object[] d = { "test" };
        QName opName = new QName("sdfdf", "sayHello");
        Object[] obj = client.invoke(opName, d);
        System.out.println("resp:" + obj[0]);

    } catch (Exception e) {
        e.printStackTrace();
    }

}

}

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答