Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
KAA-494: handle REFUSE_BAD_CREDENTIALS in HTTP channel
  • Loading branch information
batytskyy committed Jun 10, 2015
1 parent 2c78a11 commit d6934ca
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
Expand Up @@ -71,8 +71,7 @@ public byte[] executeHttpRequest(String uri, LinkedHashMap<String, byte[]> entit
if (status >= 200 && status < 300) {
responseDataRaw = getResponseBody(response, verifyResponse);
} else {
throw new TransportException(
"Invalid response code from server: " + status);
throw new TransportException(status);
}
} finally {
method = null;
Expand Down
Expand Up @@ -43,6 +43,8 @@ public abstract class AbstractHttpChannel implements KaaDataChannel {
public static final Logger LOG = LoggerFactory // NOSONAR
.getLogger(AbstractHttpChannel.class);

private static final int UNATHORIZED_HTTP_STATUS = 401;

private IPTransportInfo currentServer;
private final AbstractKaaClient client;
private final KaaClientState state;
Expand Down Expand Up @@ -232,6 +234,18 @@ public void resume() {
}

protected void connectionFailed(boolean failed) {
connectionFailed(failed, -1);
}

protected void connectionFailed(boolean failed, int status) {
switch (status) {
case UNATHORIZED_HTTP_STATUS:
state.clean();
break;
default:
break;
}

lastConnectionFailed = failed;
if (failed) {
client.getChannelManager().onServerFailed(currentServer);
Expand Down
Expand Up @@ -24,6 +24,7 @@
import org.kaaproject.kaa.client.channel.ChannelDirection;
import org.kaaproject.kaa.client.channel.ServerType;
import org.kaaproject.kaa.client.persistence.KaaClientState;
import org.kaaproject.kaa.client.transport.TransportException;
import org.kaaproject.kaa.common.TransportType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -53,6 +54,9 @@ public void run() {
try {
processTypes(typesToProcess);
connectionFailed(false);
} catch (TransportException e) {
LOG.error("Failed to receive response from the operation {}", e);
connectionFailed(true, e.getStatus());
} catch (Exception e) {
LOG.error("Failed to receive response from the operation {}", e);
connectionFailed(true);
Expand Down
Expand Up @@ -18,6 +18,8 @@

public class TransportException extends Exception {

private int status;

/**
*
*/
Expand All @@ -30,4 +32,13 @@ public TransportException(String message) {
public TransportException(Exception e) {
super(e);
}

public TransportException(int status) {
super("Invalid response code from server: " + status);
this.status = status;
}

public int getStatus() {
return status;
}
}
Expand Up @@ -73,8 +73,7 @@ public byte[] executeHttpRequest(String uri, LinkedHashMap<String, byte[]> entit
if (status >= 200 && status < 300) {
responseDataRaw = getResponseBody(response, verifyResponse);
} else {
throw new TransportException(
"Invalid response code from server: " + status);
throw new TransportException(status);
}
} finally {
response.close();
Expand Down

0 comments on commit d6934ca

Please sign in to comment.