发布接口的写法



@Controller
public class webservicePubApi {
@Reference
private SysUserDubboService sysUserDubboService;
@RequestMapping(method=RequestMethod.POST, value="/sso/validaty")
@ResponseBody
private ResParam checkUserInfoForSpe(@RequestBody(required=true) ReqParam reqParam, HttpServletRequest request,
            HttpServletResponse response){
ResParam res = new ResParam();
res.setResult(-1);
String created = reqParam.getCreated();
String token = reqParam.getToken();
String remark = reqParam.getDigest();
String source = reqParam.getSource();
Subject currentUser = SecurityUtils.getSubject();
SysUser user = SessionUtils.getUser();
String sessionId = currentUser.getSession().getId().toString();
String[] mark = DES.getUnDes(remark).split("#"); 
Date reqDate = new Date();
try {
reqDate = org.apache.commons.lang3.time.DateUtils.parseDate(created, "yyyy-MM-dd hh:mm:ss");
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Date nowDate = org.apache.commons.lang.time.DateUtils.addMinutes(new Date(), -2);
boolean timeFlag = DateUtils.before(nowDate, reqDate);
if(!timeFlag){
if(sessionId.equals(token)&&user!=null){
//验证通过
//判定接入端密码是否正确
if("speit".equals(mark[2])){
SysUser sysUser = sysUserDubboService.getSysUserInfoByLoginName(user.getLoginName());
res.setLoginName(user.getLoginName());
res.setEmail(sysUser.getEmail());
res.setTelephone(sysUser.getTelephone());
res.setResult(0);
}
}
}
return res;

}





@XmlRootElement(name = "ReqParam")
public class ReqParam {
private String created;
private String token;
private String source;
private String digest;
@XmlElement
public String getCreated() {
return created;
}
public void setCreated(String created) {
this.created = created;
}
@XmlElement
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
@XmlElement
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
@XmlElement
public String getDigest() {
return digest;
}
public void setDigest(String digest) {
this.digest = digest;
}
}


web.xml

  <servlet>
<servlet-name>rest</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>  
            <param-name>contextConfigLocation</param-name>  
            <param-value>classpath:rest-servlet.xml</param-value>  
        </init-param>  
<load-on-startup>1</load-on-startup>
</servlet>


<servlet-mapping>
<servlet-name>rest</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
  



rest-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">


    <mvc:annotation-driven />
    <context:component-scan base-package="com.hongguaninfo.ffwb.forward.web" />
    <mvc:resources mapping="/resources/**" location="/resources/" />




    <bean
        class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
        <property name="order" value="1" />
        <property name="favorParameter" value="false" />
        <property name="ignoreAcceptHeader" value="true" />
        <property name="defaultContentType" value="text/html" />
        <property name="mediaTypes">
            <map>
                <entry key="json" value="application/json" />
                <entry key="xml" value="application/xml" />
            </map>
        </property>
       
        <property name="defaultViews">
            <list>
                <bean id="jsonView"
                    class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" />
                <bean id="xmlView"
                    class="org.springframework.web.servlet.view.xml.MarshallingView">
                    <constructor-arg>
                        <bean class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
                            <property name="classesToBeBound">
                                <list>
                                    <value>com.hongguaninfo.ffwb.forward.entity.ReqParam</value>
                                    <value>com.hongguaninfo.ffwb.forward.entity.ResParam</value>
                                </list>
                            </property>
                        </bean>
                    </constructor-arg>
                </bean>
            </list>
        </property>
    </bean>


</beans>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值