Skip to content

Commit

Permalink
release 0.4.0-alpha4
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyangming committed Jun 21, 2017
1 parent 023d639 commit 637ef7c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@
import org.bytesoft.common.utils.ByteUtils;
import org.bytesoft.common.utils.CommonUtils;
import org.bytesoft.compensable.TransactionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import feign.FeignException;
import feign.Request;
import feign.Response;
import feign.codec.DecodeException;

public class CompensableFeignDecoder implements feign.codec.Decoder {
static Logger logger = LoggerFactory.getLogger(CompensableFeignDecoder.class);

static final String HEADER_TRANCACTION_KEY = "org.bytesoft.bytetcc.transaction";
static final String HEADER_PROPAGATION_KEY = "org.bytesoft.bytetcc.propagation";

Expand Down Expand Up @@ -61,18 +65,22 @@ public Object decode(Response resp, Type type) throws IOException, DecodeExcepti
return this.delegate.decode(resp, type);
}

String transactionStr = StringUtils.isBlank(respTransactionStr) ? reqTransactionStr : respTransactionStr;
String propagationStr = StringUtils.isBlank(respPropagationStr) ? reqTransactionStr : respPropagationStr;
try {
String transactionStr = StringUtils.isBlank(respTransactionStr) ? reqTransactionStr : respTransactionStr;
String propagationStr = StringUtils.isBlank(respPropagationStr) ? reqPropagationStr : respPropagationStr;

byte[] byteArray = ByteUtils.stringToByteArray(transactionStr);
TransactionContext transactionContext = (TransactionContext) CommonUtils.deserializeObject(byteArray);
byte[] byteArray = ByteUtils.stringToByteArray(transactionStr);
TransactionContext transactionContext = (TransactionContext) CommonUtils.deserializeObject(byteArray);

SpringCloudBeanRegistry beanRegistry = SpringCloudBeanRegistry.getInstance();
RemoteCoordinator remoteCoordinator = beanRegistry.getConsumeCoordinator(propagationStr);
SpringCloudBeanRegistry beanRegistry = SpringCloudBeanRegistry.getInstance();
RemoteCoordinator remoteCoordinator = beanRegistry.getConsumeCoordinator(propagationStr);

TransactionResponseImpl response = new TransactionResponseImpl();
response.setTransactionContext(transactionContext);
response.setSourceTransactionCoordinator(remoteCoordinator);
TransactionResponseImpl response = new TransactionResponseImpl();
response.setTransactionContext(transactionContext);
response.setSourceTransactionCoordinator(remoteCoordinator);
} catch (IOException ex) {
logger.error("Error occurred while decoding response({})!", resp, ex);
}

return this.delegate.decode(resp, type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@
import org.bytesoft.common.utils.ByteUtils;
import org.bytesoft.common.utils.CommonUtils;
import org.bytesoft.compensable.TransactionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import feign.Request;
import feign.Response;

public class CompensableFeignErrorDecoder implements feign.codec.ErrorDecoder {
static Logger logger = LoggerFactory.getLogger(CompensableFeignErrorDecoder.class);

static final String HEADER_TRANCACTION_KEY = "org.bytesoft.bytetcc.transaction";
static final String HEADER_PROPAGATION_KEY = "org.bytesoft.bytetcc.propagation";

Expand Down Expand Up @@ -58,11 +62,11 @@ public Exception decode(String methodKey, Response resp) {
return this.delegate.decode(methodKey, resp);
}

String transactionStr = StringUtils.isBlank(respTransactionStr) ? reqTransactionStr : respTransactionStr;
String propagationStr = StringUtils.isBlank(respPropagationStr) ? reqTransactionStr : respPropagationStr;

// int status = resp.status();
try {
String transactionStr = StringUtils.isBlank(respTransactionStr) ? reqTransactionStr : respTransactionStr;
String propagationStr = StringUtils.isBlank(respPropagationStr) ? reqPropagationStr : respPropagationStr;

byte[] byteArray = ByteUtils.stringToByteArray(transactionStr);
TransactionContext transactionContext = (TransactionContext) CommonUtils.deserializeObject(byteArray);

Expand All @@ -73,7 +77,7 @@ public Exception decode(String methodKey, Response resp) {
response.setTransactionContext(transactionContext);
response.setSourceTransactionCoordinator(remoteCoordinator);
} catch (IOException ex) {
return this.delegate.decode(methodKey, resp);
logger.error("Error occurred while decoding response: methodKey= {}, response= {}", methodKey, resp, ex);
}

return this.delegate.decode(methodKey, resp);
Expand Down

0 comments on commit 637ef7c

Please sign in to comment.