Skip to content

Commit

Permalink
[BACKLOG-4587] Relevant errors for data service connection issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Morrise committed Aug 26, 2015
1 parent 855b96b commit 2b63c8c
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 27 deletions.
102 changes: 76 additions & 26 deletions core/src/org/pentaho/di/cluster/HttpUtil.java
Expand Up @@ -26,11 +26,12 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.List;
import java.util.Map;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

Expand All @@ -39,8 +40,10 @@
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.lang.StringUtils;
import org.pentaho.di.core.Const;
import org.pentaho.di.core.encryption.Encr;
Expand All @@ -51,44 +54,91 @@ public class HttpUtil {

public static final int ZIP_BUFFER_SIZE = 8192;

public static String execService( VariableSpace space, String hostname, String port, String webAppName,
String serviceAndArguments, String username, String password, String proxyHostname, String proxyPort,
String nonProxyHosts ) throws Exception {
// Prepare HTTP get
//
private static HttpClient getClient( VariableSpace space, String hostname, String port, String webAppName,
String username, String password, String proxyHostname, String proxyPort, String nonProxyHosts ) {

HttpClient client = SlaveConnectionManager.getInstance().createHttpClient();
addCredentials( client, space, hostname, port, webAppName, username, password );
addProxy( client, space, hostname, proxyHostname, proxyPort, nonProxyHosts );

return client;
}

public static PostMethod execService( VariableSpace space, String hostname, String port, String webAppName,
String urlString, String username, String password, String proxyHostname, String proxyPort,
String nonProxyHosts, Iterable<Header> headers, Map<String, Object> parameters, Map<String, String> arguments )
throws Exception {

HttpClient
client =
getClient( space, hostname, port, webAppName, username, password, proxyHostname, proxyPort, nonProxyHosts );

client.getHttpConnectionManager().getParams().setConnectionTimeout( 0 );
client.getHttpConnectionManager().getParams().setSoTimeout( 0 );

PostMethod method = new PostMethod( urlString );

method.setDoAuthentication( true );

for ( Header header : headers ) {
method.addRequestHeader( header );
}

for ( Map.Entry<String, Object> parameter : parameters.entrySet() ) {
method.getParams().setParameter( parameter.getKey(), parameter.getValue() );
}

for ( Map.Entry<String, String> arg : arguments.entrySet() ) {
method.addParameter( arg.getKey(), arg.getValue() );
}

execMethod( client, method );
return method;
}

public static String execService( VariableSpace space, String hostname, String port, String webAppName,
String serviceAndArguments, String username, String password, String proxyHostname, String proxyPort,
String nonProxyHosts ) throws Exception {

HttpClient
client =
getClient( space, hostname, port, webAppName, username, password, proxyHostname, proxyPort, nonProxyHosts );

String urlString = constructUrl( space, hostname, port, webAppName, serviceAndArguments );
HttpMethod method = new GetMethod( urlString );

// Execute request
//
InputStream inputStream = null;
BufferedInputStream bufferedInputStream = null;
try {
execMethod( client, method );
return method.getResponseBodyAsString();
} finally {
method.releaseConnection();
}

}

public static int execMethod( HttpClient client, HttpMethod method ) throws Exception {
int result;
try {
int result = client.executeMethod( method );
if ( result != 200 ) {
throw new KettleException( "Response code " + result + " received while querying " + urlString );
}
result = client.executeMethod( method );
} catch ( Exception e ) {
throw new KettleException(
"You don't seem to be getting a connection to the server. Check the host and port you're using and make sure the sever is up and running." );
}

// the response
String body = method.getResponseBodyAsString();
if ( result == 500 ) {
throw new KettleException( "There was an error reading data from the server." );
}

return body;
} finally {
if ( bufferedInputStream != null ) {
bufferedInputStream.close();
}
if ( inputStream != null ) {
inputStream.close();
}
if ( result == 401 ) {
throw new KettleException(
"Nice try-but we couldn't log you in. Check your username and password and try again." );
}

// Release current connection to the connection pool once you are done
method.releaseConnection();
if ( result != 200 ) {
throw new KettleException( method.getResponseBodyAsString() );
}

return result;
}

/**
Expand Down
8 changes: 7 additions & 1 deletion core/src/org/pentaho/di/core/sql/SQLCondition.java
Expand Up @@ -250,7 +250,13 @@ private Condition parseAtomicCondition( String clause ) throws KettleSQLExceptio
"Unfortunately support for conditions is still very rudimentary, only 1 simple condition is supported ["
+ clause + "]" );
}
String left = strings.get( 0 );
String left = "";
try {
left = strings.get( 0 );
} catch ( Exception e ) {
throw new KettleSQLException( "Invalid SQL statement [" + clause + "]" );
}


// See if this is not a having clause expression :
// example:
Expand Down

0 comments on commit 2b63c8c

Please sign in to comment.