public abstract class AbstractDataStore implements Datastore {
private final RestconfClientImpl client;
+ private static final int STATUS_OK = 200;
+ private static final int STATUS_NOT_FOUND = 404;
public AbstractDataStore(RestconfClientImpl client) {
super();
@SuppressWarnings("unchecked")
@Override
public com.google.common.base.Optional<T> apply(ClientResponse response) {
- switch (response.getStatus()) {
- case 200: // Status OK
- DataObject dataObject = deserialize(domPath,response.getEntityInputStream());
- return (Optional<T>) Optional.of(dataObject);
- case 404: // Status Not Found
- return Optional.<T> absent();
+ switch (response.getStatus()) {
+ case STATUS_OK:
+ DataObject dataObject = deserialize(domPath,response.getEntityInputStream());
+ return (Optional<T>) Optional.of(dataObject);
+ case STATUS_NOT_FOUND:
+ return Optional.<T> absent();
default:
- throw new IllegalStateException("Failed : HTTP error code : " + response.getStatus());
+ throw new IllegalStateException("Failed : HTTP error code : " + response.getStatus());
}
}
private final BindingNormalizedNodeCodecRegistry mappingService;
private final SchemaContext schcemaContext;
private final Module module;
+ private static final int STATUS_OK = 200;
public BindingToRestRpc(final Class<?> proxiedInterface,final BindingNormalizedNodeCodecRegistry mappingService2,final RestconfClientImpl client,final SchemaContext schemaContext) throws Exception {
this.mappingService = mappingService2;
return client.post(ResourceUri.OPERATIONS.getPath() + "/" + moduleName + ":" + rpcMethodName,payloadString,new Function<ClientResponse, Object>() {
@Override
public Object apply(final ClientResponse clientResponse) {
- if (clientResponse.getStatus() != 200) {
+ if (clientResponse.getStatus() != STATUS_OK) {
throw new IllegalStateException("Can't get data from restconf. "+clientResponse.getClientResponseStatus());
}
List<RpcError> errors = new ArrayList<>();
public class ConfigurationDataStoreImpl extends AbstractDataStore implements ConfigurationDatastore {
+ private static final int STATUS_OK = 200;
+
@Override
protected String getStorePrefix() {
return ResourceUri.CONFIG.getPath();
@SuppressWarnings("unchecked")
@Override
public RpcResult<Boolean> apply(ClientResponse clientResponse) {
- if (clientResponse.getStatus() != 200) {
+ if (clientResponse.getStatus() != STATUS_OK) {
RpcError rpcError = new RestRpcError(RpcError.ErrorSeverity.ERROR,RpcError.ErrorType.RPC,null,null,"HTTP status "+clientResponse.getStatus(),null,null);
Collection<RpcError> errors = new ArrayList<RpcError>();
errors.add(rpcError);
@SuppressWarnings("unchecked")
@Override
public RpcResult<Boolean> apply(ClientResponse clientResponse) {
- if (clientResponse.getStatus() != 200) {
+ if (clientResponse.getStatus() != STATUS_OK) {
RpcError rpcError = new RestRpcError(RpcError.ErrorSeverity.ERROR,RpcError.ErrorType.RPC,null,null,"HTTP status "+clientResponse.getStatus(),null,null);
Collection<RpcError> errors = new ArrayList<RpcError>();
errors.add(rpcError);
private Method listenerCallbackMethod;
private final RestconfClientImpl restconfClient;
private final EventStreamInfo streamInfo;
+ private static final int STATUS_OK = 200;
public RestListenableEventStreamContext(final EventStreamInfo streamInfo,final RestconfClientImpl restconfClient){
this.restconfClient = restconfClient;
throw new IllegalStateException(e);
}
boolean success = true;
- if (response.getStatus() != 200) {
+ if (response.getStatus() != STATUS_OK) {
success = false;
}
private DataObjectSerializerGenerator generator;
+ private static final int STATUS_OK = 200;
+
public RestconfClientImpl(final URL url, final SchemaContextHolder schemaContextHolder) {
Preconditions.checkArgument(url != null, "Restconf endpoint URL must be supplied.");
Preconditions.checkNotNull(schemaContextHolder, "Schema Context Holder must not be null.");
new Function<ClientResponse, Set<Class<? extends RpcService>>>() {
@Override
public Set<Class<? extends RpcService>> apply(final ClientResponse clientResponse) {
- if (clientResponse.getStatus() != 200) {
+ if (clientResponse.getStatus() != STATUS_OK) {
throw new RuntimeException("Failed : HTTP error code : " + clientResponse.getStatus());
}
return RestconfUtils.rpcServicesFromInputStream(clientResponse.getEntityInputStream(),
new Function<ClientResponse, Set<EventStreamInfo>>() {
@Override
public Set<EventStreamInfo> apply(final ClientResponse clientResponse) {
- if (clientResponse.getStatus() != 200) {
+ if (clientResponse.getStatus() != STATUS_OK) {
throw new RuntimeException("Failed : HTTP error code : " + clientResponse.getStatus());
}
try {