Hi,

I'm trying to use the rest api of geoserver 1.7.4, i just installed the rest
component and then i create a java client in order to invoke the rest
services.
When i try to obtain the response of geoserver the following exception is
thrown.

java.io.IOException: Server returned HTTP response code: 401 for URL:
http://localhost:8080/geoserver/rest/workspaces/Montevideo/datastores/Montevideo/featuretypes

I'm using BASIC authentication like in the examples, but i think i'm doing
something wrong

Montevideo is a namespace and i have created a Montevideo datastore too.
username is admin and password geoserver

In the body i send the following xml content:

<?xml version="1.0" encoding="UTF-8"?>
<featureType>
        <name>barrios</name>
</featureType>


This is the following code:


HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                connection.setRequestMethod(method);

                // write auth header
                BASE64Encoder encoder = new BASE64Encoder();
                String encodedCredential = encoder.encode((username + ":" + 
password)
                                .getBytes());
                connection.setRequestProperty("Authorization:", "BASIC "
                                + encodedCredential);
                connection.setRequestProperty("Content-Type","text/xml");

                // write body if we're doing POST or PUT
                byte buffer[] = new byte[8192];
                int read = 0;
                if (body != null) {
                        connection.setDoOutput(true);

                        OutputStream output = connection.getOutputStream();
                        while ((read = body.read(buffer)) != -1) {
                                output.write(buffer, 0, read);
                        }
                }

                // do request
                long time = System.currentTimeMillis();
                connection.connect();

                InputStream responseBodyStream = connection.getInputStream();


If anyone could tell me what could be wrong i would be appreciated.

Thanks, Santiago.
-- 
View this message in context: 
http://www.nabble.com/java.io.IOException%3A-Server-returned-HTTP-response-code%3A-401-tp24539982p24539982.html
Sent from the GeoServer - Dev mailing list archive at Nabble.com.


------------------------------------------------------------------------------
_______________________________________________
Geoserver-devel mailing list
Geoserver-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-devel

Reply via email to