Skip to content

Commit

Permalink
Merge pull request #3 from glascaleia/master
Browse files Browse the repository at this point in the history
FIXED Reconnection Problem
  • Loading branch information
fizzi authored Oct 1, 2020
2 parents 100f10d + 259f673 commit 29c83a2
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 134 deletions.
21 changes: 0 additions & 21 deletions .gitignore

This file was deleted.

15 changes: 15 additions & 0 deletions java/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# ignore target artifact folders
target/

# ignore IDE artifacts
.settings
.classpath
.project
*.idea
.class
.DS_Store

# ignore demo artifact folders
*.iml
/.idea/
/target/
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@

package gov.protezionecivile.radar.downloader;

import com.google.common.base.Preconditions;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
Expand All @@ -297,23 +296,23 @@
import java.io.*;
import java.lang.reflect.Type;

import static com.google.common.base.Preconditions.checkArgument;

/**
* @author Francesco Izzi @ CNR IMAA geoSDI
*/

@Component(value = "dpcSessionHandler")
public class DPCRadarDataStompSessionHandler extends StompSessionHandlerAdapter implements InitializingBean {

private static final Logger logger = LogManager.getLogger(DPCRadarDataStompSessionHandler.class);
//
@Value("${productToDownload}")
public String productToDownload;

@Value("${defaultSavePath}")
public String defaultSavePath;

private final String DOWNLOAD_PRODUCT_URL = "http://www.protezionecivile.gov.it/wide-api/wide/product/downloadProduct";

private Logger logger = LogManager.getLogger(DPCRadarDataStompSessionHandler.class);

private StompClient stompClient;

@Override
public void afterConnected(StompSession session, StompHeaders connectedHeaders) {
Expand Down Expand Up @@ -404,6 +403,22 @@ public void handleFrame(StompHeaders headers, Object payload) {
}
}

/**
* This implementation is empty.
*
* @param session
* @param exception
*/
@Override
public void handleTransportError(StompSession session, Throwable exception) {
logger.warn("#########################handleTransportError : {}\n", exception.getMessage());
try {
this.stompClient.reconnect();
} catch (Exception ex) {
ex.printStackTrace();
}
}

public String getProductToDownload() {
return productToDownload;
}
Expand All @@ -412,11 +427,18 @@ public String getDefaultSavePath() {
return defaultSavePath;
}

/**
* @param theStompClient
*/
void injectStompClient(StompClient theStompClient) {
this.stompClient = theStompClient;
}

@Override
public void afterPropertiesSet() throws Exception {
Preconditions.checkArgument(this.productToDownload != null && !this.productToDownload.trim().isEmpty(), "The paramenter productToDownload not present");
Preconditions.checkArgument(this.defaultSavePath != null && !this.defaultSavePath.trim().isEmpty(), "The paramenter defaultSavePath not present");
checkArgument(this.productToDownload != null && !this.productToDownload.trim().isEmpty(), "The paramenter productToDownload not present");
checkArgument(this.defaultSavePath != null && !this.defaultSavePath.trim().isEmpty(), "The paramenter defaultSavePath not present");
logger.info("Configured products to Download : {} ",productToDownload);
logger.info("Directory to download DPC-Radar data : {} ", defaultSavePath);
}
}
}
Loading

0 comments on commit 29c83a2

Please sign in to comment.