Skip to content

Commit

Permalink
Add request time and start time
Browse files Browse the repository at this point in the history
  • Loading branch information
Bertrand Paquet committed Jul 21, 2011
1 parent 1277e12 commit d182664
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 25 deletions.
17 changes: 15 additions & 2 deletions src/com/bpa/pentaho/plugins/AdvancedHTTP.java
@@ -1,6 +1,7 @@
package com.bpa.pentaho.plugins;

import java.io.InputStream;
import java.util.Date;

import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.Header;
Expand Down Expand Up @@ -58,9 +59,19 @@ private Object[] execHttp(RowMetaInterface rowMeta, Object[] row) throws KettleE
return callHttpService(rowMeta, row);
}

private Object[] makeResponse(RowMetaInterface rowMeta, Object[] rowData, String body, int code, long startTime, long requestTime) {
Object [] tmp = rowData;
tmp = RowDataUtil.addValueData(tmp, rowMeta.size(), body);
tmp = RowDataUtil.addValueData(tmp, rowMeta.size() + 1, new Long(code));
tmp = RowDataUtil.addValueData(tmp, rowMeta.size() + 2, new Date(startTime));
tmp = RowDataUtil.addValueData(tmp, rowMeta.size() + 3, new Long(requestTime));
return tmp;
}

