Skip to content

Commit

Permalink
Fix resultset when both http response time and http response headers …
Browse files Browse the repository at this point in the history
…are selected.
  • Loading branch information
rfradinho committed Apr 11, 2017
1 parent 5d9b7ed commit a409c56
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions engine/src/org/pentaho/di/trans/steps/http/HTTP.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ private Object[] callHttpService( RowMetaInterface rowMeta, Object[] rowData ) t
}
if ( !Utils.isEmpty( meta.getResponseTimeFieldName() ) ) {
newRow = RowDataUtil.addValueData( newRow, returnFieldsOffset, new Long( responseTime ) );
returnFieldsOffset++;
}
if ( !Utils.isEmpty( meta.getResponseHeaderFieldName() ) ) {
newRow = RowDataUtil.addValueData( newRow, returnFieldsOffset, headerString.toString() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ private Object[] callHTTPPOST( Object[] rowData ) throws KettleException {
}
if ( !Utils.isEmpty( meta.getResponseTimeFieldName() ) ) {
newRow = RowDataUtil.addValueData( newRow, returnFieldsOffset, new Long( responseTime ) );
returnFieldsOffset++;
}
if ( !Utils.isEmpty( meta.getResponseHeaderFieldName() ) ) {
newRow = RowDataUtil.addValueData( newRow, returnFieldsOffset, headerString.toString() );
Expand Down
1 change: 1 addition & 0 deletions engine/src/org/pentaho/di/trans/steps/rest/Rest.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ private Object[] callRest( Object[] rowData ) throws KettleException {
// add response time to output
if ( !Utils.isEmpty( data.resultResponseFieldName ) ) {
newRow = RowDataUtil.addValueData( newRow, returnFieldsOffset, new Long( responseTime ) );
returnFieldsOffset++;
}
// add response header to output
if ( !Utils.isEmpty( data.resultHeaderFieldName ) ) {
Expand Down
7 changes: 5 additions & 2 deletions engine/test-src/org/pentaho/di/trans/steps/http/HTTPIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,14 @@ public void test204Answer() throws Exception {
@Test
public void testResponseHeader() throws Exception {
HTTPData data = new HTTPData();
int[] index = { 0, 1, 2 };
int[] index = { 0, 1, 3 };
RowMeta meta = new RowMeta();
meta.addValueMeta( new ValueMetaString( "fieldName" ) );
meta.addValueMeta( new ValueMetaInteger( "codeFieldName" ) );
meta.addValueMeta( new ValueMetaInteger( "responseTimeFieldName" ) );
meta.addValueMeta( new ValueMetaString( "headerFieldName" ) );
Object[] expectedRow =
new Object[] { "", 402L, "{\"host\":\"localhost\"}" };
new Object[] { "", 402L, 0L, "{\"host\":\"localhost\"}" };
HTTP http =
new HTTPHandler( stepMockHelper.stepMeta, data, 0, stepMockHelper.transMeta, stepMockHelper.trans, true );
RowMetaInterface inputRowMeta = mock( RowMetaInterface.class );
Expand All @@ -219,6 +220,8 @@ public void testResponseHeader() throws Exception {
when( stepMockHelper.processRowsStepMetaInterface.getResultCodeFieldName() ).thenReturn( "ResultCodeFieldName" );
when( stepMockHelper.processRowsStepMetaInterface.getFieldName() ).thenReturn( "ResultFieldName" );
when( stepMockHelper.processRowsStepMetaInterface.getEncoding() ).thenReturn( "UTF8" );
when( stepMockHelper.processRowsStepMetaInterface.getResponseTimeFieldName() ).thenReturn(
"ResponseTimeFieldName" );
when( stepMockHelper.processRowsStepMetaInterface.getResponseHeaderFieldName() ).thenReturn(
"ResponseHeaderFieldName" );
http.init( stepMockHelper.processRowsStepMetaInterface, data );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,14 @@ public void test204Answer() throws Exception {
public void testResponseHeader() throws Exception {
startHttpServer( get204AnswerHandler() );
HTTPPOSTData data = new HTTPPOSTData();
int[] index = { 0, 1, 2 };
int[] index = { 0, 1, 3 };
RowMeta meta = new RowMeta();
meta.addValueMeta( new ValueMetaString( "fieldName" ) );
meta.addValueMeta( new ValueMetaInteger( "codeFieldName" ) );
meta.addValueMeta( new ValueMetaInteger( "responseTimeFieldName" ) );
meta.addValueMeta( new ValueMetaString( "headerFieldName" ) );
Object[] expectedRow =
new Object[] { "", 402L, "{\"host\":\"localhost\"}" };
new Object[] { "", 402L, 0L, "{\"host\":\"localhost\"}" };
HTTPPOST HTTPPOST = new HTTPPOSTHandler(
stepMockHelper.stepMeta, data, 0, stepMockHelper.transMeta, stepMockHelper.trans, true );
RowMetaInterface inputRowMeta = mock( RowMetaInterface.class );
Expand All @@ -222,6 +223,8 @@ public void testResponseHeader() throws Exception {
when( stepMockHelper.processRowsStepMetaInterface.getResultCodeFieldName() ).thenReturn( "ResultCodeFieldName" );
when( stepMockHelper.processRowsStepMetaInterface.getFieldName() ).thenReturn( "ResultFieldName" );
when( stepMockHelper.processRowsStepMetaInterface.getEncoding() ).thenReturn( "UTF-8" );
when( stepMockHelper.processRowsStepMetaInterface.getResponseTimeFieldName() ).thenReturn(
"ResponseTimeFieldName" );
when( stepMockHelper.processRowsStepMetaInterface.getResponseHeaderFieldName() ).thenReturn(
"ResponseHeaderFieldName" );
HTTPPOST.init( stepMockHelper.processRowsStepMetaInterface, data );
Expand Down
7 changes: 5 additions & 2 deletions engine/test-src/org/pentaho/di/trans/steps/rest/RestIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,14 @@ public void testNoContent() throws Exception {
public void testResponseHeader() throws Exception {
try {
RestData data = new RestData();
int[] index = { 0, 1, 2 };
int[] index = { 0, 1, 3 };
RowMeta meta = new RowMeta();
meta.addValueMeta( new ValueMetaString( "fieldName" ) );
meta.addValueMeta( new ValueMetaInteger( "codeFieldName" ) );
meta.addValueMeta( new ValueMetaInteger( "responseTimeFieldName" ) );
meta.addValueMeta( new ValueMetaString( "headerFieldName" ) );
Object[] expectedRow =
new Object[] { "", 204L, "{\"host\":\"localhost\"}" };
new Object[] { "", 204L, 0L, "{\"host\":\"localhost\"}" };
Rest rest =
new RestHandler( stepMockHelper.stepMeta, data, 0, stepMockHelper.transMeta, stepMockHelper.trans, true );
RowMetaInterface inputRowMeta = mock( RowMetaInterface.class );
Expand All @@ -211,6 +212,8 @@ public void testResponseHeader() throws Exception {
when( stepMockHelper.processRowsStepMetaInterface.getUrl() ).thenReturn(
HTTP_LOCALHOST_9998 + "restTest/restNoContentAnswer" );
when( stepMockHelper.processRowsStepMetaInterface.getMethod() ).thenReturn( RestMeta.HTTP_METHOD_GET );
when( stepMockHelper.processRowsStepMetaInterface.getResponseTimeFieldName() ).thenReturn(
"ResponseTimeFieldName" );
when( stepMockHelper.processRowsStepMetaInterface.getResponseHeaderFieldName() ).thenReturn(
"ResponseHeaderFieldName" );
rest.init( stepMockHelper.processRowsStepMetaInterface, data );
Expand Down

0 comments on commit a409c56

Please sign in to comment.