首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

axis2和cxf获得内置对象

2013-11-08 
axis2和cxf取得内置对象开发webservice的时候使用内置对象的确很头疼,网上找了好多资料才勉强搜集了一下,

axis2和cxf取得内置对象
开发webservice的时候使用内置对象的确很头疼,网上找了好多资料才勉强搜集了一下,给大家分享一下吧。

1.axis2获取内置对象

package org.lxh;    public class Snippet {      public HttpServletRequest getRequest() {          MessageContext mc = MessageContext.getCurrentMessageContext();          if (mc == null) {              System.out.println("无法获取到MessageContext");              return null;          }          HttpServletRequest request = (HttpServletRequest)mc.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST);          return request;      }        public HttpServletResponse getResponse() {          MessageContext mc = MessageContext.getCurrentMessageContext();          if (mc == null) {              System.out.println("无法获取到MessageContext");              return null;          }          HttpServletResponse response = (HttpServletResponse)mc.getProperty(HTTPConstants.MC_HTTP_SERVLETRESPONSE);          return response;      }  }  


2.cxf获取内置对象

package org.lxh;    import java.util.Date;  import javax.annotation.Resource;  import javax.jws.WebService;  import javax.servlet.http.HttpServletRequest;  import javax.servlet.http.HttpSession;  import javax.xml.ws.WebServiceContext;  import javax.xml.ws.handler.MessageContext;  import org.apache.cxf.message.Message;  import org.apache.cxf.transport.http.AbstractHTTPDestination;  import org.slf4j.Logger;  import org.slf4j.LoggerFactory;  import org.springframework.beans.factory.annotation.Autowired;    @WebService  public class SendSMSImpl implements SendSMS {      private Logger log = LoggerFactory.getLogger(this.getClass());        @Resource      private WebServiceContext context;        public String getIp() {          try {              MessageContext ctx = context.getMessageContext();              HttpServletRequest request = (HttpServletRequest) ctx                      .get(AbstractHTTPDestination.HTTP_REQUEST);              String ip = request.getRemoteAddr();              return ip;          } catch (Exception e) {              return "获取ip失败";          }      }  }  

热点排行