您的位置:程序门 -> java -> web services / xml



jsp调用webservice的问题


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


jsp调用webservice的问题
发表于:2007-06-11 05:59:12 楼主
最近在做webservice的测试,使用myeclipse5.1.1创建webservice,名字为user,在服务中添加两个方法

public   string   example(string   message)   {
return   message;
}

public   string[]   usercheck(string   username,string   password){
string   s[]   =   null;
if   (username.equalsignorecase( "robin ")   &&   password.equalsignorecase( "password ")){
s   =   new   string[3];
s[0]   =   "robin ";
s[1]= "robin ";
s[2]= "robin ";
}
return   s;
}

发布到tomcat6中,然后通过myeclipse生成客户端,在客户端中调用服务进行测试。在客户端中调用正常。接下来想在jsp中实现用户身份验证功能,即有叶面提交用户名和密码,由wenservice返回。
于是编写身份验证bean
public   class   tt   {

private   static   userclient   uc   =   new   userclient();
private   static   userporttype   ut   =   uc.getuserhttpport();

public   string   getexmple(){
string   s   =   ut.example( "robin ");
return   s;
}

public   list   getuser(string   username,string   password){
list   s   =   null;
arrayofstring   as   =   (arrayofstring)ut.usercheck(username,password);
try   {
s   =   (list)as.getstring();
}catch(exception   e   ){
s   =   null;
}

return   s;
}


public   static   void   main(string[]   args)   {
//   todo   auto-generated   method   stub

tt   t   =   new   tt();
system.out.println(t.getexmple());
list   l   =   t.getuser( "robin ", "password ");
if(l==null){
system.out.println( "dd   ");
}else{
system.out.println(l.size());
}

//system.out.println(.size());

}

}

在eclipse中直接运行,正常。但是当我在jsp中进行引用的时候出现问题
<%@   page   import= "com.zoo.tt "   %>
      <%
        tt   t   =   new   tt();
        out.println(t.getexmple());
        list   l   =   t.getuser( "robin ", "password ");
        out.println( "________ ");
        out.println(l.size());
        out.println( "________ ");
          %>

字符串的引用没有问题,就是在list调用时出错
unable   to   locate   jaxb.properties   for   package   com.zoo.service.user

郁闷几天ing
发表于:2007-06-11 08:52:001楼 得分:0
提示找不到jaxb.properties   这个文件

把这个package   com.zoo.service.user类贴出来看看。。。
发表于:2007-06-11 10:51:292楼 得分:0
感谢楼上的。
服务端源代码
iuser:
package   com.zoo.service.user;
//generated   by   myeclipse

public   interface   iuser   {

public   string   example(string   message);

public   string[]   usercheck(string   username,string   password);

}

userimpl:
package   com.zoo.service.user;
//generated   by   myeclipse

public   class   userimpl   implements   iuser   {

public   string   example(string   message)   {
return   message;
}

public   string[]   usercheck(string   username,string   password){
string   s[]   =   null;
if   (username.equalsignorecase( "robin ")   &&   password.equalsignorecase( "password ")){
s   =   new   string[3];
s[0]   =   "robin ";
s[1]= "robin ";
s[2]= "robin ";
}
return   s;
}

}

客户端:
userclient:

package   com.zoo.service.client;

import   java.net.malformedurlexception;
import   java.util.collection;
import   java.util.hashmap;
import   java.util.list;

import   javax.xml.namespace.qname;
import   org.codehaus.xfire.xfireruntimeexception;
import   org.codehaus.xfire.aegis.aegisbindingprovider;
import   org.codehaus.xfire.annotations.annotationservicefactory;
import   org.codehaus.xfire.annotations.jsr181.jsr181webannotations;
import   org.codehaus.xfire.client.xfireproxyfactory;
import   org.codehaus.xfire.jaxb2.jaxbtyperegistry;
import   org.codehaus.xfire.service.endpoint;
import   org.codehaus.xfire.service.service;
import   org.codehaus.xfire.soap.abstractsoapbinding;
import   org.codehaus.xfire.transport.transportmanager;

import   com.zoo.service.user.arrayofstring;

