webservice自定义标签及获得httpservletrquest

详见E:\学习文档子目录压缩\专项进阶,如ngnix,webservice,linux等\webservice\webservice springcxfservice3自定义标签及获得httpservletrquest

写发布接口类的接口

package com.xiang.iwebservice;

 

 

import javax.jws.WebMethod;

import javax.jws.WebParam;

import javax.jws.WebService;

 

import com.spcxfwebsercie.pojo.CXFXmlMessage;

@WebService

publicinterfaceILoingWebservice {

    @WebMethod

   publicCXFXmlMessage login(@WebParam(name="deviceID")String deviceID,@WebParam(name="timestamp")String timestamp,@WebParam(name="signature")String signature);

}


如图响应数据 Result,Token应该封装成一个类,这个xml类型还必须和ILoingWebservice.java的响应类型CXFXmlMessage一致




发布的webserver接口类实现这个接口

package com.xiang.iplewebservice;

 

import java.util.ArrayList;

import java.util.Date;

import java.util.List;

 

import javax.annotation.Resource;

import javax.jws.WebService;

import javax.servlet.ServletContext;

importjavax.servlet.http.HttpServletRequest;

import javax.xml.ws.WebServiceContext;

import javax.xml.ws.handler.MessageContext;

 

import com.spcxfwebsercie.pojo.CXFXmlMessage;

import com.spcxfwebsercie.pojo.Message;

importcom.xiang.iwebservice.ILoingWebservice;

import com.xiang.util.MakeToken;

 

@WebService

public class ImplLoingWebservice implementsILoingWebservice {

         privateList<Message> messages=null;

         publicImplLoingWebservice() {

                  //用户及密码map

                   messages=new ArrayList<Message>();

                   Message one = newMessage("GPS001|caozuoyuan01");

                   messages.add(one);

         }

         @Resource

         privateWebServiceContext context;

         @Override

         publicCXFXmlMessage login(String deviceID, String timestamp, String signature) {

                   MessageContext messageContext =context.getMessageContext();

                   HttpServletRequest request =(HttpServletRequest) messageContext.get(MessageContext.SERVLET_REQUEST);

                   //==之前不是自定义标签的

          /*  String  token =null;

                    for (Message message : messages) {

                            if(!deviceID.equals(message.getDeviceID())){

                                            thrownew RuntimeException("只开设备与设备操作员ID不正确");

                                   }

                              if(!signature.equals(message.getSignature())){

                                       thrownew RuntimeException("哥们你知道我的算法么,我是带签名的");

                               }

                               //制造token返回,token有效期为1小时,登陆时间存入application中

                               ServletContext application =request.getSession().getServletContext();

                               long currenttime = new Date().getTime();

                              application.setAttribute(deviceID+"logintime", currenttime);

                               token = MakeToken.getToken(deviceID);

                   }

                  returntoken;*/

                  //=================================

                   CXFXmlMessage   xml= new CXFXmlMessage();

                    for (Message message : messages) {

                            String token=null;

                            if(!deviceID.equals(message.getDeviceID())){

                                     xml.setResult(-1);

                                     xml.setErrorMessage("只开设备与设备操作员ID不正确");

                            }

                           if(deviceID.equals(message.getDeviceID())&&!signature.equals(message.getSignature())){

                                    xml.setResult(-2);

                                    xml.setErrorMessage("哥们你知道我的算法么,我是带签名的");

                            }

                            ServletContext application =request.getSession().getServletContext();

                           if(deviceID.equals(message.getDeviceID())&&signature.equals(message.getSignature())){

                                   //制造token返回,token有效期为1小时,登陆时间存入application中

                                     long currenttime = new Date().getTime();

                                    application.setAttribute(deviceID+"logintime", currenttime);

                                     token = MakeToken.getToken(deviceID);

                            }else{

                                     token="无法制造token";

                            }

                            xml.setToken(token);

                            //============================

                    }

                  returnxml;

         }

 

}

CXF获得httpservletrequest

import javax.xml.ws.WebServiceContext;

 

发布接口


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值