9d767a2670f1e5ac05cc7192bcc5751c5c0dd637.svn-base
6.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package com.thinkgem.jeesite.modules.rest.wsapi.dto.web;
import java.io.PrintWriter;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.thinkgem.jeesite.common.mapper.JaxbMapper;
import com.thinkgem.jeesite.common.mapper.JsonMapper;
import com.thinkgem.jeesite.common.utils.xml.JXmlUtils;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.reg.entity.base.RegBaseH;
import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusQlr;
import com.thinkgem.jeesite.modules.reg.entity.updata.RegBusSjhjtable;
import com.thinkgem.jeesite.modules.reg.service.bus.RegBusQlrService;
import com.thinkgem.jeesite.modules.reg.service.updata.RegBusSjhjtableService;
import com.thinkgem.jeesite.modules.rest.wsapi.dto.service.RestfulService;
import com.thinkgem.jeesite.modules.sys.web.LoginController;
@Controller
@RequestMapping(value = "${adminPath}/regService")
public class TestRestfulController extends BaseController {
@Autowired
private RestfulService restfulService;
@Autowired
private RegBusQlrService regBusQlrService;
@Autowired
private RegBusSjhjtableService regBusSjhjtableService;
@RequestMapping("display")
public ModelAndView helloWorld() {
String message = restfulService.getHelloWorld();
//logger.info(message);
return new ModelAndView("display", "message", message);
}
@RequestMapping(value="display/random")
@ResponseBody
public String displayJson() throws Exception{
int randomValue = restfulService.getRandomNumber();
Map<String,Object> map = new HashMap<String,Object>();
map.put("随机数", randomValue);
ObjectMapper objectMapper = new ObjectMapper();
String result = objectMapper.writeValueAsString(map);
return result;
}
@RequestMapping(value="display/hxml")
public @ResponseBody String displayUserWithXml(HttpServletResponse response, Model model) throws Exception{
//报文头部数据填充
RegBusSjhjtable regBusSjhjtable = new RegBusSjhjtable();
regBusSjhjtable.setBizmsgid("500115151030000025");
regBusSjhjtable.setAsid("AS100");
regBusSjhjtable.setAreacode("500115");
regBusSjhjtable.setRectype("2000402");
regBusSjhjtable.setRighttype("3");
regBusSjhjtable.setRegtype("100");
regBusSjhjtable.setCreatedate(new Date());
regBusSjhjtable.setRecflowid("201507011190001");
regBusSjhjtable.setRegorgid("500115");
regBusSjhjtable.setParcelid("500115001019GB00008");
regBusSjhjtable.setEstatenum("500115001019GB00008F00000064");
regBusSjhjtable.setPreestatenum("500115001019GB00008F00000064");
regBusSjhjtable.setPrecertid("汉2016证书000001");
regBusSjhjtable.setCertcount("12");
regBusSjhjtable.setProofcount("12");
regBusSjhjtable.setDigitalsign("6bfa32a846896c9cf6");
regBusSjhjtableService.save(regBusSjhjtable);
//获取权利人信息xml
RegBusQlr regBusQlr = regBusQlrService.get("016efb4bc6f74f8d91966134dbc1d219");
StringBuilder sbStr = new StringBuilder();
//报文头转化
String retHead = JaxbMapper.toXml(regBusSjhjtable, RegBusSjhjtable.class, "UTF-8");
//报文体-权利人信息转化
String retQlr = JaxbMapper.toXml(regBusQlr, RegBusQlr.class, "UTF-8");
sbStr.append(JXmlUtils.messageBStr).append(retHead.substring(56));
sbStr.append(JXmlUtils.dataBStr).append(retQlr.substring(56))
.append(JXmlUtils.dataEStr).append(JXmlUtils.messageEStr);
System.out.println(sbStr.toString());
//调用生成XML报文文件的函数,参数为生成文件名和要生成的内容字符串
JXmlUtils.strChangeXML("Biz500115151030000001", sbStr.toString());
return sbStr.toString();
}
@RequestMapping(value="display/hjson")
@ResponseBody
public String displayUserWithJson(HttpServletResponse response, Model model) throws Exception{
List<RegBaseH> regBaseHs = restfulService.getRegBaseH();
String ret = JsonMapper.toJsonString(regBaseHs);
//model.addAttribute("regBaseHs", ret);
//modelMap.put("regBaseHs", ret);//已经有已引用的户信息记录
return ret;
}
@RequestMapping(value="display/mydata")
public void displayUserWithJson(HttpServletRequest request, HttpServletResponse response) throws Exception{
response.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
String userName = request.getParameter("username");
String passWord = request.getParameter("password");
System.out.println("userName:"+userName);
System.out.println("passWord:"+passWord);
Subject currentUser = SecurityUtils.getSubject();
if (!currentUser.isAuthenticated()) {
//collect user principals and credentials in a gui specific manner
//such as username/password html form, X509 certificate, OpenID, etc.
//We'll use the username/password example here since it is the most common.
//(do you know what movie this is from? ;)
UsernamePasswordToken token = new UsernamePasswordToken(userName, passWord);
//this is all you have to do to support 'remember me' (no config - built in!):
token.setRememberMe(true);
LoginController loginc = new LoginController();
loginc.loginFail(request, response, null);
}
//调用应用中的登录函数
out.print("login successful!");
out.flush();
out.close();
}
}