private Object[] callHttpService(RowMetaInterface rowMeta, Object[] rowData) throws KettleException
{
String url = initUrl(rowMeta, rowData);
long start = System.currentTimeMillis();
try
{
if(log.isDetailed()) logDetailed(Messages.getString("AdvancedHTTP.Log.Connecting",url));
Expand Down Expand Up @@ -125,10 +136,12 @@ else if (AdvancedHTTPMeta.HTTP_CALL_TYPE_POST_FORM.equals(meta.getHttpCallType()
while ( (c=inputStream.read())!=-1) bodyBuffer.append((char)c);
inputStream.close();

long stop = System.currentTimeMillis();

String body = bodyBuffer.toString();
if (log.isDebug()) log.logDebug(toString(), "Response body: "+body);

return RowDataUtil.addValueData(RowDataUtil.addValueData(rowData, rowMeta.size(), body), rowMeta.size() + 1, new Long(result));
return makeResponse(rowMeta, rowData, body, result, start, stop-start);
}
finally
{
Expand All @@ -142,7 +155,7 @@ else if (AdvancedHTTPMeta.HTTP_CALL_TYPE_POST_FORM.equals(meta.getHttpCallType()
throw new KettleException(Messages.getString("AdvancedHTTP.Log.UnableGetResult",url), e);
}
else {
return RowDataUtil.addValueData(RowDataUtil.addValueData(rowData, rowMeta.size(), e.getMessage()), rowMeta.size() + 1, new Long(-1));
return makeResponse(rowMeta, rowData, e.getMessage(), -1, start, -1);
}
}
}
Expand Down
55 changes: 53 additions & 2 deletions src/com/bpa/pentaho/plugins/AdvancedHTTPDialog.java
Expand Up @@ -62,6 +62,14 @@ public class AdvancedHTTPDialog extends BaseStepDialog implements StepDialogInte
private Text wHttpReturnCodeFieldName;
private FormData fdlHttpReturnCodeFieldName, fdHttpReturnCodeFieldName;

private Label wlHttpStartTimeFieldName;
private Text wHttpStartTimeFieldName;
private FormData fdlHttpStartTimeFieldName, fdHttpStartTimeFieldName;

private Label wlHttpRequestTimeFieldName;
private Text wHttpRequestTimeFieldName;
private FormData fdlHttpRequestTimeFieldName, fdHttpRequestTimeFieldName;

private Label wlFields;
private TableView wFields;
private FormData fdlFields, fdFields;
Expand Down Expand Up @@ -346,20 +354,56 @@ public void focusGained(org.eclipse.swt.events.FocusEvent e)
fdHttpReturnCodeFieldName.right= new FormAttachment(100, 0);
wHttpReturnCodeFieldName.setLayoutData(fdHttpReturnCodeFieldName);

// HttpStartTimeFieldName line...
wlHttpStartTimeFieldName=new Label(shell, SWT.RIGHT);
wlHttpStartTimeFieldName.setText(Messages.getString("AdvancedHTTPDialog.HttpStartTimeFieldName.Label")); //$NON-NLS-1$
props.setLook(wlHttpStartTimeFieldName);
fdlHttpStartTimeFieldName=new FormData();
fdlHttpStartTimeFieldName.left = new FormAttachment(0, 0);
fdlHttpStartTimeFieldName.right= new FormAttachment(middle, -margin);
fdlHttpStartTimeFieldName.top = new FormAttachment(wHttpReturnCodeFieldName, margin*2);
wlHttpStartTimeFieldName.setLayoutData(fdlHttpStartTimeFieldName);
wHttpStartTimeFieldName=new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
props.setLook(wHttpStartTimeFieldName);
wHttpStartTimeFieldName.addModifyListener(lsMod);
fdHttpStartTimeFieldName=new FormData();
fdHttpStartTimeFieldName.left = new FormAttachment(middle, 0);
fdHttpStartTimeFieldName.top = new FormAttachment(wHttpReturnCodeFieldName, margin*2);
fdHttpStartTimeFieldName.right= new FormAttachment(100, 0);
wHttpStartTimeFieldName.setLayoutData(fdHttpStartTimeFieldName);

// HttpRequestTimeFieldName line...
wlHttpRequestTimeFieldName=new Label(shell, SWT.RIGHT);
wlHttpRequestTimeFieldName.setText(Messages.getString("AdvancedHTTPDialog.HttpRequestTimeFieldName.Label")); //$NON-NLS-1$
props.setLook(wlHttpRequestTimeFieldName);
fdlHttpRequestTimeFieldName=new FormData();
fdlHttpRequestTimeFieldName.left = new FormAttachment(0, 0);
fdlHttpRequestTimeFieldName.right= new FormAttachment(middle, -margin);
fdlHttpRequestTimeFieldName.top = new FormAttachment(wHttpStartTimeFieldName, margin*2);
wlHttpRequestTimeFieldName.setLayoutData(fdlHttpRequestTimeFieldName);
wHttpRequestTimeFieldName=new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
props.setLook(wHttpRequestTimeFieldName);
wHttpRequestTimeFieldName.addModifyListener(lsMod);
fdHttpRequestTimeFieldName=new FormData();
fdHttpRequestTimeFieldName.left = new FormAttachment(middle, 0);
fdHttpRequestTimeFieldName.top = new FormAttachment(wHttpStartTimeFieldName, margin*2);
fdHttpRequestTimeFieldName.right= new FormAttachment(100, 0);
wHttpRequestTimeFieldName.setLayoutData(fdHttpRequestTimeFieldName);

// Use basic auth line
wlUseBasicAuth=new Label(shell, SWT.RIGHT);
wlUseBasicAuth.setText(Messages.getString("AdvancedHTTPDialog.UseBasicAuth.Label"));
props.setLook(wlUseBasicAuth);
fdlUseBasicAuth=new FormData();
fdlUseBasicAuth.left = new FormAttachment(0, 0);
fdlUseBasicAuth.top = new FormAttachment(wHttpReturnCodeFieldName, margin);
fdlUseBasicAuth.top = new FormAttachment(wHttpRequestTimeFieldName, margin);
fdlUseBasicAuth.right= new FormAttachment(middle, -margin);
wlUseBasicAuth.setLayoutData(fdlUseBasicAuth);
wUseBasicAuth=new Button(shell, SWT.CHECK );
props.setLook(wUseBasicAuth);
fdUseBasicAuth=new FormData();
fdUseBasicAuth.left = new FormAttachment(middle, 0);
fdUseBasicAuth.top = new FormAttachment(wHttpReturnCodeFieldName);
fdUseBasicAuth.top = new FormAttachment(wHttpRequestTimeFieldName);
fdUseBasicAuth.right= new FormAttachment(100, 0);
wUseBasicAuth.setLayoutData(fdUseBasicAuth);
wUseBasicAuth.addSelectionListener(new SelectionAdapter()
Expand Down Expand Up @@ -493,6 +537,9 @@ public void run()
wUrl.addSelectionListener( lsDef );
wHttpBodyFieldName.addSelectionListener( lsDef );
wHttpReturnCodeFieldName.addSelectionListener( lsDef );
wHttpStartTimeFieldName.addSelectionListener( lsDef );
wHttpRequestTimeFieldName.addSelectionListener( lsDef );

wBasicAuthLogin.addSelectionListener( lsDef );
wBasicAuthPassword.addSelectionListener( lsDef );

Expand Down Expand Up @@ -585,6 +632,8 @@ public void getData()

if (input.getHttpBodyFieldName()!=null) wHttpBodyFieldName.setText(input.getHttpBodyFieldName());
if (input.getHttpReturnCodeFieldName()!=null) wHttpReturnCodeFieldName.setText(input.getHttpReturnCodeFieldName());
if (input.getHttpStartTimeFieldName()!=null) wHttpStartTimeFieldName.setText(input.getHttpStartTimeFieldName());
if (input.getHttpRequestTimeFieldName()!=null) wHttpRequestTimeFieldName.setText(input.getHttpRequestTimeFieldName());

wFields.setRowNums();
wFields.optWidth(true);
Expand Down Expand Up @@ -626,6 +675,8 @@ private void ok()
input.setStrictSSLCheck( wStrictSSLCheck.getSelection() );
input.setHttpBodyFieldName( wHttpBodyFieldName.getText() );
input.setHttpReturnCodeFieldName( wHttpReturnCodeFieldName.getText() );
input.setHttpStartTimeFieldName( wHttpStartTimeFieldName.getText() );
input.setHttpRequestTimeFieldName( wHttpRequestTimeFieldName.getText() );
stepname = wStepname.getText(); // return value

dispose();
Expand Down
83 changes: 63 additions & 20 deletions src/com/bpa/pentaho/plugins/AdvancedHTTPMeta.java
Expand Up @@ -32,21 +32,20 @@ public class AdvancedHTTPMeta extends BaseStepMeta implements StepMetaInterface
public static String HTTP_CALL_TYPE_GET = "GET";
public static String HTTP_CALL_TYPE_POST_FORM = "POST x-www-form-urlencoded";

/** URL / service to be called */
private String url;

/** function arguments : fieldname*/
private String argumentField[];

/** IN / OUT / INOUT */
private String argumentParameter[];

/** function bodyFieldName: new value name */
private String httpBodyFieldName;

/** function bodyFieldName: new value name */
private String httpReturnCodeFieldName;


private String httpStartTimeFieldName;

private String httpRequestTimeFieldName;

private boolean failOnError;

private boolean strictSSLCheck;
Expand All @@ -62,7 +61,7 @@ public class AdvancedHTTPMeta extends BaseStepMeta implements StepMetaInterface
private String basicAuthPassword;

private String httpCallType;

public AdvancedHTTPMeta()
{
super(); // allocate BaseStepMeta
Expand Down Expand Up @@ -149,6 +148,34 @@ public void setHttpReturnCodeFieldName(String httpReturnCodeFieldName)
}

/**
* @return the httpStartTimeFieldName
*/
public String getHttpStartTimeFieldName() {
return httpStartTimeFieldName;
}

/**
* @param httpStartTimeFieldName the httpStartTimeFieldName to set
*/
public void setHttpStartTimeFieldName(String httpStartTimeFieldName) {
this.httpStartTimeFieldName = httpStartTimeFieldName;
}

/**
* @return the httpRequestTimeFieldName
*/
public String getHttpRequestTimeFieldName() {
return httpRequestTimeFieldName;
}

/**
* @param httpRequestTimeFieldName the httpRequestTimeFieldName to set
*/
public void setHttpRequestTimeFieldName(String httpRequestTimeFieldName) {
this.httpRequestTimeFieldName = httpRequestTimeFieldName;
}

/**
* @return Returns fail on error
*/
public boolean isFailOnError() {
Expand Down Expand Up @@ -304,6 +331,8 @@ public void setDefault()

httpBodyFieldName = "http_body"; //$NON-NLS-1$
httpReturnCodeFieldName = "http_return_code"; //$NON-NLS-1$
httpStartTimeFieldName = "http_start_time"; //$NON-NLS-1$
httpRequestTimeFieldName = "http_request_time"; //$NON-NLS-1$

failOnError = true;
strictSSLCheck = true;
Expand All @@ -327,6 +356,16 @@ public void getFields(RowMetaInterface inputRowMeta, String name, RowMetaInterfa
v.setPrecision(0);
inputRowMeta.addValueMeta(v);
}
if (!Const.isEmpty(httpStartTimeFieldName))
{
ValueMetaInterface v = new ValueMeta(httpStartTimeFieldName, ValueMeta.TYPE_DATE);
inputRowMeta.addValueMeta(v);
}
if (!Const.isEmpty(httpRequestTimeFieldName))
{
ValueMetaInterface v = new ValueMeta(httpRequestTimeFieldName, ValueMeta.TYPE_INTEGER);
inputRowMeta.addValueMeta(v);
}
}

public String getXML()
Expand Down Expand Up @@ -354,13 +393,11 @@ public String getXML()

retval.append(" </lookup>").append(Const.CR); //$NON-NLS-1$

retval.append(" <http_body_field>").append(Const.CR); //$NON-NLS-1$
retval.append(" ").append(XMLHandler.addTagValue("name", httpBodyFieldName)); //$NON-NLS-1$ //$NON-NLS-2$
retval.append(" </http_body_field>").append(Const.CR); //$NON-NLS-1$

retval.append(" <http_return_code_field>").append(Const.CR); //$NON-NLS-1$
retval.append(" ").append(XMLHandler.addTagValue("name", httpReturnCodeFieldName)); //$NON-NLS-1$ //$NON-NLS-2$
retval.append(" </http_return_code_field>").append(Const.CR); //$NON-NLS-1$

retval.append(" "+XMLHandler.addTagValue("httpBodyFieldName", httpBodyFieldName));
retval.append(" "+XMLHandler.addTagValue("httpReturnCodeFieldName", httpReturnCodeFieldName));
retval.append(" "+XMLHandler.addTagValue("httpStartTimeFieldName", httpStartTimeFieldName));
retval.append(" "+XMLHandler.addTagValue("httpRequestTimeFieldName", httpRequestTimeFieldName));

return retval.toString();
}
Expand Down Expand Up @@ -394,8 +431,10 @@ private void readData(Node stepnode, List<? extends SharedObjectInterface> datab
argumentParameter[i] = XMLHandler.getTagValue(anode, "parameter"); //$NON-NLS-1$
}

httpBodyFieldName = XMLHandler.getTagValue(stepnode, "http_body_field", "name"); // Optional, can be null //$NON-NLS-1$
httpReturnCodeFieldName = XMLHandler.getTagValue(stepnode, "http_return_code_field", "name"); // Optional, can be null //$NON-NLS-1$
httpBodyFieldName = XMLHandler.getTagValue(stepnode, "httpBodyFieldName");
httpReturnCodeFieldName = XMLHandler.getTagValue(stepnode, "httpReturnCodeFieldName");
httpStartTimeFieldName = XMLHandler.getTagValue(stepnode, "httpStartTimeFieldName");
httpRequestTimeFieldName = XMLHandler.getTagValue(stepnode, "httpRequestTimeFieldName");
}
catch (Exception e)
{
Expand Down Expand Up @@ -426,8 +465,10 @@ public void readRep(Repository rep, long id_step, List<DatabaseMeta> databases,
argumentParameter[i] = rep.getStepAttributeString(id_step, i, "arg_parameter"); //$NON-NLS-1$
}

httpBodyFieldName = rep.getStepAttributeString(id_step, "http_body_field_name"); //$NON-NLS-1$
httpReturnCodeFieldName = rep.getStepAttributeString(id_step, "http_return_code_field_name"); //$NON-NLS-1$
httpBodyFieldName = rep.getStepAttributeString(id_step, "httpBodyFieldName"); //$NON-NLS-1$
httpReturnCodeFieldName = rep.getStepAttributeString(id_step, "httpReturnCodeFieldName"); //$NON-NLS-1$
httpStartTimeFieldName = rep.getStepAttributeString(id_step, "httpStartTimeFieldName"); //$NON-NLS-1$
httpRequestTimeFieldName = rep.getStepAttributeString(id_step, "httpStartTimeFieldName"); //$NON-NLS-1$
}
catch (Exception e)
{
Expand Down Expand Up @@ -455,8 +496,10 @@ public void saveRep(Repository rep, long id_transformation, long id_step) throws
rep.saveStepAttribute(id_transformation, id_step, i, "arg_parameter", argumentParameter[i]); //$NON-NLS-1$
}

rep.saveStepAttribute(id_transformation, id_step, "http_body_field_name", httpBodyFieldName); //$NON-NLS-1$
rep.saveStepAttribute(id_transformation, id_step, "http_return_code_field_name", httpReturnCodeFieldName); //$NON-NLS-1$
rep.saveStepAttribute(id_transformation, id_step, "httpBodyFieldName", httpBodyFieldName); //$NON-NLS-1$
rep.saveStepAttribute(id_transformation, id_step, "httpReturnCodeFieldName", httpReturnCodeFieldName); //$NON-NLS-1$
rep.saveStepAttribute(id_transformation, id_step, "httpStartTimeFieldName", httpStartTimeFieldName); //$NON-NLS-1$
rep.saveStepAttribute(id_transformation, id_step, "httpRequestTimeFieldName", httpRequestTimeFieldName); //$NON-NLS-1$
}
catch (Exception e)
{
Expand Down
Expand Up @@ -10,9 +10,11 @@ AdvancedHTTPDialog.StrictSSLCheck.Label=Strict SSL check?
AdvancedHTTPDialog.UseBasicAuth.Label=Use basic auth
AdvancedHTTPDialog.BasicAuthLogin.Label=BasicAuth login
AdvancedHTTPDialog.BasicAuthPassword.Label=BasicAuth Password
AdvancedHTTPDialog.HttpBodyFieldName.Label=Http Body fieldname
AdvancedHTTPDialog.HttpCallType.Label=Http Call Type
AdvancedHTTPDialog.HttpBodyFieldName.Label=Http Body fieldname
AdvancedHTTPDialog.HttpReturnCodeFieldName.Label=Http Return code fieldname
AdvancedHTTPDialog.HttpStartTimeFieldName.Label=Http Start time fieldname
AdvancedHTTPDialog.HttpRequestTimeFieldName.Label=Http Request time fieldname
AdvancedHTTPDialog.FailedToGetFields.DialogTitle=Get fields failed
AdvancedHTTPDialog.Shell.Title=HTTP web service
AdvancedHTTP.Log.ConnectedToDB=Connected to database...
Expand Down

0 comments on commit d182664

Please sign in to comment.