开发CXF客户端通过HTTP Basic Authorization 安全认证的几种办法
开发CXF客户端通过HTTP Basic Authorization 安全认证的几种办法,有很多个,但是网上包括英文stackoverflow网站和官方文档全部是错误的。一般的CXF客户端开发方法是首先通过网络获取WSDL文件,然后再发送验证用户名密码调用服务,然而在客户端声明并创建服务实例的时候,如
HelloWorldService ss = new HelloWorldService(wsdlURL, SERVICE_NAME);
就无法通过Http basic 验证,所以之后的所有用户名和密码设置全部失效。
下面贴出几种CXF客户端通过HTTP Basic Authorization 安全认证的方法代码:
private static final QName SERVICE_NAME = new QName("http://example.org/", "HelloWorldService");
private HelloWorld_HelloWorldPort_Client() {
}
public static void main(String args[]) throws java.lang.Exception {
URL wsdlURL = HelloWorldService.WSDL_LOCATION;
if (args.length > 0 && args[0] != null && !"".equals(args[0])) {
File wsdlFile = new File(args[0]);
try {
if (wsdlFile.exists()) {
wsdlURL = wsdlFile.toURI().toURL();
} else {
wsdlURL = new URL(args[0]);
}
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
System.setProperty( "proxySet", "true" );
System.setProperty( "http.proxyHost", "10.133.96.245" );
System.setProperty( "http.proxyPort", "8080" );
//very important!!!
wsdlURL=new File("D:/hello.xml").toURI().toURL();
HelloWorldService ss = new HelloWorldService(wsdlURL, SERVICE_NAME);//如果wsdlURL是来自HTTP的网络,则此处无法通过Http Basic 验证,已经出错
HelloWorld port = ss.getHelloWorldPort();
//1、使用本地wsdl文件,而不是从网络中获取wsdl,则可以正常工作
// Service service = Service.create(wsdlURL, SERVICE_NAME);
// HelloWorld port = (HelloWorld) service.getPort(HelloWorld.class);
// BindingProvider bp=(BindingProvider)port;
// bp.getRequestContext().put(
// BindingProvider.USERNAME_PROPERTY, "ross");
// bp.getRequestContext().put(
// BindingProvider.PASSWORD_PROPERTY, "ross");
//2、以下可正常工作
// JaxWsProxyFactoryBean clientFactory = new JaxWsProxyFactoryBean();
// clientFactory.setAddress("http://localhost:8081/hello");
// clientFactory.setServiceClass(HelloWorld.class);
// clientFactory.setUsername("ross");
// clientFactory.setPassword("ross");
// HelloWorld port = (HelloWorld)clientFactory.create();
//end
//3、使用本地wsdl文件,而不是从网络中获取wsdl,则可以正常工作
// Client client = ClientProxy.getClient(port);
// HTTPConduit http = (HTTPConduit) client.getConduit();
// AuthorizationPolicy authorizationPolicy = new AuthorizationPolicy();
// authorizationPolicy.setUserName("ross");
// authorizationPolicy.setPassword("ross");
// authorizationPolicy.setAuthorizationType("Basic");
// http.setAuthorization(authorizationPolicy);
//end
//4、使用本地wsdl文件,而不是从网络中获取wsdl,则可以正常工作
// Map<String, List<String>> headers = new HashMap<String, List<String>>();
// headers.put("Authorization", Arrays.asList("Basic cm9zczpyb3Nz"));
// Client client = ClientProxy.getClient(port);
// client.getRequestContext().put(Message.PROTOCOL_HEADERS, headers);
//end
//5、使用本地wsdl文件,而不是从网络中获取wsdl,则可以正常工作
Client client = ClientProxy.getClient(port);
HTTPConduit http =
(HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setAutoRedirect(true);
http.setClient(httpClientPolicy);
http.setAuthSupplier(
new MyBasicAuthSupplier("mule-realm", "ross", "ross"));
//end
// Okay, are you sick of configuration files ?
// This will show you how to configure the http conduit dynamically
// Client client = ClientProxy.getClient(port);
// HTTPConduit http = (HTTPConduit) client.getConduit();
// HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
// httpClientPolicy.setConnectionTimeout(36000);
// httpClientPolicy.setAllowChunking(false);
// httpClientPolicy.setReceiveTimeout(32000);
// httpClientPolicy.setConnection(ConnectionType.CLOSE);
// http.setClient(httpClientPolicy);
{
System.out.println("Invoking sayHi...");
java.lang.String _sayHi_arg0 = "";
java.lang.String _sayHi__return = port.sayHi(_sayHi_arg0);
System.out.println("sayHi.result=" + _sayHi__return);
}
System.exit(0);
}
低密度脂蛋白胆固醇偏高怎么办?
低密度脂蛋白偏高对心脑血管不利。要注意控制饮食,戒烟戒酒,少吃油腻,多吃青菜,吃饭七成饱。饭后一小时活动,微出汗,半上午或半下午可吃点水果。坚持下去,就会正常的。
多吃豆制品和少量饮葡萄酒(一天不超过100毫升)可增加高密度脂蛋白胆固醇水平。大量饮酒极易由于热能过剩而肥胖,同时肝内合成甘油三酯量增加,极低密度脂蛋白胆固醇分泌也增多,反而造成高脂血症。
要戒酒,低脂饮食(少吃肥肉及油炸食品),多运动,总胆固醇高会导致动脉粥样硬化,引起高血压\冠心病\ 脂肪肝, 找医生开点,降脂药.高血脂是指血中胆固醇(TC)和/或甘油三酯(TG)过高或高密度脂蛋白胆固醇(HDL-C)过低,现代医学称之为血脂异常。
附:
高脂肪,高胆固醇食物:
纯糖、巧克力、糖果、甜点、冰淇淋、甜饮料、花生、松籽、蜂蜜、肥肉、黄油、奶油、内脏、动物脑、鱼籽、动物油脂等
Database Systems: Why is it hard to scale a database, in layman's terms? - Quora
为什么数据库难以扩展具备高伸缩性?
The real-world analog here is that databases are often stored on hard drives, and hard drives are of finite space, and you can only pack so many hard drives on a computer (in a data center, on a rack). Data centers are now very, very large in order to contend with this common problem but if you are an extremely voluminous library, you may exceed this constraint, and overflow your data center rack's ability to hold hard drives, or even your entire data center and need a new one (rare). Still, the point is that no matter how much room you start off with, you may exceed it, and you may not be able to linearly keep adding more "units" of room (i.e. shelves in the same building) and you might have to take some sort of step jump, like leasing another building or renting another rack or building another datacenter.