public   class   userclient   {

private   static   xfireproxyfactory   proxyfactory   =   new   xfireproxyfactory();

private   hashmap   endpoints   =   new   hashmap();

private   service   service0;

public   userclient()   {
create0();
endpoint   userhttpportep   =   service0.addendpoint(new   qname(
"http://user.service.zoo.com ",   "userhttpport "),   new   qname(
"http://user.service.zoo.com ",   "userhttpbinding "),
"http://localhost/zoo/services/user ");
endpoints.put(new   qname( "http://user.service.zoo.com ",   "userhttpport "),
userhttpportep);
endpoint   userporttypelocalendpointep   =   service0.addendpoint(new   qname(
"http://user.service.zoo.com ",   "userporttypelocalendpoint "),
new   qname( "http://user.service.zoo.com ",
"userporttypelocalbinding "),   "xfire.local://user ");
endpoints.put(new   qname( "http://user.service.zoo.com ",
"userporttypelocalendpoint "),   userporttypelocalendpointep);
}

public   object   getendpoint(endpoint   endpoint)   {
try   {
return   proxyfactory.create((endpoint).getbinding(),   (endpoint)
.geturl());
}   catch   (malformedurlexception   e)   {
throw   new   xfireruntimeexception( "invalid   url ",   e);
}
}

public   object   getendpoint(qname   name)   {
endpoint   endpoint   =   ((endpoint)   endpoints.get((name)));
if   ((endpoint)   ==   null)   {
throw   new   illegalstateexception( "no   such   endpoint! ");
}
return   getendpoint((endpoint));
}

public   collection   getendpoints()   {
return   endpoints.values();
}

private   void   create0()   {
transportmanager   tm   =   (org.codehaus.xfire.xfirefactory.newinstance()
.getxfire().gettransportmanager());
hashmap   props   =   new   hashmap();
props.put( "annotations.allow.interface ",   true);
annotationservicefactory   asf   =   new   annotationservicefactory(
new   jsr181webannotations(),   tm,   new   aegisbindingprovider(
new   jaxbtyperegistry()));
asf.setbindingcreationenabled(false);
service0   =   asf.create((com.zoo.service.client.userporttype.class),
props);
{
abstractsoapbinding   soapbinding   =   asf.createsoap11binding(service0,
new   qname( "http://user.service.zoo.com ",
"userporttypelocalbinding "),
"urn:xfire:transport:local ");
}
{
abstractsoapbinding   soapbinding   =   asf
.createsoap11binding(service0,   new   qname(
"http://user.service.zoo.com ",   "userhttpbinding "),
"http://schemas.xmlsoap.org/soap/http ");
}
}

public   userporttype   getuserhttpport()   {
return   ((userporttype)   (this).getendpoint(new   qname(
"http://user.service.zoo.com ",   "userhttpport ")));
}

public   userporttype   getuserhttpport(string   url)   {
userporttype   var   =   getuserhttpport();
org.codehaus.xfire.client.client.getinstance(var).seturl(url);
return   var;
}

public   userporttype   getuserporttypelocalendpoint()   {
return   ((userporttype)   (this).getendpoint(new   qname(
"http://user.service.zoo.com ",   "userporttypelocalendpoint ")));
}

public   userporttype   getuserporttypelocalendpoint(string   url)   {
userporttype   var   =   getuserporttypelocalendpoint();
org.codehaus.xfire.client.client.getinstance(var).seturl(url);
return   var;
}

public   static   void   main(string[]   args)   {

userclient   client   =   new   userclient();

//create   a   default   service   endpoint
userporttype   service   =   client.getuserhttpport();

//todo:   add   custom   client   code   here
//
//service.yourserviceoperationhere();

system.out.println( "test   client   completed ");
system.out.println( "test   client   completed ");

system.out.println(service.example( "ww "));

list   s   =   null;
arrayofstring   as   =   service.usercheck( "robin ", "robin ");

try   {
s   =   (list)as.getstring();
system.out.println(s.size());
}catch(exception   e){
system.out.println( "s   is   null ");
}





//s   =   (list)ut.usercheck(username,password);


system.out.println( "test   client   completed ");
system.exit(0);
}

}

userporttype   :

package   com.zoo.service.client;

import   javax.jws.webmethod;
import   javax.jws.webparam;
import   javax.jws.webresult;
import   javax.jws.webservice;
import   javax.jws.soap.soapbinding;
import   com.zoo.service.user.arrayofstring;

@webservice(name   =   "userporttype ",   targetnamespace   =   "http://user.service.zoo.com ")
@soapbinding(use   =   soapbinding.use.literal,   parameterstyle   =   soapbinding.parameterstyle.wrapped)
public   interface   userporttype   {

@webmethod(operationname   =   "example ",   action   =   " ")
@webresult(name   =   "out ",   targetnamespace   =   "http://user.service.zoo.com ")
public   string   example(
@webparam(name   =   "in0 ",   targetnamespace   =   "http://user.service.zoo.com ")
string   in0);

@webmethod(operationname   =   "usercheck ",   action   =   " ")
@webresult(name   =   "out ",   targetnamespace   =   "http://user.service.zoo.com ")
public   arrayofstring   usercheck(
@webparam(name   =   "in0 ",   targetnamespace   =   "http://user.service.zoo.com ")
string   in0,
@webparam(name   =   "in1 ",   targetnamespace   =   "http://user.service.zoo.com ")
string   in1);

}


发表于:2007-06-11 12:57:333楼 得分:0
不错,开源了


快速检索

最新资讯
热门点击