implemented openIR with session_id

This commit is contained in:
strawmanbobi
2019-01-05 19:18:23 +08:00
parent 967245c2d7
commit 105bdecb02
6 changed files with 84 additions and 25 deletions

View File

@@ -18,10 +18,10 @@ public interface IDecodeSessionRepository {
Map<Object, Object> findAllDecodeSessions();
void add(DecodeSession decodeSession);
void add(String decodeSessionId, Integer remoteId);
void delete(Integer id);
void delete(String decodeSessionId);
DecodeSession find(Integer id);
Integer find(String decodeSessionId);
}

View File

@@ -37,16 +37,16 @@ public class DecodeSessionRepositoryImpl implements IDecodeSessionRepository {
hashOperations = redisTemplate.opsForHash();
}
public void add(final DecodeSession decodeSession) {
hashOperations.put(KEY, decodeSession.getId(), decodeSession.getName());
public void add(final String decodeSessionId, Integer binaryId) {
hashOperations.put(KEY, decodeSessionId, binaryId);
}
public void delete(final Integer id) {
hashOperations.delete(KEY, id);
public void delete(String decodeSessionId) {
hashOperations.delete(KEY, decodeSessionId);
}
public DecodeSession find(final Integer id) {
return (DecodeSession) hashOperations.get(KEY, id);
public Integer find(String decodeSessionId) {
return (Integer) hashOperations.get(KEY, decodeSessionId);
}
public Map<Object, Object> findAllDecodeSessions() {

View File

@@ -12,31 +12,31 @@ package net.irext.decoder.model;
*/
public class DecodeSession {
private Integer id;
private String name;
private String sessionId;
private Integer binaryId;
public DecodeSession(Integer id, String name) {
this.id = id;
this.name = name;
public DecodeSession(String sessionId, Integer binaryId) {
this.sessionId = sessionId;
this.binaryId = binaryId;
}
public DecodeSession() {
}
public Integer getId() {
return id;
public String getSessionId() {
return sessionId;
}
public void setId(Integer id) {
this.id = id;
public void setSessionId(String sessionId) {
this.sessionId = sessionId;
}
public String getName() {
return name;
public Integer getBinaryId() {
return binaryId;
}
public void setName(String name) {
this.name = name;
public void setBinaryId(Integer binaryId) {
this.binaryId = binaryId;
}
}

View File

@@ -18,6 +18,7 @@ public class DecodeRequest {
private ACStatus acStatus;
private int keyCode;
private int changeWindDir;
private String sessionId;
public DecodeRequest(int indexId, ACStatus acStatus, int keyCode, int changeWindDir) {
this.indexId = indexId;
@@ -61,4 +62,12 @@ public class DecodeRequest {
public void setChangeWindDir(int changeWindDir) {
this.changeWindDir = changeWindDir;
}
public String getSessionId() {
return sessionId;
}
public void setSessionId(String sessionId) {
this.sessionId = sessionId;
}
}

View File

@@ -0,0 +1,34 @@
package net.irext.decoder.response;
/**
* Filename: StringResponse.java
* Revised: Date: 2017-05-16
* Revision: Revision: 1.0
* <p>
* Description: String response
* <p>
* Revision log:
* 2017-05-16: created by strawmanbobi
*/
public class StringResponse extends ServiceResponse {
private String entity;
public StringResponse(Status status, String entity) {
super(status);
this.entity = entity;
}
public StringResponse() {
}
public String getEntity() {
return entity;
}
public void setEntity(String entity) {
this.entity = entity;
}
}

View File

@@ -3,6 +3,7 @@ package net.irext.decoder.service;
import net.irext.decoder.businesslogic.DecodeLogic;
import net.irext.decoder.businesslogic.IndexLogic;
import net.irext.decoder.mapper.RemoteIndexMapper;
import net.irext.decoder.model.DecodeSession;
import net.irext.decoder.model.RemoteIndex;
import net.irext.decoder.cache.IDecodeSessionRepository;
import net.irext.decoder.cache.IIRBinaryRepository;
@@ -12,8 +13,10 @@ import net.irext.decoder.request.OpenRequest;
import net.irext.decoder.response.DecodeResponse;
import net.irext.decoder.response.ServiceResponse;
import net.irext.decoder.response.Status;
import net.irext.decoder.response.StringResponse;
import net.irext.decoder.service.base.AbstractBaseService;
import net.irext.decoder.utils.LoggerUtil;
import net.irext.decoder.utils.MD5Util;
import net.irext.decodesdk.bean.ACStatus;
import net.irext.decodesdk.utils.Constants;
import org.springframework.beans.factory.annotation.Autowired;
@@ -21,6 +24,8 @@ import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
/**
* Filename: IRDecodeService.java
@@ -55,16 +60,17 @@ public class IRDecodeService extends AbstractBaseService {
}
@PostMapping("/open")
public ServiceResponse irOpen(@RequestBody OpenRequest openRequest) {
public StringResponse irOpen(HttpServletRequest request, @RequestBody OpenRequest openRequest) {
try {
int remoteIndexId = openRequest.getRemoteIndexId();
LoggerUtil.getInstance().trace(TAG,"irOpen API called : " + remoteIndexId);
ServiceResponse response = new ServiceResponse();
StringResponse response = new StringResponse();
RemoteIndex remoteIndex = IndexLogic.getInstance(remoteIndexMapper).getRemoteIndex(remoteIndexId);
if (null == remoteIndex) {
response.setStatus(new Status(Constants.ERROR_CODE_NETWORK_ERROR, ""));
response.setEntity(null);
return response;
} else {
LoggerUtil.getInstance().trace(TAG, "remoteIndex get : " + remoteIndex.getId() + ", " +
@@ -74,12 +80,21 @@ public class IRDecodeService extends AbstractBaseService {
if (null != binaryContent) {
LoggerUtil.getInstance().trace(TAG,"binary content fetched : " + binaryContent.length);
// construct a session with this binary
String address = request.getRemoteAddr();
LoggerUtil.getInstance().trace(TAG, "request Address = " + address);
String timeStamp =
new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new java.util.Date());
String sessionId = MD5Util.MD5Encode(address + timeStamp, null);
DecodeSession decodeSession = new DecodeSession(sessionId, remoteIndex.getId());
decodeSessionRepository.add(decodeSession.getSessionId(), decodeSession.getBinaryId());
response.setEntity(decodeSession.getSessionId());
}
response.setStatus(new Status(Constants.ERROR_CODE_SUCCESS, ""));
return response;
} catch (Exception e) {
e.printStackTrace();
return getExceptionResponse(DecodeResponse.class);
return getExceptionResponse(StringResponse.class);
}
}
@@ -90,6 +105,7 @@ public class IRDecodeService extends AbstractBaseService {
ACStatus acstatus = decodeRequest.getAcStatus();
int keyCode = decodeRequest.getKeyCode();
int changeWindDir = decodeRequest.getChangeWindDir();
String sessionId = decodeRequest.getSessionId();
DecodeResponse response = new DecodeResponse();
int[] irArray = DecodeLogic.getInstance().decode();