Skip to content

Commit

Permalink
외부 요청 URI property로 변경 iotoasis#287
Browse files Browse the repository at this point in the history
  • Loading branch information
pahnjy01 committed Dec 6, 2016
1 parent 1f2d433 commit 28f38c7
Show file tree
Hide file tree
Showing 24 changed files with 161 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public int retrieveCurrentValue(Domain domain) {
// contextAddress = ContextAddress.newContextAddress();
logger.info(LogPrint.outputInfoLogPrint());
IHttpResponseMessage message = clientService.requestGetService
(contextAddress.getAddress() + AddressStore.RETRIEVE_CURRENT_VALUE + "/" + domain.getName());
(contextAddress.getSDAAddress() + AddressStore.RETRIEVE_CURRENT_VALUE + "/" + domain.getName());
String response = new Gson().toJson(message);
int currentValue = Integer.parseInt(response);
return currentValue;
Expand All @@ -52,7 +52,7 @@ public int retrievePastValue(Domain domain) {
// contextAddress = ContextAddress.newContextAddress();
logger.info(LogPrint.outputInfoLogPrint());
IHttpResponseMessage message = clientService.requestGetService(
contextAddress.getAddress() + AddressStore.RETRIEVE_PAST_VALUE + "/" + domain.getName());
contextAddress.getSDAAddress() + AddressStore.RETRIEVE_PAST_VALUE + "/" + domain.getName());
String response = new Gson().toJson(message);
int pastValue = Integer.parseInt(response);
return pastValue;
Expand All @@ -65,7 +65,7 @@ public int retrieveAllDeviceUseAmount(Domain domain) {
// contextAddress = ContextAddress.newContextAddress();
logger.info(LogPrint.outputInfoLogPrint());
IHttpResponseMessage message = clientService.requestGetService(
contextAddress.getAddress() + AddressStore.RETRIEVE_USE_AMOUNT + "/" + domain.getName());
contextAddress.getSDAAddress() + AddressStore.RETRIEVE_USE_AMOUNT + "/" + domain.getName());
String response = new Gson().toJson(message);
int useAmount = Integer.parseInt(response);
return useAmount;
Expand All @@ -77,7 +77,7 @@ public int retrieveObjectValue(Domain domain) {
//
// contextAddress = ContextAddress.newContextAddress();
IHttpResponseMessage message = clientService.requestGetService(
contextAddress.getAddress() + AddressStore.RETRIEVE_OBJECT_VALUE + "/" + domain.getName());
contextAddress.getSDAAddress() + AddressStore.RETRIEVE_OBJECT_VALUE + "/" + domain.getName());
String response = new Gson().toJson(message);
int objectValue = Integer.parseInt(response);
return objectValue;
Expand All @@ -90,7 +90,7 @@ public int retrieveCurrentClassPCAmount(Domain domain) {
// contextAddress = ContextAddress.newContextAddress();
logger.info(LogPrint.outputInfoLogPrint());
IHttpResponseMessage message = clientService.requestGetService(
contextAddress.getAddress() + AddressStore.RETRIEVE_CURRENT_PC + "/" + domain.getName());
contextAddress.getSDAAddress() + AddressStore.RETRIEVE_CURRENT_PC + "/" + domain.getName());
String response = new Gson().toJson(message);
int currentPC = Integer.parseInt(response);
return currentPC;
Expand All @@ -103,7 +103,7 @@ public int retrieveNextClassPCAmount(Domain domain) {
// contextAddress = ContextAddress.newContextAddress();
logger.info(LogPrint.outputInfoLogPrint());
IHttpResponseMessage message = clientService.requestGetService(
contextAddress.getAddress() + AddressStore.RETRIEVE_NEXT_PC + "/" + domain.getName());
contextAddress.getSDAAddress() + AddressStore.RETRIEVE_NEXT_PC + "/" + domain.getName());
String response = new Gson().toJson(message);
int nextPC = Integer.parseInt(response);
return nextPC;
Expand All @@ -116,7 +116,7 @@ public int retrieveCurrentClassMouseAmount(Domain domain) {
// contextAddress = ContextAddress.newContextAddress();
logger.info(LogPrint.outputInfoLogPrint());
IHttpResponseMessage message = clientService.requestGetService(
contextAddress.getAddress() + AddressStore.RETRIEVE_CURRENT_MOUSE + "/" + domain.getName());
contextAddress.getSDAAddress() + AddressStore.RETRIEVE_CURRENT_MOUSE + "/" + domain.getName());
String response = new Gson().toJson(message);
int currentMouse = Integer.parseInt(response);
return currentMouse;
Expand All @@ -129,7 +129,7 @@ public int retrieveNextClassMouseAmount(Domain domain) {
// contextAddress = ContextAddress.newContextAddress();
logger.info(LogPrint.outputInfoLogPrint());
IHttpResponseMessage message = clientService.requestGetService(
contextAddress.getAddress() + AddressStore.RETRIEVE_NEXT_MOUSE + "/" + domain.getName());
contextAddress.getSDAAddress() + AddressStore.RETRIEVE_NEXT_MOUSE + "/" + domain.getName());
String response = new Gson().toJson(message);
int nextMouse = Integer.parseInt(response);
return nextMouse;
Expand All @@ -142,7 +142,7 @@ public int retrieveCurrentClassKeyBoardAmount(Domain domain) {
// contextAddress = ContextAddress.newContextAddress();
logger.info(LogPrint.outputInfoLogPrint());
IHttpResponseMessage message = clientService.requestGetService(
contextAddress.getAddress() + AddressStore.RETRIEVE_CURRENT_KEYBOARD + "/" + domain.getName());
contextAddress.getSDAAddress() + AddressStore.RETRIEVE_CURRENT_KEYBOARD + "/" + domain.getName());
String response = new Gson().toJson(message);
int currentKeyBoard = Integer.parseInt(response);
return currentKeyBoard;
Expand All @@ -155,7 +155,7 @@ public int retrieveNextClassKeyBoardAmount(Domain domain) {
// contextAddress = ContextAddress.newContextAddress();
logger.info(LogPrint.outputInfoLogPrint());
IHttpResponseMessage message = clientService.requestGetService(
contextAddress.getAddress() + AddressStore.RETRIEVE_NEXT_KEYBOARD + "/" + domain.getName());
contextAddress.getSDAAddress() + AddressStore.RETRIEVE_NEXT_KEYBOARD + "/" + domain.getName());
String response = new Gson().toJson(message);
int nextKeyBoard = Integer.parseInt(response);
return nextKeyBoard;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.pineone.icbms.so.contextinformation.entity.ContextInformation;
import com.pineone.icbms.so.contextinformation.pr.ContextInformationPresentation;
import com.pineone.icbms.so.util.address.AddressStore;
import com.pineone.icbms.so.util.address.ContextAddress;
import com.pineone.icbms.so.util.conversion.DataConversion;
Expand Down Expand Up @@ -45,7 +44,7 @@ public String registerContextInformation(ContextInformation contextInformation){
logger.debug("ContextInformation = " + contextInformation.toString());
// contextAddress = ContextAddress.newContextAddress();
IHttpResponseMessage message = clientService.requestPostService
(contextAddress.getAddress() + AddressStore.REGISTER_CONTEXTINFORMATION, sendData);
(contextAddress.getSDAAddress() + AddressStore.REGISTER_CONTEXTINFORMATION, sendData);
String response = new Gson().toJson(message);
return response;
}
Expand All @@ -55,7 +54,7 @@ public List<String> retrieveContextInformationListFromSDA(){
//
logger.info(LogPrint.outputInfoLogPrint());
IHttpResponseMessage message = clientService.requestGetService(
contextAddress.getAddress() + AddressStore.RETRIEVE_CONTEXTINFORMATION);
contextAddress.getSDAAddress() + AddressStore.RETRIEVE_CONTEXTINFORMATION);
String readData = new Gson().toJson(message);
Type type = new TypeToken<List<String>>(){}.getType();
List<String> contextInformationNameList = new Gson().fromJson(readData,type);
Expand All @@ -68,7 +67,7 @@ public ContextInformation retrieveGeneralContextDetail(String contextId){
logger.info(LogPrint.outputInfoLogPrint());
logger.debug("ContextId = " + contextId);
IHttpResponseMessage message = clientService.requestGetService(
contextAddress.getAddress() + AddressStore.RETRIEVE_CONTEXTINFORMATION + "/" + contextId);
contextAddress.getSDAAddress() + AddressStore.RETRIEVE_CONTEXTINFORMATION + "/" + contextId);
String readData = new Gson().toJson(message);
Type type = new TypeToken<ContextInformation>(){}.getType();
ContextInformation contextInformation = new Gson().fromJson(readData,type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ public String registerContextModel(ContextModel contextModel) {
logger.debug("ContextModel = " + contextModel.toString());

String sendData = DataConversion.objectToString(contextModel);
IHttpResponseMessage message = clientService.requestPostService
(contextAddress.getAddress() + AddressStore.REGISTER_CONTEXTMODEL, sendData);
String response = DataConversion.responseDataToString(message);
String response = clientService.requestPostServiceReceiveString(contextAddress.getSDAAddress() + AddressStore.REGISTER_CONTEXTMODEL, sendData);
return response;
}

Expand All @@ -61,7 +59,7 @@ public List<ContextModel> retrieveContextModelListFromSDA() {
//
logger.info(LogPrint.outputInfoLogPrint());
IHttpResponseMessage message = clientService.requestGetService(
contextAddress.getAddress() + AddressStore.RETRIEVE_CONTEXTMODEL);
contextAddress.getSDAAddress() + AddressStore.RETRIEVE_CONTEXTMODEL);
String readData = new Gson().toJson(message);
Type type = new TypeToken<List<ContextModel>>(){}.getType();
List<ContextModel> contextModelList = new Gson().fromJson(readData,type);
Expand All @@ -75,9 +73,7 @@ public ContextModel retrieveContextModelDetail(String contextModelId) {
//
logger.info(LogPrint.outputInfoLogPrint() + ", ContextModelId = " + contextModelId);
logger.debug("ContextModelId = " + contextModelId);
IHttpResponseMessage message = clientService.requestGetService(
contextAddress.getAddress() + AddressStore.RETRIEVE_CONTEXTMODEL + "/" + contextModelId);
String readData = DataConversion.responseDataToString(message);
String readData = clientService.requestGetServiceReceiveString(contextAddress.getSDAAddress() + AddressStore.RETRIEVE_CONTEXTMODEL + "/" + contextModelId);
Type type = new TypeToken<ContextModel>(){}.getType();
ContextModel contextModel = new Gson().fromJson(readData, type);

Expand All @@ -92,7 +88,7 @@ public List<String> retrieveContextModelEvent(String contextModelId) {

//
// IHttpResponseMessage message = clientService.requestGetService(
// contextAddress.getAddress() + AddressStore.RETRIEVE_CONTEXTMODEL_EVENT + "/" + contextModelName);
// contextAddress.getSDAAddress() + AddressStore.RETRIEVE_CONTEXTMODEL_EVENT + "/" + contextModelName);
// String readData = new Gson().toJson(message);
// Type type = new TypeToken<List<String>>(){}.getType();
// List<String> domainIdList = new Gson().fromJson(readData,type);
Expand Down Expand Up @@ -223,11 +219,11 @@ public List<String> retrieveContextModelEvent(String contextModelId) {

private List<Content> getContents(String contextModelId) throws BadRequestException {
IHttpResponseMessage message = clientService.requestGetService(
contextAddress.getAddress() + contextModelId + "/?p=," );
contextAddress.getSDAAddress() + contextModelId + "/?p=," );
if(message.getStatusCode() == 200) {
System.out.println(message.getBodyByteArray().toString());
logger.debug("ResponseMessage : " + message);
String readData = DataConversion.responseDataToString(message);
String readData = clientService.responseDataToString(message);
Type type = new TypeToken<RetrieveData>() {
}.getType();
RetrieveData retrieveData = new Gson().fromJson(readData, type);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.pineone.icbms.so.device.store.DeviceResultStore;
import com.pineone.icbms.so.device.store.DeviceStore;
import com.pineone.icbms.so.device.util.ClientProfile;
import com.pineone.icbms.so.util.address.AddressStore;
import com.pineone.icbms.so.util.address.ContextAddress;
import com.pineone.icbms.so.util.conversion.DataConversion;
import com.pineone.icbms.so.util.logprint.LogPrint;
import com.pineone.icbms.so.util.session.DefaultSession;
Expand Down Expand Up @@ -44,13 +46,16 @@ public class DeviceManagerLogic implements DeviceManager {
@Autowired
private DeviceControlProxy deviceControlProxy;

@Autowired
ContextAddress contextAddress;

@Override
public void deviceRegister(String deviceUri, String time){
// NOTE : 디바이스 생성.
logger.debug("Device Uri = " + deviceUri + " Time = " + time);
// 디바이스 ID로 SDA에 데이터 요청.
// TODO: SDA에 Device Uri만으로 Device정보 연동 규격 필요.
Device device = deviceRequest(ClientProfile.SDA_DATAREQUEST_URI + ClientProfile.SDA_DEVICE + deviceUri);
Device device = deviceRequest(contextAddress.getSIAddress() + AddressStore.SDA_DEVICE + deviceUri);
logger.debug("Device = " + device.toString());
// 디바이스 저장.
deviceCreate(device);
Expand Down Expand Up @@ -121,7 +126,7 @@ public String deviceExecute(String deviceId,String deviceCommand, String session
}

// Device 제어 요청 보냄.
ResultMessage resultMessage = deviceControlProxy.deviceControlRequest(ClientProfile.SI_CONTOL_URI,deviceControlMessage);
ResultMessage resultMessage = deviceControlProxy.deviceControlRequest(contextAddress.getSIAddress() + AddressStore.SI_CONTOL_URI,deviceControlMessage);
logger.debug(LogPrint.LogMethodNamePrint() + " | Device Control Result : " + " , Device Uri = " + device.getDeviceUri() + " , Result : " + resultMessage + " , Session ID = " + sessionId);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public Device findDeviceById(@PathVariable String deviceId){
// Search Device By Id
logger.info(LogPrint.inputInfoLogPrint() + "DeviceID = " + deviceId);
Device device = deviceManager.deviceSearchById(deviceId);
logger.debug("Devoce = " + deviceId.toString());
logger.debug("Device ID = " + deviceId);
return device;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package com.pineone.icbms.so.device.proxy;

import com.pineone.icbms.so.device.entity.Device;
import com.pineone.icbms.so.device.util.ClientProfile;
import com.pineone.icbms.so.util.address.AddressStore;
import com.pineone.icbms.so.util.address.ContextAddress;
import com.pineone.icbms.so.util.http.ClientService;
import com.pineone.icbms.so.util.logprint.LogPrint;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;
import org.json.simple.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
Expand All @@ -31,6 +33,10 @@ public class DeviceSDAProxy implements DeviceICollectionProxy {

public static final Logger logger = LoggerFactory.getLogger(DeviceSDAProxy.class);

@Autowired
ContextAddress contextAddress;


/**
* 1. Domain 조회(get)
* @param requestUri
Expand Down Expand Up @@ -129,7 +135,7 @@ public String findDeviceOperation(String deviceId, String deviceService) {
logger.info((LogPrint.outputInfoLogPrint())+ "DeviceID = " + deviceId);
logger.debug("DeviceID = " + deviceId + "DeviceService = " + deviceService);

String requestUri = ClientProfile.SDA_DATAREQUEST_URI + ClientProfile.SDA_DEVICE + ClientProfile.SDA_DEVICE_OPERATION;
String requestUri = contextAddress.getSDAAddress() + AddressStore.SDA_DEVICE + AddressStore.SDA_DEVICE_OPERATION;
JSONObject obj = new JSONObject();
obj.put("deviceId", deviceId);
obj.put("deviceService", deviceService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
import com.pineone.icbms.so.device.entity.DeviceSubscriptionData;
import com.pineone.icbms.so.device.entity.ResultMessage;
import com.pineone.icbms.so.device.util.ClientProfile;
import com.pineone.icbms.so.util.address.AddressStore;
import com.pineone.icbms.so.util.address.ContextAddress;
import com.pineone.icbms.so.util.http.ClientService;
import com.pineone.icbms.so.util.logprint.LogPrint;
import org.codehaus.jackson.map.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
Expand All @@ -28,6 +31,9 @@ public class DeviceSIProxy implements DeviceControlProxy {
private ClientService clientService = new ClientService();
private ObjectMapper mapper = new ObjectMapper();

@Autowired
ContextAddress contextAddress;

public static final Logger logger = LoggerFactory.getLogger(DeviceSIProxy.class);

@Override
Expand Down Expand Up @@ -57,14 +63,14 @@ public String deviceSubscriptionRequest(String deviceUri) {
logger.debug(LogPrint.LogMethodNamePrint() + " | DeviceUri = " + deviceUri);

DeviceSubscriptionData deviceSubscriptionData = new DeviceSubscriptionData();
deviceSubscriptionData.set_notificationUri(ClientProfile.SO_DEVICE_STATUS_URI);
deviceSubscriptionData.set_notificationUri(contextAddress.getSOAddress() + AddressStore.SO_DEVICE_STATUS);
deviceSubscriptionData.set_uri(deviceUri);

String requestBody = new Gson().toJson(deviceSubscriptionData);
// DeviceLogic에 생성되거나 제어되면 서브스크립트 걸어야 겠군.
// 현제 정책이 안되어 있어서. 등록되면 걸지.. 제어시 걸지는 고려 필요.

String responseData = clientService.requestPostServiceReceiveString(ClientProfile.SI_SUBSCRIPTION_URI, requestBody);
String responseData = clientService.requestPostServiceReceiveString(contextAddress.getSIAddress() + AddressStore.SI_SUBSCRIPTION_URI, requestBody);
// ResponseData{ "code" : "2000", "message" : "", "content" : "" }
logger.debug(LogPrint.LogMethodNamePrint() + " | Subscription Request : Response Data = " + responseData);
ResultMessage resultMessage = new ResultMessage();
Expand All @@ -91,8 +97,7 @@ public String deviceSubscriptionReleaseRequest(String deviceUri) {
String requestBody = new Gson().toJson(deviceSubscriptionData);
// DeviceLogic에 생성되거나 제어되면 서브스크립트 걸어야 겠군.
// 현제 정책이 안되어 있어서. 등록되면 걸지.. 제어시 걸지는 고려 필요.

String responseData = clientService.requestPostServiceReceiveString(ClientProfile.SI_SUBSCRIPTION_RELEASE_URI, requestBody);
String responseData = clientService.requestPostServiceReceiveString(contextAddress.getSIAddress() + AddressStore.SI_SUBSCRIPTION_RELEASE_URI, requestBody);
logger.debug(LogPrint.LogMethodNamePrint() + " | Device SubscriptionRelease Request Result = " + responseData);
logger.info("<================ Device SubscriptionRelease Request End ================>");
return responseData;
Expand Down
Loading

0 comments on commit 28f38c7

Please sign in to comment.