一、对象参数的传递
首先是我们要传输的变量对象Order,代码如下:
package samples.userguide.example5;
public class Order
{
private String customerName;
private String shippingAddress;
public String getCustomerName()
{ return customerName; }
public void setCustomerName(String name)
{ customerName = name; }
}
要发布的services的代码如下:
package samples.userguide.example5;
public class BeanService
{
public Order getNewOrder(Order order)
{
order.setCustomerName("liuyujun");
return order;
}
}
然后我们只要在配置文件server-config.wsdd里加入下面这段就可以发布了
<service name="OrderProcessor" provider="java:RPC">
<parameter name="className" value="samples.userguide.example5.BeanService"/>
<parameter name="allowedMethods" value="*"/>
<beanMapping qname="myNS:Order" xmlns:myNS="urn:BeanService" languageSpecificType="java:samples.userguide.example5.Order"/>
</service>
特别要注意多了beanMapping这部分,qname指明我们用自己命名空间里的哪个对象,xmlns:myNS则指明了我们的命名空间,后面还一个指明了用到的对象类。
客户端调用程序:
package samples.userguide.example5;
public class Client
{
private final static String targetEndpointAddress = "http://localhost:8080/axis/services/OrderProcessor";
private final static QName qn = new QName( "urn:BeanService", "Order" );
public static void main(String [] args) throws Exception
{
//创建一个参数对象
Order order = new Order();
order.setCustomerName("Glen Daniels");
Service service = new Service();
Call call = (Call) service.createCall();
//注册对象类型
call.registerTypeMapping(Order.class, qn,
new org.apache.axis.encoding.ser.
BeanSerializerFactory(Order.class, qn),
new org.apache.axis.encoding.ser.
BeanDeserializerFactory(Order.class, qn));
call.setTargetEndpointAddress(new java.net.URL(targetEndpointAddress));
call.setOperationName(new QName("OrderProcessor", "getNewOrder"));
call.addParameter("order", qn, ParameterMode.IN);
call.setReturnType(qn, Order.class);
Order newOrder = (Order) call.invoke(new Object[] {order});
System.out.println("new custname:"+newOrder.getCustomerName());
}
}
这样就能看到返回的效果了;
二、获得访问者信息
MessageContext context = MessageContext.getCurrentContext();
HttpServletRequest req = (HttpServletRequest) context.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST);
这样就可以得到ruquest对象获得相关信息了,当然request的有些功能是用不了的,比如,getSession就是无效的