Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## 1.0.3 (04/16/2018)
- More specific exception classes thrown when requests fail.

## 1.0.2 (04/12/2018)
- More specific exception classes thrown when requests fail.
- Mark internal classes as not final to allow mocking more easily.
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>org.sourcelab</groupId>
<artifactId>kafka-connect-client</artifactId>
<version>1.0.3-SNAPSHOT</version>
<version>1.0.3</version>
<packaging>jar</packaging>

<!-- Require Maven 3.3.9 -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@
import org.sourcelab.kafka.connect.apiclient.Configuration;
import org.sourcelab.kafka.connect.apiclient.request.JacksonFactory;
import org.sourcelab.kafka.connect.apiclient.request.Request;
import org.sourcelab.kafka.connect.apiclient.rest.exceptions.ConnectionException;
import org.sourcelab.kafka.connect.apiclient.rest.exceptions.ResultParsingException;
import org.sourcelab.kafka.connect.apiclient.rest.handlers.RestResponseHandler;

import javax.net.ssl.SSLContext;
import java.io.IOException;
import java.net.SocketException;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
Expand Down Expand Up @@ -215,16 +218,13 @@ private <T> T submitGetRequest(final String url, final Map<String, String> getPa

// Execute and return
return httpClient.execute(get, responseHandler);
} catch (final ClientProtocolException e) {
e.printStackTrace();
} catch (final IOException e) {
} catch (final ClientProtocolException | SocketException | URISyntaxException connectionException) {
// Typically this is a connection issue.
throw new ConnectionException(connectionException.getMessage(), connectionException);
} catch (final IOException ioException) {
// Typically this is a parse error.
e.printStackTrace();
} catch (final URISyntaxException e) {
// Bad URI building
e.printStackTrace();
throw new ResultParsingException(ioException.getMessage(), ioException);
}
return null;
}

/**
Expand Down Expand Up @@ -257,13 +257,13 @@ private <T> T submitPostRequest(final String url, final Object requestBody, fina

// Execute and return
return httpClient.execute(post, responseHandler);
} catch (final ClientProtocolException e) {
e.printStackTrace();
} catch (final IOException e) {
} catch (final ClientProtocolException | SocketException connectionException) {
// Typically this is a connection issue.
throw new ConnectionException(connectionException.getMessage(), connectionException);
} catch (final IOException ioException) {
// Typically this is a parse error.
e.printStackTrace();
throw new ResultParsingException(ioException.getMessage(), ioException);
}
return null;
}

/**
Expand Down Expand Up @@ -296,16 +296,13 @@ private <T> T submitPutRequest(final String url, final Object requestBody, final

// Execute and return
return httpClient.execute(put, responseHandler);
} catch (final ClientProtocolException e) {
e.printStackTrace();
} catch (final IOException e) {
} catch (final ClientProtocolException | SocketException | URISyntaxException connectionException) {
// Typically this is a connection issue.
throw new ConnectionException(connectionException.getMessage(), connectionException);
} catch (final IOException ioException) {
// Typically this is a parse error.
e.printStackTrace();
} catch (final URISyntaxException e) {
// Bad URI building
e.printStackTrace();
throw new ResultParsingException(ioException.getMessage(), ioException);
}
return null;
}

/**
Expand Down Expand Up @@ -340,16 +337,13 @@ private <T> T submitDeleteRequest(final String url, final Object requestBody, fi

// Execute and return
return httpClient.execute(delete, responseHandler);
} catch (final ClientProtocolException e) {
e.printStackTrace();
} catch (final IOException e) {
} catch (final ClientProtocolException | SocketException | URISyntaxException connectionException) {
// Typically this is a connection issue.
throw new ConnectionException(connectionException.getMessage(), connectionException);
} catch (final IOException ioException) {
// Typically this is a parse error.
e.printStackTrace();
} catch (final URISyntaxException e) {
// Bad URI building
e.printStackTrace();
throw new ResultParsingException(ioException.getMessage(), ioException);
}
return null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright 2018 SourceLab.org https://github.com/SourceLabOrg/kafka-connect-client
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
* persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package org.sourcelab.kafka.connect.apiclient.rest.exceptions;

/**
* Thrown for underlying connection issues.
*/
public class ConnectionException extends InvalidRequestException {
/**
* Constructor.
*
* @param message Error message.
* @param cause Originating exception.
*/
public ConnectionException(final String message, final Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ public InvalidRequestException(final String message, final int errorCode) {
this.errorCode = errorCode;
}

/**
* Constructor.
* @param message Error message.
* @param cause Originating exception.
*/
public InvalidRequestException(final String message, final Throwable cause) {
super(message, cause);
this.errorCode = -1;
}

/**
* @return Http Error Code.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright 2018 SourceLab.org https://github.com/SourceLabOrg/kafka-connect-client
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
* persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package org.sourcelab.kafka.connect.apiclient.rest.exceptions;

/**
* Thrown when failure to parse result.
*/
public class ResultParsingException extends InvalidRequestException {
/**
* Constructor.
* @param message Error message.
* @param cause Originating cause.
*/
public ResultParsingException(final String message, final Throwable cause) {
super(message, cause);
}
}