Project

General

Profile

pubsub rest api call create-node method always return <error code="401" type="auth"><not-authorized xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error>

lin jiafu
Added over 1 year ago

my tigase service version is 7.1.0 and my init.properties config is :

config-type=--gen-config-all

--admins=admin@im.hsilu.com,http@im.hsilu.com,pubsub@im.hsilu.com

--virt-hosts=im.hsilu.com

--debug=server

--user-db=mysql

--user-db-uri=jdbc:mysql://192.168.18.59:3306/tigasedb?user=web&password=123456&useUnicode=true&characterEncoding=UTF-8

http/setup/admin-credentials=admin:tigase

--comp-name-1=http

--comp-class-1=tigase.http.HttpMessageReceiver

http/http/port[I]=8080

http/dns-webservice/active[B]=true

http/api-keys[s]=open_access

--api-keys[s]=open_access

--api-keys=open_access

http/api-key=open_access

http/server-class[S]=tigase.http.java.JavaStandaloneHttpServer

and my java code is :

DownloadFromUrlGet("http://192.168.18.45:8080/rest/pubsub/pubsub.im.hsilu.com/create-node", "utf-8", "admin@im.hsilu.com", "admin")

public static String DownloadFromUrlGet(String urlstr, String code, String user, String password) throws MalformedURLException {

    StringBuilder data = new StringBuilder();

    URL url = new URL(urlstr);

    int counts = 0;

    while (true) {

        try {

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

            String authString = user + ":" + password;

            byte[] authEncBytes = Base64.encodeBase64(authString.getBytes());

            String authStringEnc = new String(authEncBytes);

            connection.setRequestProperty("Authorization", "Basic " + authStringEnc);

            connection.setRequestProperty("User-Agent", "MSIE 7.0");

            connection.setConnectTimeout(5000);

            connection.setRequestProperty("Content-Type", "application/json");

            connection.setRequestMethod("GET");

            BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), code));

            String line = null;

            while ((line = br.readLine()) != null) {

                data.append(line);

                data.append("\r\n");

            }

            connection.disconnect();

            break;

        } catch (ConnectException e) {

            if (counts >= 5) {

                System.out.println(urlstr + " : " + e.toString());

                 e.printStackTrace();

                return null;

            }

            counts++;

            System.out.println("再次尝试");

            continue;

        } catch (Exception e) {

            if (counts >= 5) {

                System.out.println(urlstr + " : " + e.toString());

                 e.printStackTrace();

                return null;

            }

            counts++;

            System.out.println("再次尝试");

            continue;

        }

    }

    return data.toString();

}

but it return all the time,please help me, thakns.


Replies (2)

(1)

Added by Andrzej Wójcik IoT 1 CloudTigaseTeam over 1 year ago

You have following lines in yours etc/init.properties file:

http/api-keys[s]=open_access
--api-keys[s]=open_access
--api-keys=open_access
http/api-key=open_access

so you try to set api-key 4 times and each try overrides previous one! Please use only one of those lines, not all of them at the same time.

API key property is a setting REST module, so you should use:

http/rest/api-keys[s]=open_access

or

--api-keys=open_access

Moreover, I do not see proper configuration of PubSub component required for usage of PubSub with HTTP API, see https://projects.tigase.org/projects/tigase-pubsub/wiki/REST_API

Added by lin jiafu over 1 year ago

thanks Andrzej Wójcik,i use your method, but it does not work ,and it return the same, my config is in the init.properties file,please help me, thanks again.

    (1-2/2)