随笔 - 9  文章 - 12  trackbacks - 0
<2008年5月>
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

常用链接

留言簿(2)

随笔档案

相册

搜索

  •  

最新评论

阅读排行榜

评论排行榜

前些天做了一个小系统用到webservice, 只有客户端  (外网的servcice),  公司的网络环境是采用代理上网.

走了好多弯路才调通,    现在分享一下,  希望能对在这方面感到困惑的朋友有一点帮助.

我采用的框架是axis2.


 //options用来包容客户端的各种设置

 Options options = new Options();

//设置地址
        options.setTo(
                new EndpointReference(address));

//设置服务端认证.  , 开始的时候没有设host和domain,   认证通不过,  生成的http header 中也没有认证信息.  搞了好半天才发现必须设置主机和域名(服务器端的)
        HttpTransportProperties.Authenticator auth=new HttpTransportProperties.Authenticator();
        auth.setUsername("Administrator");
        auth.setPassword("2222");
        auth.setHost("test.xxx.com");
        auth.setDomain("test.xxxx.com");

        options.setProperty(HTTPConstants.AUTHENTICATE, auth);
 
        options.setAction("Execute");
        
//必须设置http version为1.0,  这样客户端的代理属性才起作用.
        options.setProperty(HTTPConstants.HTTP_PROTOCOL_VERSION,
           HTTPConstants.HEADER_PROTOCOL_10);

        //proxy settings
        ProxyProperties proxyProperties=new ProxyProperties();
        proxyProperties.setProxyName("PROXYSERVER");
        proxyProperties.setProxyPort(8080);
        proxyProperties.setUserName("luyanbo");
        proxyProperties.setPassWord("sand");
        proxyProperties.setDomain("sand.cn");
       
        options.setProperty(HTTPConstants.PROXY, proxyProperties);
    
        ServiceClient servicClient = new ServiceClient();
        servicClient.setOptions(options);
        
//发送并接收
        OMElement result = servicClient.sendReceive(getAuthXml());

用的过程中, 发现axis2的文档实在太粗略了, 很多不该省略的地方也省了,  像代理属性设置里面,  http版本的设置就没有提到. 可能他们也是发扬风格. 怎么省事怎么来的吧

posted on 2007-09-24 18:30 人生如戏 阅读(3851) 评论(6)  编辑  收藏

FeedBack:
# re: axis2连接属性设置 2007-09-30 11:48 Bryan
你好,有几个问题想请教一下:
1 服务端你是用TOMCAT吧,怎样设置才能使客户端访问webservice的时候必须使用用户认证?能否给个例子
2 客户端设置的用户名,服务端应该怎么做才能取到?

谢谢  回复  更多评论
  
# re: axis2连接属性设置 2007-10-04 17:35 人生如戏
容器管理验证方法控制着当用户访问受保护的web应用资源时,如何进行用户的身份鉴别。当一个web应用使用了Basic Authentication(BASIC参数在web.xml文件中auto-method元素中设置),而有用户访问受保护的web应用时,Tomcat将通过HTTP Basic Authentication方式,弹出一个对话框,要求用户输入用户名和密码。在这种验证方法中,所有密码将被以64位的编码方式在网络上传输。

注意:使用Basic Authentication通过被认为是不安全的,因为它没有强健的加密方法,除非在客户端和服务器端都使用HTTPS或者其他密码加密码方式(比如,在一个虚拟私人网络中)。若没有额外的加密方法,网络管理员将能够截获(或滥用)用户的密码。但是,如果你是刚开始使用Tomcat,或者你想在你的web应用中测试一下基于容器的安全管理,Basic Authentication还是非常易于设置和使用的。只需要添加<security-constraint>和<login-config> 两个元素到你的web应用的web.xml文件中,并且在CATALINA_BASE/conf/tomcat-users.xml 文件中添加适当的<role>和<user>即可,然后重新启动Tomcat。

下面例子中的web.xml摘自一个俱乐部会员网站系统,该系统中只有member目录被保护起来,并使用Basic Authentication进行身份验证。。

<!--
Define the Members-only area, by defining
a "Security Constraint" on this Application, and
mapping it to the subdirectory (URL) that we want
to restrict.
-->
<security-constraint>
<web-resource-collection>
<web-resource-name>
Entire Application
</web-resource-name>
<url-pattern>/members/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>member</role-name>
</auth-constraint>
</security-constraint>
<!-- Define the Login Configuration for this Application -->
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>My Club Members-only Area</realm-name>
</login-config>

说明: <url-pattern>/members/*</url-pattern> 指定受保护的资源的url pattern

<auth-constraint>
<role-name>member</role-name>
</auth-constraint>
指定访问需要的角色, 需要在tomcat-users.xml里添加 member 角色 , 和自己指定的用户名, 密码。


至于客户端的输入的用户名密码, 由容器来处理, 不需程序控制
  回复  更多评论
  
# re: axis2连接属性设置 2007-10-08 13:40 Bryan
@人生如戏
谢谢你的回答。

关于第二个问题,我其实是想在我提供的web service程序里去获取已经被验证通过的用户名,不知道Axis2里面有没有这样的api?  回复  更多评论
  
# re: axis2连接属性设置 2007-10-16 13:16 人生如戏
这个我也不清楚  回复  更多评论
  
# re: axis2连接属性设置 2007-12-28 10:09 a-moon
1:如果我想在服务器端取到客户端soap里面的http头信息怎么取啊?
2:如果我想在客户端设置http头content-type 怎么设置啊?
.....请指教...  回复  更多评论
  
# re: axis2连接属性设置[未登录] 2008-05-13 15:56 sunshine
ProxyProperties proxyProperties=new ProxyProperties();
我用这个对象老报错  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: