如何在JAX-WS中添加响应头 [英] How to add response header in JAX-WS

查看:179
本文介绍了如何在JAX-WS中添加响应头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个基于Web服务的Web组件,我使用Web服务
发布我的服务,我想在响应中添加标题,以便客户端可以使用带有响应结果的标题

I have developed a Web-service based web component, i publishing my service using web service and i want to add headers in response so that client can use that header with response result

我的网络服务类..

@WebService()
public class FooService{

@WebMethod()
public String fooWebMethod(String input){
//----some code----
  return resultString;
 }

}

我的网络服务客户端类..

My web service client class ..

public class WebServInvoker { 
public static void main(String[] args) {
             FooServiceServiceLocator locator = new FooServiceServiceLocator();
             FooService wsClient = locator.getFooServicePort();
             wsClient.fooWebMethod("some string");

       }
}

现在我想发送更多信息对于用户的Web服务响应,我不知道该怎么做请帮帮我

Now i want to send extra information to user in web service response , I have no idea how to do it Please help me

推荐答案

添加一个处理程序。一种方法如下所示

Add a handler. One way to do it as below

@WebService()
@HandlerChain(file = "FooService-HandlerChain.xml")
public class FooService{
      //your code 
}

然后你的处理程序文件

<handler-chains xmlns="http://java.sun.com/xml/ns/javaee">
  <handler-chain>
  <service-name-pattern xmlns:ns1="yournamespacepattern">ns1:FooService</service-name-pattern>
  <handler>
     <handler-name>HandlerClassName</handler-name>
     <handler-class>packagename.HandlerClassName</handler-class>
  </handler>


然后您的处理程序类

 public class HandlerClassName implements SOAPHandler<SOAPMessageContext>
 {
  public HandlerClassName () {
 }

public Set<QName> getHeaders(){
    return // set of headers;
}


public boolean handleMessage(SOAPMessageContext context)
{
     //handle message
}

}

这篇关于如何在JAX-WS中添加响应头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