hello
This commit is contained in:
@@ -169,6 +169,7 @@ public class GeoServerRegistrationService {
|
||||
* @param layerName GeoServer layer name
|
||||
*/
|
||||
public void registerShapefileByPath(String absoluteFilePath, String layerName) {
|
||||
String shpFilePath = null; // Declare outside try block for error handling
|
||||
try {
|
||||
log.info("Starting shapefile registration to GeoServer (file path reference)");
|
||||
log.info("Input file path: {}", absoluteFilePath);
|
||||
@@ -202,7 +203,7 @@ public class GeoServerRegistrationService {
|
||||
log.info("File size: {} MB", file.length() / 1024 / 1024);
|
||||
|
||||
// Convert .zip path to .shp path if needed
|
||||
String shpFilePath = absoluteFilePath;
|
||||
shpFilePath = absoluteFilePath;
|
||||
if (lowerPath.endsWith(".zip")) {
|
||||
shpFilePath = absoluteFilePath.substring(0, absoluteFilePath.length() - 4) + ".shp";
|
||||
File shpFile = new File(shpFilePath);
|
||||
@@ -215,6 +216,41 @@ public class GeoServerRegistrationService {
|
||||
log.info("Converted ZIP path to SHP path: {}", shpFilePath);
|
||||
}
|
||||
|
||||
// Verify all shapefile components exist and are readable
|
||||
File shpFile = new File(shpFilePath);
|
||||
String basePathWithoutExt = shpFilePath.substring(0, shpFilePath.length() - 4);
|
||||
String[] requiredExtensions = {".shp", ".shx", ".dbf"};
|
||||
String[] optionalExtensions = {".prj", ".cpg", ".qpj"};
|
||||
|
||||
log.info("=== Shapefile Component Verification ===");
|
||||
for (String ext : requiredExtensions) {
|
||||
File component = new File(basePathWithoutExt + ext);
|
||||
if (!component.exists()) {
|
||||
throw new IllegalArgumentException(
|
||||
"Required shapefile component not found: " + component.getAbsolutePath());
|
||||
}
|
||||
if (!component.canRead()) {
|
||||
throw new IllegalArgumentException(
|
||||
"Cannot read shapefile component (permission denied): "
|
||||
+ component.getAbsolutePath());
|
||||
}
|
||||
log.info(" ✓ {} exists ({} bytes, readable: {})", ext, component.length(), true);
|
||||
}
|
||||
|
||||
for (String ext : optionalExtensions) {
|
||||
File component = new File(basePathWithoutExt + ext);
|
||||
if (component.exists()) {
|
||||
log.info(
|
||||
" ✓ {} exists ({} bytes, readable: {})",
|
||||
ext,
|
||||
component.length(),
|
||||
component.canRead());
|
||||
} else {
|
||||
log.info(" ⚠ {} not found (optional)", ext);
|
||||
}
|
||||
}
|
||||
log.info("=== End Verification ===");
|
||||
|
||||
// Check if layer exists and handle overwrite
|
||||
if (properties.isOverwriteExisting() && layerExists(layerName)) {
|
||||
log.info("Layer '{}' already exists. Deleting...", layerName);
|
||||
@@ -258,21 +294,55 @@ public class GeoServerRegistrationService {
|
||||
e.getStatusCode(),
|
||||
e.getResponseBodyAsString());
|
||||
|
||||
if (e.getStatusCode() == HttpStatus.INTERNAL_SERVER_ERROR) {
|
||||
if (e.getStatusCode() == HttpStatus.BAD_REQUEST) {
|
||||
log.error("");
|
||||
log.error("========================================");
|
||||
log.error("ERROR: GeoServer cannot access the file path");
|
||||
log.error("ERROR: GeoServer returned 400 Bad Request - Cannot locate file");
|
||||
log.error("");
|
||||
if (shpFilePath != null) {
|
||||
log.error("File URL sent to GeoServer: file://{}", shpFilePath);
|
||||
} else {
|
||||
log.error("File URL: (path not yet determined)");
|
||||
}
|
||||
log.error("");
|
||||
log.error("Possible causes:");
|
||||
log.error(" 1. File path is not accessible from GeoServer server");
|
||||
log.error(" 2. GeoServer user lacks read permissions");
|
||||
log.error(" 3. File path format is incorrect (must be absolute path)");
|
||||
log.error(" 1. PATH MISMATCH: GeoServer sees a different path than application server");
|
||||
if (shpFilePath != null) {
|
||||
log.error(" - Application path: {}", shpFilePath);
|
||||
} else {
|
||||
log.error(" - Application path: {}", absoluteFilePath);
|
||||
}
|
||||
log.error(" - GeoServer may see: different mount point or drive letter");
|
||||
log.error("");
|
||||
log.error("Solutions:");
|
||||
log.error(" 1. Verify GeoServer has file system access to the .shp file");
|
||||
log.error(" 2. Check file permissions (chmod 644 or similar)");
|
||||
log.error(" 3. Ensure path is absolute and correctly formatted");
|
||||
log.error(" 4. Ensure all shapefile components (.shp, .shx, .dbf, .prj) exist");
|
||||
log.error(" 2. GEOSERVER SECURITY: External file access may be disabled");
|
||||
log.error(" - Check GeoServer global settings for 'Enable external entities'");
|
||||
log.error(" - Check data security settings");
|
||||
log.error("");
|
||||
log.error(" 3. FILE ACCESS: GeoServer process cannot read the file");
|
||||
log.error(" - Check file permissions from GeoServer server perspective");
|
||||
log.error(" - GeoServer user (tomcat/geoserver) needs read access");
|
||||
log.error("");
|
||||
log.error(" 4. MISSING COMPONENTS: Required shapefile files missing");
|
||||
log.error(" - All files (.shp, .shx, .dbf, .prj) must exist");
|
||||
log.error("");
|
||||
log.error("Verification steps:");
|
||||
log.error(" 1. SSH to GeoServer server");
|
||||
if (shpFilePath != null) {
|
||||
log.error(" 2. Run: ls -la {}", shpFilePath);
|
||||
} else {
|
||||
log.error(" 2. Run: ls -la <shapefile-path>");
|
||||
}
|
||||
log.error(" 3. Verify path matches and files are readable by GeoServer user");
|
||||
log.error(" 4. Check GeoServer logs for more details");
|
||||
log.error("========================================");
|
||||
log.error("");
|
||||
} else if (e.getStatusCode() == HttpStatus.INTERNAL_SERVER_ERROR) {
|
||||
log.error("");
|
||||
log.error("========================================");
|
||||
log.error("ERROR: GeoServer internal error (500)");
|
||||
log.error("");
|
||||
log.error("This usually indicates a shapefile format issue or corruption.");
|
||||
log.error("Check GeoServer logs for detailed error information.");
|
||||
log.error("========================================");
|
||||
log.error("");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user