데이터 분할 전송 중 예외가 발생하는 경우 예외 정보를 데이터셋으로 전달하도록 수정 (구현이 안되어 있었음)
This commit is contained in:
@@ -155,11 +155,10 @@ public class NexacroView extends AbstractView {
|
|||||||
private void sendFirstRowData(PlatformData platformData, NexacroFirstRowHandler firstRowHandler, boolean isCallEndMethod)
|
private void sendFirstRowData(PlatformData platformData, NexacroFirstRowHandler firstRowHandler, boolean isCallEndMethod)
|
||||||
throws PlatformException {
|
throws PlatformException {
|
||||||
|
|
||||||
|
setFirstRowStatusDataSet(platformData);
|
||||||
|
|
||||||
removeTransferData(firstRowHandler, platformData);
|
removeTransferData(firstRowHandler, platformData);
|
||||||
|
|
||||||
// add first row status DataSet
|
|
||||||
platformData.addDataSet(NexacroUtil.createFirstRowStatusDataSet(NexacroConstants.ERROR.DEFAULT_ERROR_CODE, null));
|
|
||||||
|
|
||||||
if(logger.isDebugEnabled()) {
|
if(logger.isDebugEnabled()) {
|
||||||
logger.debug("response platformdata=[{}]", new Debugger().detail(platformData));
|
logger.debug("response platformdata=[{}]", new Debugger().detail(platformData));
|
||||||
}
|
}
|
||||||
@@ -168,6 +167,21 @@ public class NexacroView extends AbstractView {
|
|||||||
NexacroFirstRowAccessor.end(firstRowHandler);
|
NexacroFirstRowAccessor.end(firstRowHandler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setFirstRowStatusDataSet(PlatformData platformData){
|
||||||
|
|
||||||
|
Variable errorCodeVariable = platformData.getVariable(NexacroConstants.ERROR.ERROR_CODE);
|
||||||
|
if(errorCodeVariable != null && errorCodeVariable.getInt() < 0) {
|
||||||
|
// error status
|
||||||
|
Variable errorMsgVariable = platformData.getVariable(NexacroConstants.ERROR.ERROR_MSG);
|
||||||
|
platformData.addDataSet(NexacroUtil.createFirstRowStatusDataSet(errorCodeVariable.getInt(), errorMsgVariable != null? errorMsgVariable.getString(): null));
|
||||||
|
} else {
|
||||||
|
// success status
|
||||||
|
platformData.addDataSet(NexacroUtil.createFirstRowStatusDataSet(NexacroConstants.ERROR.DEFAULT_ERROR_CODE, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Statements
|
* Statements
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|||||||
import com.nexacro.xapi.data.DataSet;
|
import com.nexacro.xapi.data.DataSet;
|
||||||
import com.nexacro.xapi.data.PlatformData;
|
import com.nexacro.xapi.data.PlatformData;
|
||||||
import com.nexacro.xapi.data.Variable;
|
import com.nexacro.xapi.data.Variable;
|
||||||
|
import com.nexacro.xapi.data.datatype.PlatformDataType;
|
||||||
import com.nexacro.xapi.tx.DataDeserializer;
|
import com.nexacro.xapi.tx.DataDeserializer;
|
||||||
import com.nexacro.xapi.tx.DataSerializerFactory;
|
import com.nexacro.xapi.tx.DataSerializerFactory;
|
||||||
import com.nexacro.xapi.tx.PlatformException;
|
import com.nexacro.xapi.tx.PlatformException;
|
||||||
@@ -33,9 +34,6 @@ import com.nexacro.xapi.tx.PlatformType;
|
|||||||
@ContextConfiguration(locations = { "classpath*:spring/context-*.xml" } )
|
@ContextConfiguration(locations = { "classpath*:spring/context-*.xml" } )
|
||||||
public class NexacroFirstRowHandlerTest {
|
public class NexacroFirstRowHandlerTest {
|
||||||
|
|
||||||
// @Autowired
|
|
||||||
// private LargeDataService largeService;
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
}
|
}
|
||||||
@@ -44,6 +42,54 @@ public class NexacroFirstRowHandlerTest {
|
|||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testSendDataSet() {
|
||||||
|
|
||||||
|
FirstRowTrackableServletOutputStream outputStream = new FirstRowTrackableServletOutputStream();
|
||||||
|
NexacroFirstRowHandler firstRowHandler = createFirstRowHandler(outputStream);
|
||||||
|
|
||||||
|
String sendDataSetName = "ds1";
|
||||||
|
DataSet ds = new DataSet(sendDataSetName);
|
||||||
|
ds.addColumn("column1", PlatformDataType.INT);
|
||||||
|
ds.addColumn("column2", PlatformDataType.STRING);
|
||||||
|
|
||||||
|
int dataCount = 1000;
|
||||||
|
for(int i=0; i<dataCount; i++) {
|
||||||
|
int newRow = ds.newRow();
|
||||||
|
ds.set(newRow, "column1", i);
|
||||||
|
ds.set(newRow, "column2", "string"+i);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
firstRowHandler.sendDataSet(ds);
|
||||||
|
} catch (PlatformException e) {
|
||||||
|
Assert.fail("send dataset failed. e=" + e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// end tag
|
||||||
|
try {
|
||||||
|
NexacroFirstRowAccessor.end(firstRowHandler);
|
||||||
|
} catch (PlatformException e) {
|
||||||
|
Assert.fail("fail. call end method. e=" + e);
|
||||||
|
}
|
||||||
|
|
||||||
|
PlatformData platformData = readPlatformData(outputStream);
|
||||||
|
|
||||||
|
Assert.assertNotNull("first row function is not work. check it.", platformData);
|
||||||
|
|
||||||
|
DataSet sendedDataSet = platformData.getDataSet(sendDataSetName);
|
||||||
|
Assert.assertNotNull("first row function is not work. check it.", sendedDataSet);
|
||||||
|
|
||||||
|
int actualRowCount = sendedDataSet.getRowCount();
|
||||||
|
int expectedRowCount = dataCount;
|
||||||
|
Assert.assertEquals("sended row count not same.", expectedRowCount, actualRowCount);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSendPlatformType() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSendVariableAfterSendDataSet() {
|
public void testSendVariableAfterSendDataSet() {
|
||||||
|
|
||||||
@@ -65,54 +111,6 @@ public class NexacroFirstRowHandlerTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
|
||||||
public void testFirstRowIbatis() {
|
|
||||||
boolean useJdbcTemplate = false;
|
|
||||||
doCallService(useJdbcTemplate);
|
|
||||||
}
|
|
||||||
|
|
||||||
// @Test
|
|
||||||
public void testFirstRowJdbcTemplate() {
|
|
||||||
boolean useJdbcTemplate = true;
|
|
||||||
doCallService(useJdbcTemplate);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void doCallService(boolean useJdbcTemplate) {
|
|
||||||
|
|
||||||
FirstRowTrackableServletOutputStream outputStream = new FirstRowTrackableServletOutputStream();
|
|
||||||
NexacroFirstRowHandler firstRowHandler = createFirstRowHandler(outputStream);
|
|
||||||
|
|
||||||
String sendDataSetName = "firstRowData";
|
|
||||||
int initDataCount = 1000;
|
|
||||||
|
|
||||||
int firstRowCount = 100;
|
|
||||||
// call service
|
|
||||||
// if(useJdbcTemplate) {
|
|
||||||
// largeService.selectJdbcLargeData(firstRowHandler, sendDataSetName, firstRowCount, initDataCount);
|
|
||||||
// } else {
|
|
||||||
// largeService.selectLargeData(firstRowHandler, sendDataSetName, firstRowCount, initDataCount);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// end tag
|
|
||||||
try {
|
|
||||||
NexacroFirstRowAccessor.end(firstRowHandler);
|
|
||||||
} catch (PlatformException e) {
|
|
||||||
Assert.fail("fail. call end method. e=" + e);
|
|
||||||
}
|
|
||||||
|
|
||||||
PlatformData platformData = readPlatformData(outputStream);
|
|
||||||
|
|
||||||
Assert.assertNotNull("first row function is not work. check it.", platformData);
|
|
||||||
|
|
||||||
DataSet sendedDataSet = platformData.getDataSet(sendDataSetName);
|
|
||||||
Assert.assertNotNull("first row function is not work. check it.", sendedDataSet);
|
|
||||||
|
|
||||||
int actualRowCount = sendedDataSet.getRowCount();
|
|
||||||
int expectedRowCount = initDataCount;
|
|
||||||
Assert.assertEquals("sended row count not same.", expectedRowCount, actualRowCount);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private NexacroFirstRowHandler createFirstRowHandler(ServletOutputStream outputStream) {
|
private NexacroFirstRowHandler createFirstRowHandler(ServletOutputStream outputStream) {
|
||||||
|
|
||||||
// response를 생성한다.
|
// response를 생성한다.
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.StringReader;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
|
|
||||||
@@ -25,6 +26,8 @@ import org.springframework.test.context.web.WebAppConfiguration;
|
|||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.test.web.servlet.MvcResult;
|
import org.springframework.test.web.servlet.MvcResult;
|
||||||
import org.springframework.test.web.servlet.ResultHandler;
|
import org.springframework.test.web.servlet.ResultHandler;
|
||||||
|
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||||
|
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
||||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||||
import org.springframework.web.context.WebApplicationContext;
|
import org.springframework.web.context.WebApplicationContext;
|
||||||
import org.springframework.web.servlet.HandlerInterceptor;
|
import org.springframework.web.servlet.HandlerInterceptor;
|
||||||
@@ -34,7 +37,12 @@ import org.springframework.web.servlet.View;
|
|||||||
import com.nexacro.spring.NexacroConstants;
|
import com.nexacro.spring.NexacroConstants;
|
||||||
import com.nexacro.spring.servlet.NexacroInterceptor;
|
import com.nexacro.spring.servlet.NexacroInterceptor;
|
||||||
import com.nexacro.spring.view.NexacroView;
|
import com.nexacro.spring.view.NexacroView;
|
||||||
|
import com.nexacro.xapi.data.DataSet;
|
||||||
import com.nexacro.xapi.data.PlatformData;
|
import com.nexacro.xapi.data.PlatformData;
|
||||||
|
import com.nexacro.xapi.tx.DataDeserializer;
|
||||||
|
import com.nexacro.xapi.tx.DataSerializerFactory;
|
||||||
|
import com.nexacro.xapi.tx.PlatformException;
|
||||||
|
import com.nexacro.xapi.tx.PlatformType;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@WebAppConfiguration
|
@WebAppConfiguration
|
||||||
@@ -198,6 +206,42 @@ assertThat(res.getContentAsString (), is(“content”));
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFirstRowStatus() throws Exception {
|
||||||
|
|
||||||
|
MvcResult result = mockMvc.perform(get("/NexacroFirstRowStatus").content("").contentType(MediaType.TEXT_XML))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(content().contentType("text/xml;charset=UTF-8"))
|
||||||
|
.andReturn();
|
||||||
|
|
||||||
|
// check response
|
||||||
|
String responseString = result.getResponse().getContentAsString();
|
||||||
|
|
||||||
|
PlatformData readData = readData(responseString);
|
||||||
|
|
||||||
|
DataSet dummy = readData.getDataSet("dummy");
|
||||||
|
Assert.assertNotNull("DataSet 'dummy' should be sended.", dummy);
|
||||||
|
|
||||||
|
DataSet firstRowStatusDs = readData.getDataSet(NexacroConstants.ERROR_FIRST_ROW.ERROR_DATASET);
|
||||||
|
Assert.assertNotNull("FirstRow status must be transmitted.", firstRowStatusDs);
|
||||||
|
|
||||||
|
// row count
|
||||||
|
int actualRowCount = firstRowStatusDs.getRowCount();
|
||||||
|
int expectedRowCount = 1;
|
||||||
|
Assert.assertEquals(expectedRowCount, actualRowCount);
|
||||||
|
|
||||||
|
// default error code
|
||||||
|
int actualErrorCode = 0;
|
||||||
|
int expectedErrorCode = firstRowStatusDs.getInt(0, NexacroConstants.ERROR_FIRST_ROW.ERROR_CODE);
|
||||||
|
Assert.assertEquals(expectedErrorCode, actualErrorCode);
|
||||||
|
|
||||||
|
// default error msg
|
||||||
|
String actualErrorMsg = null;
|
||||||
|
String expectedErrorMsg = firstRowStatusDs.getString(0, NexacroConstants.ERROR_FIRST_ROW.ERROR_MSG);
|
||||||
|
Assert.assertEquals(expectedErrorMsg, actualErrorMsg);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNotEnterRequiredDataSet() throws Exception {
|
public void testNotEnterRequiredDataSet() throws Exception {
|
||||||
|
|
||||||
@@ -304,4 +348,16 @@ assertThat(res.getContentAsString (), is(“content”));
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private PlatformData readData(String responseString) {
|
||||||
|
PlatformData readData = null;
|
||||||
|
DataDeserializer deserializer = DataSerializerFactory.getDeserializer(PlatformType.CONTENT_TYPE_XML);
|
||||||
|
try {
|
||||||
|
readData = deserializer.readData(new StringReader(responseString), null, PlatformType.DEFAULT_CHAR_SET);
|
||||||
|
} catch (PlatformException e) {
|
||||||
|
Assert.fail("response string deserialize failed. e=" + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return readData;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,9 +21,12 @@ import org.springframework.web.context.WebApplicationContext;
|
|||||||
|
|
||||||
import com.nexacro.spring.NexacroConstants;
|
import com.nexacro.spring.NexacroConstants;
|
||||||
import com.nexacro.spring.NexacroException;
|
import com.nexacro.spring.NexacroException;
|
||||||
|
import com.nexacro.spring.data.NexacroFirstRowHandler;
|
||||||
import com.nexacro.spring.data.NexacroResult;
|
import com.nexacro.spring.data.NexacroResult;
|
||||||
|
import com.nexacro.xapi.data.DataSet;
|
||||||
import com.nexacro.xapi.data.PlatformData;
|
import com.nexacro.xapi.data.PlatformData;
|
||||||
import com.nexacro.xapi.data.Variable;
|
import com.nexacro.xapi.data.Variable;
|
||||||
|
import com.nexacro.xapi.data.datatype.PlatformDataType;
|
||||||
import com.nexacro.xapi.tx.DataDeserializer;
|
import com.nexacro.xapi.tx.DataDeserializer;
|
||||||
import com.nexacro.xapi.tx.DataSerializerFactory;
|
import com.nexacro.xapi.tx.DataSerializerFactory;
|
||||||
import com.nexacro.xapi.tx.PlatformException;
|
import com.nexacro.xapi.tx.PlatformException;
|
||||||
@@ -111,6 +114,46 @@ public class NexacroExceptionResolveTest {
|
|||||||
Assert.assertEquals("Variable 'ErrorMsg' must be transfered defined message.", expectedErrorMsg, actualErrorMsg);
|
Assert.assertEquals("Variable 'ErrorMsg' must be transfered defined message.", expectedErrorMsg, actualErrorMsg);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testExceptionWithFirstRow() throws Exception {
|
||||||
|
|
||||||
|
MvcResult result = mockMvc.perform(MockMvcRequestBuilders.get("/ExceptionWithFirstRow").content(""))
|
||||||
|
// 200 ok
|
||||||
|
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||||
|
.andReturn();
|
||||||
|
|
||||||
|
// resolved exception..
|
||||||
|
Exception resolvedException = result.getResolvedException();
|
||||||
|
Assert.assertNotNull("Exception should be resolved.", resolvedException);
|
||||||
|
|
||||||
|
// check response
|
||||||
|
String responseString = result.getResponse().getContentAsString();
|
||||||
|
|
||||||
|
PlatformData readData = readData(responseString);
|
||||||
|
|
||||||
|
DataSet dummy = readData.getDataSet("dummy");
|
||||||
|
Assert.assertNotNull("DataSet 'dummy' should be sended.", dummy);
|
||||||
|
|
||||||
|
DataSet firstRowStatusDs = readData.getDataSet(NexacroConstants.ERROR_FIRST_ROW.ERROR_DATASET);
|
||||||
|
Assert.assertNotNull("FirstRow status must be transmitted.", firstRowStatusDs);
|
||||||
|
|
||||||
|
// row count
|
||||||
|
int actualRowCount = firstRowStatusDs.getRowCount();
|
||||||
|
int expectedRowCount = 1;
|
||||||
|
Assert.assertEquals(expectedRowCount, actualRowCount);
|
||||||
|
|
||||||
|
// error code
|
||||||
|
int actualErrorCode = -1;
|
||||||
|
int expectedErrorCode = firstRowStatusDs.getInt(0, NexacroConstants.ERROR_FIRST_ROW.ERROR_CODE);
|
||||||
|
Assert.assertEquals(expectedErrorCode, actualErrorCode);
|
||||||
|
|
||||||
|
// error msg
|
||||||
|
String actualErrorMsg = "exception occured while first row";
|
||||||
|
String expectedErrorMsg = firstRowStatusDs.getString(0, NexacroConstants.ERROR_FIRST_ROW.ERROR_MSG);
|
||||||
|
Assert.assertEquals(expectedErrorMsg, actualErrorMsg);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSendUserExceptionMessage() {
|
public void testSendUserExceptionMessage() {
|
||||||
@@ -160,6 +203,24 @@ public class NexacroExceptionResolveTest {
|
|||||||
return new NexacroResult();
|
return new NexacroResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/ExceptionWithFirstRow")
|
||||||
|
public NexacroResult throwAnotherException(NexacroFirstRowHandler firstRowHandler) throws Exception {
|
||||||
|
|
||||||
|
DataSet ds = new DataSet("dummy");
|
||||||
|
ds.addColumn("dummy", PlatformDataType.STRING);
|
||||||
|
ds.newRow();
|
||||||
|
ds.set(0, "dummy", "dummydata");
|
||||||
|
|
||||||
|
firstRowHandler.sendDataSet(ds);
|
||||||
|
|
||||||
|
boolean occuredException = true;
|
||||||
|
if(occuredException) {
|
||||||
|
throw new IllegalAccessException("exception occured while first row");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new NexacroResult();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,8 +21,10 @@ import com.nexacro.xapi.data.DataSet;
|
|||||||
import com.nexacro.xapi.data.DataSetList;
|
import com.nexacro.xapi.data.DataSetList;
|
||||||
import com.nexacro.xapi.data.PlatformData;
|
import com.nexacro.xapi.data.PlatformData;
|
||||||
import com.nexacro.xapi.data.VariableList;
|
import com.nexacro.xapi.data.VariableList;
|
||||||
|
import com.nexacro.xapi.data.datatype.PlatformDataType;
|
||||||
import com.nexacro.xapi.tx.HttpPlatformRequest;
|
import com.nexacro.xapi.tx.HttpPlatformRequest;
|
||||||
import com.nexacro.xapi.tx.HttpPlatformResponse;
|
import com.nexacro.xapi.tx.HttpPlatformResponse;
|
||||||
|
import com.nexacro.xapi.tx.PlatformException;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class TestController {
|
public class TestController {
|
||||||
@@ -154,6 +156,20 @@ public class TestController {
|
|||||||
return new NexacroResult();
|
return new NexacroResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value="/NexacroFirstRowStatus")
|
||||||
|
public NexacroResult methodNexacroFirstRowStatus(NexacroFirstRowHandler firstRowHandler) throws PlatformException {
|
||||||
|
|
||||||
|
DataSet ds = new DataSet("dummy");
|
||||||
|
ds.addColumn("dummy", PlatformDataType.STRING);
|
||||||
|
ds.newRow();
|
||||||
|
ds.set(0, "dummy", "dummydata");
|
||||||
|
|
||||||
|
firstRowHandler.sendDataSet(ds);
|
||||||
|
|
||||||
|
return new NexacroResult();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@RequestMapping(value="/NexacroFileResult")
|
@RequestMapping(value="/NexacroFileResult")
|
||||||
public NexacroFileResult methodNexacroFileResult() {
|
public NexacroFileResult methodNexacroFileResult() {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user