package com.misys.hackathon.chatbot.controller;
import com.misys.hackathon.chatbot.model.AuthenticationMessage;
import com.misys.hackathon.chatbot.model.AuthenticationRq;
import com.misys.hackathon.chatbot.model.MessageQuote;
import com.misys.hackathon.chatbot.model.Messages;
import com.misys.hackathon.chatbot.model.authDCRq.*;
import com.misys.hackathon.chatbot.model.authDCRs.AuthenticationDCIdRs;
import com.misys.hackathon.chatbot.model.authDCRs.AuthenticationDCPassRs;
import com.misys.hackathon.chatbot.nlpProcessor.NlpProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.RequestEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import java.util.Arrays;
import java.util.List;
@RestController
@CrossOrigin("*")
public class MessagesController {
private int id = 2000;
RestTemplate restTemplate = new RestTemplate();
Logger logger = LoggerFactory.getLogger("MessagesController.class");
String userLocator = "";
String sessionId;
String dcUrl = "http://fr1csldcdev0013.misys.global.ad:9086/foundation-guiwar/security/pegasus_security_check";
@RequestMapping("/messages")
public Messages getMessages() {
RestTemplate restTemplate = new RestTemplate();
MessageQuote messageQuote = restTemplate.getForObject("http://localhost:3000/messages/1", MessageQuote.class);
logger.info("The message from JsonServer: " + messageQuote);
return new Messages(messageQuote.getId(), messageQuote.getText());
}
@RequestMapping(value = "/messages", method = RequestMethod.POST)
public Messages postMessage(@RequestBody MessageQuote messageQuote) {
MessageQuote messages = new MessageQuote();
NlpProcessor nlpProcessor = new NlpProcessor();
messages.setText(nlpProcessor.processMsg(messageQuote.getText()));
messages.setId(Integer.toString(id));
logger.info("The message from NlpProcessor: " + messages.getText());
return new Messages(messages.getId(), messages.getText());
}
@RequestMapping(value = "/security/loginuser", method = RequestMethod.POST)
public AuthenticationMessage postAuthenticateUsr(@RequestBody AuthenticationRq authenticationRq) {
HttpEntity<AuthenticationDCIdRs> authenticationDCIdResponse;
HttpEntity<AuthenticationDCPassRs> authenticationDCPassResponse;
AuthenticationMessage authenticationMessage = new AuthenticationMessage();
if (authenticationRq != null && !authenticationRq.getUserid().equals("") && !authenticationRq.getPassword().equals("")) {
authenticationDCIdResponse = authenticateUser(authenticationRq);
if (authenticationDCIdResponse != null && authenticationDCIdResponse.getBody() != null && authenticationDCIdResponse.getBody().isSuccess()) {
logger.info("DC user name authorized");
authenticationDCPassResponse = authenticatePass(authenticationRq);
if (authenticationDCPassResponse != null && authenticationDCPassResponse.getBody() != null && authenticationDCPassResponse.getBody().isSuccess()) {
logger.info("DC password authentication succeded");
userLocator = authenticationDCPassResponse.getBody().getHeader().getToken();
logger.info("Userlocator : "+userLocator);
authenticationMessage.setStatus("success");
authenticationMessage.setMessage("DC authentication succeded");
} else {
logger.info("failed : DC password authentication failed");
authenticationMessage.setStatus("fail");
authenticationMessage.setMessage("failed : DC authentication failed");
}
} else {
logger.info("user name authorization failure");
authenticationMessage.setMessage("user name authorization failure");
authenticationMessage.setStatus("failure");
}
}
return authenticationMessage;
}
private HttpEntity<AuthenticationDCIdRs> authenticateUser(AuthenticationRq authenticationRq) {
AuthenticationDCIdRq authenticationDCIdRq = new AuthenticationDCIdRq();
HttpEntity<AuthenticationDCIdRs> response;
//set Data
UserData userData = new UserData();
userData.setLoginID(authenticationRq.getUserid());
Data data = new Data();
data.setData(userData);
authenticationDCIdRq.setData(data);
//set header
Header header = new Header();
CaptchaData captchaData = new CaptchaData();
header.setConversationScopeId(1);
header.setUserInputCaptchaData(captchaData);
authenticationDCIdRq.setHeader(header);
//service call
HttpEntity<AuthenticationDCIdRq> request = new HttpEntity<>(authenticationDCIdRq);
response = restTemplate.exchange(dcUrl, HttpMethod.POST, request, AuthenticationDCIdRs.class);
List<String> cookie = response.getHeaders().get("Set-Cookie");
sessionId = Arrays.asList(cookie.get(0).split(";")).get(0);
logger.info("Set-Cookie: " + cookie.toString());
logger.info("Session Id: " + sessionId);
return response;
}
public HttpEntity<AuthenticationDCPassRs> authenticatePass(AuthenticationRq authenticationRq) {
AuthenticationDCPassRq authenticationDCPassRq = new AuthenticationDCPassRq();
AuthenticationMessage authenticationMessage = new AuthenticationMessage();
HttpEntity<AuthenticationDCPassRq> request = null;
HttpEntity<AuthenticationDCPassRs> response = null;
//set header
Header1 header1 = new Header1();
authenticationDCPassRq.setHeader(header1);
//set data
UserData1 userData1 = new UserData1();
userData1.setCredentials(authenticationRq.getPassword());
Data1 data = new Data1();
data.setData(userData1);
authenticationDCPassRq.setData(data);
//service call
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add("cookie", sessionId);
request = new HttpEntity(authenticationDCPassRq, httpHeaders);
response = restTemplate.exchange(dcUrl, HttpMethod.POST, request, AuthenticationDCPassRs.class);
return response;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
问答机器人
共22个文件
java:21个
xml:1个
需积分: 48 29 下载量 10 浏览量
2018-06-07
17:54:10
上传
评论 3
收藏 16KB ZIP 举报
温馨提示
一个比较简单的机器人自动问答系统,简单易用,概括性的描述了目前的问答系统,同时用示例做了一个小例子,可以直接用于实际应用。
资源推荐
资源详情
资源评论
收起资源包目录
chatbot-master.zip (22个子文件)
chatbot-master
src
test
java
com
misys
hackathon
chatbot
ChatbotApplicationTests.java 345B
main
java
com
misys
hackathon
chatbot
ChatbotApplication.java 321B
model
authDCRq
AuthenticationDCIdRq.java 480B
Data1.java 281B
CaptchaData.java 293B
AuthenticationDCPassRq.java 490B
UserData1.java 339B
InnerData.java 299B
Data.java 276B
Header1.java 572B
UserData.java 297B
Header.java 881B
MessageQuote.java 698B
AuthenticationMessage.java 456B
authDCRs
AuthenticationDCIdRs.java 411B
AuthenticationDCPassRs.java 576B
Header.java 260B
AuthenticationRq.java 471B
Messages.java 538B
controller
MessagesController.java 6KB
nlpProcessor
NlpProcessor.java 3KB
pom.xml 2KB
共 22 条
- 1
资源评论
小伊xy
- 粉丝: 1
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功