I need to upload zipped shapefiles to GeoServer through REST. I have followed
the CURL example and can upload the shapefile zip fine as follows:curl -v -u
admin:geoserver -XPUT -H "Content-type: application/zip" --data-binary
@data.zip
http://172.16.17.86:9090/geoserver/rest/workspaces/IDIRA6/datastores/Murrindindi/file.shpHowever,
I want to automate this by writing a Java program to do the same which is
where I am having issues. Following is my java code:import
java.io.File;import org.apache.http.HttpEntity;import
org.apache.http.auth.*;import
org.apache.http.client.CredentialsProvider;import
org.apache.http.client.entity.EntityBuilder;import
org.apache.http.client.methods.*;import org.apache.http.impl.client.*;import
org.apache.http.util.EntityUtils;public class QuickStart {    public static
void main(String[] args) throws Exception {        CredentialsProvider
credsProvider = new BasicCredentialsProvider();       
credsProvider.setCredentials(                AuthScope.ANY,               
new UsernamePasswordCredentials("admin", "geoserver"));       
CloseableHttpClient httpclient = HttpClients.custom()               
.setDefaultCredentialsProvider(credsProvider)                .build();       
try {            File file = new File("data.zip");                           
HttpPut httpPut = new
HttpPut("http://172.16.17.86:9090/geoserver/rest/workspaces/IDIRA6/datastores/Murrindindi/file.shp";);
           
httpPut.setHeader("Content-type", "application/zip");            HttpEntity
reqEntity = EntityBuilder.create()                        .setFile(file)        
                             
.build();            httpPut.setEntity(reqEntity);           
System.out.println("executing request " + httpPut.getRequestLine());           
CloseableHttpResponse response = httpclient.execute(httpPut);            try
{               
System.out.println("----------------------------------------");               
System.out.println(response.getStatusLine());                HttpEntity
resEntity = response.getEntity();                if (resEntity != null) {       
            
System.out.println("Response content length: " +
resEntity.getContentLength());                }               
EntityUtils.consume(resEntity);            } finally {               
response.close();            }        } finally {           
httpclient.close();        }    }}However, I get the following error: I/O
exception (java.net.SocketException) caught when processing request to
{}->http://172.16.17.86:9090: Connection reset by peer: socket write
errorAny suggestions to resolve this will be much appreciated



--
Sent from: http://osgeo-org.1560.x6.nabble.com/GeoServer-User-f3786390.html
_______________________________________________
Geoserver-users mailing list

Please make sure you read the following two resources before posting to this 
list:
- Earning your support instead of buying it, but Ian Turton: 
http://www.ianturton.com/talks/foss4g.html#/
- The GeoServer user list posting guidelines: 
http://geoserver.org/comm/userlist-guidelines.html

If you want to request a feature or an improvement, also see this: 
https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer


Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

Reply via email to