<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Java rest service for user sessions help in Real User Monitoring</title>
    <link>https://community.dynatrace.com/t5/Real-User-Monitoring/Java-rest-service-for-user-sessions-help/m-p/111548#M896</link>
    <description>&lt;P&gt;1. Test the query in our Environment API OpenAPI page. There were some issues with it.&lt;/P&gt;&lt;P&gt;2. Copy the URL from the resulting curl command when you get it working&lt;/P&gt;&lt;P&gt;3. Change your code slightly when setting the headers:&lt;/P&gt;&lt;P&gt;conn.setRequestProperty("accept", "application/json");&lt;/P&gt;&lt;P&gt;conn.setRequestProperty("Authorization", "Api-Token **********************");&lt;/P&gt;&lt;P&gt;accept in lowercase and space rather than "=" after "Api-Token".&lt;/P&gt;&lt;P&gt;I got it working after making these changes and using the URLEncoded URL from the OpenAPI page with this query:&lt;/P&gt;&lt;P&gt;SELECT endTime as time, userSessionId, SUM(useraction.visuallyCompleteTime) AS 'Server Processing Time' FROM usersession WHERE (userId='Full Quote User 1' OR internalUserId='Full Quote User' or userId='Full Quote User 2' or userId='Full Quote User 3' or userId='Full Quote User') and userActionCount &amp;gt; 25 and userActionCount &amp;lt; 50 GROUP BY endTime, userSessionId&lt;/P&gt;&lt;P&gt;4. After you get it working like this, add the URLEncoder as suggested by @Radoslaw S.&lt;/P&gt;</description>
    <pubDate>Tue, 21 Apr 2020 18:17:30 GMT</pubDate>
    <dc:creator>dave_mauney</dc:creator>
    <dc:date>2020-04-21T18:17:30Z</dc:date>
    <item>
      <title>Java rest service for user sessions help</title>
      <link>https://community.dynatrace.com/t5/Real-User-Monitoring/Java-rest-service-for-user-sessions-help/m-p/111542#M890</link>
      <description>&lt;P&gt;Below is the Java class which i have written to call a usersession api , but i get 400 as response. Any help here could be appreciated. Is it issue with setting api header ? The same url is working in post man client. &lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;package com.spx.dyntrace;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;    import java.io.BufferedReader;&lt;/P&gt;&lt;P&gt;    import java.io.IOException;&lt;/P&gt;&lt;P&gt;    import java.io.InputStreamReader;&lt;/P&gt;&lt;P&gt;    import java.net.HttpURLConnection;&lt;/P&gt;&lt;P&gt;    import java.net.MalformedURLException;&lt;/P&gt;&lt;P&gt;    import java.net.URL;&lt;/P&gt;&lt;P&gt;    import java.util.Base64;&lt;/P&gt;&lt;P&gt;    &lt;/P&gt;&lt;P&gt;public class Post {&lt;!-- --&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;    &lt;/P&gt;&lt;P&gt;    &lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;        // http://localhost:8080/RESTfulExample/json/product/get&lt;/P&gt;&lt;P&gt;        public static void main(String[] args) {&lt;!-- --&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;          try {&lt;!-- --&gt;&lt;/P&gt;&lt;P&gt;              &lt;/P&gt;&lt;P&gt;         &lt;/P&gt;&lt;P&gt;                &lt;/P&gt;&lt;P&gt;                String API_KEY= "YOUR KEY";&lt;/P&gt;&lt;P&gt;               &lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;            URL url = new URL("https://YYYYYY.live.dynatrace.com/api/v1/userSessionQueryLanguage/table?query=SELECT endTime as time,  userSessionId  , SUM((useraction.visuallyCompleteTime)) AS 'Server Processing Time'FROM usersession WHERE (userId='Full Quote User 1' OR internalUserId='Full Quote User' or userId='Full Quote User 2' or userId='Full Quote User 3' or userId=\"Full Quote User\") and userActionCount &amp;gt; 25 and userActionCount &amp;lt;50 GROUP BY  endTime ,userSessionId&amp;amp;startTimestamp=1586905282288");&lt;/P&gt;&lt;P&gt;            &lt;/P&gt;&lt;P&gt;            HttpURLConnection conn = (HttpURLConnection) url.openConnection();&lt;/P&gt;&lt;P&gt;            conn.setRequestMethod("GET");&lt;/P&gt;&lt;P&gt;            conn.setRequestProperty("Accept", "application/json");&lt;/P&gt;&lt;P&gt;             //conn.addRequestProperty("Authorization", basicAuth);&lt;/P&gt;&lt;P&gt;            conn.setRequestProperty("Authorization", "Api-Token=YYYYYYYY");&lt;/P&gt;&lt;P&gt;            conn.setDoInput(true);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;                &lt;/P&gt;&lt;P&gt;        &lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;            if (conn.getResponseCode() != 200) {&lt;!-- --&gt;&lt;/P&gt;&lt;P&gt;                &lt;/P&gt;&lt;P&gt;                throw new RuntimeException("Failed : HTTP error code : "&lt;/P&gt;&lt;P&gt;                        + conn.getResponseCode());&lt;/P&gt;&lt;P&gt;                &lt;/P&gt;&lt;P&gt;            &lt;/P&gt;&lt;P&gt;            }&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;            BufferedReader br = new BufferedReader(new InputStreamReader(&lt;/P&gt;&lt;P&gt;                (conn.getInputStream())));&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;            String output;&lt;/P&gt;&lt;P&gt;            System.out.println("Output from Server .... \n");&lt;/P&gt;&lt;P&gt;            while ((output = br.readLine()) != null) {&lt;!-- --&gt;&lt;/P&gt;&lt;P&gt;                System.out.println(output);&lt;/P&gt;&lt;P&gt;            }&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;            conn.disconnect();&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;          } catch (MalformedURLException e) {&lt;!-- --&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;            e.printStackTrace();&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;          } catch (IOException e) {&lt;!-- --&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;            e.printStackTrace();&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;          }&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;        }&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;    }&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Apr 2020 15:53:54 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Real-User-Monitoring/Java-rest-service-for-user-sessions-help/m-p/111542#M890</guid>
      <dc:creator>abhilash_mittap</dc:creator>
      <dc:date>2020-04-17T15:53:54Z</dc:date>
    </item>
    <item>
      <title>Re: Java rest service for user sessions help</title>
      <link>https://community.dynatrace.com/t5/Real-User-Monitoring/Java-rest-service-for-user-sessions-help/m-p/111543#M891</link>
      <description>&lt;P&gt;Seems like the URL is invalid. Try encoding the param:&lt;/P&gt;
&lt;PRE&gt;String query = "SELECT&amp;nbsp;endTime as time, userSessionId , SUM((useraction.visuallyCompleteTime)) AS 'Server Processing Time'FROM usersession WHERE (userId='Full Quote User 1' OR internalUserId='Full Quote User' or userId='Full Quote User 2' or userId='Full Quote User 3' or userId=\"Full Quote User\") and userActionCount &amp;gt; 25 and userActionCount &amp;lt;50 GROUP BY endTime ,userSessionId, tTimestamp=1586905282288"&lt;BR /&gt;&lt;CODE&gt;String url = "https://YYYYYY.live.dynatrace.com/api/v1/userSessionQueryLanguage/table?query=" + URLEncoder.encode(query, "UTF-8");&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 27 Mar 2023 10:26:10 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Real-User-Monitoring/Java-rest-service-for-user-sessions-help/m-p/111543#M891</guid>
      <dc:creator>Radoslaw_Szulgo</dc:creator>
      <dc:date>2023-03-27T10:26:10Z</dc:date>
    </item>
    <item>
      <title>Re: Java rest service for user sessions help</title>
      <link>https://community.dynatrace.com/t5/Real-User-Monitoring/Java-rest-service-for-user-sessions-help/m-p/111544#M892</link>
      <description>&lt;P&gt;I think issue is wth api token , any idea how do we set api token &lt;/P&gt;</description>
      <pubDate>Fri, 17 Apr 2020 21:14:27 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Real-User-Monitoring/Java-rest-service-for-user-sessions-help/m-p/111544#M892</guid>
      <dc:creator>abhilash_mittap</dc:creator>
      <dc:date>2020-04-17T21:14:27Z</dc:date>
    </item>
    <item>
      <title>Re: Java rest service for user sessions help</title>
      <link>https://community.dynatrace.com/t5/Real-User-Monitoring/Java-rest-service-for-user-sessions-help/m-p/111545#M893</link>
      <description>&lt;P&gt;You mentioned this was successful using Postman. Did you use the same Token for both Postman and the Java app? If so, then this assumes the API token is set correctly. The API token needs User Sessions permission.&lt;/P&gt;&lt;P&gt;Can you verify this token has this permission?&lt;/P&gt;&lt;P&gt;A second idea:  In your code your API_KEY is set to a string, which I assume you replace with your real API Token.  But then you never use API_KEY string, but instead insert "YYYYYY" as your token.   This API token needs to be the token you get from Dynatrace GUI.  Perhaps this is obvious, but then please explain your code which does not seem to use a valid token.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Apr 2020 22:27:33 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Real-User-Monitoring/Java-rest-service-for-user-sessions-help/m-p/111545#M893</guid>
      <dc:creator>Joe_Hoffman</dc:creator>
      <dc:date>2020-04-17T22:27:33Z</dc:date>
    </item>
    <item>
      <title>Re: Java rest service for user sessions help</title>
      <link>https://community.dynatrace.com/t5/Real-User-Monitoring/Java-rest-service-for-user-sessions-help/m-p/111546#M894</link>
      <description>&lt;P&gt;Hi Joseph , &lt;/P&gt;&lt;P&gt;Yes i am using same API key that i am using in postman . &lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Is below property rightly setup ?&lt;/P&gt;&lt;P&gt;            conn.setRequestProperty("Authorization", "Api-Token=YYYYYBLdTE5Aa");&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Apr 2020 23:21:09 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Real-User-Monitoring/Java-rest-service-for-user-sessions-help/m-p/111546#M894</guid>
      <dc:creator>abhilash_mittap</dc:creator>
      <dc:date>2020-04-17T23:21:09Z</dc:date>
    </item>
    <item>
      <title>Re: Java rest service for user sessions help</title>
      <link>https://community.dynatrace.com/t5/Real-User-Monitoring/Java-rest-service-for-user-sessions-help/m-p/111547#M895</link>
      <description>&lt;P&gt;Yes, your usage of conn.setRequestProperty() seems correct, although I've not tested your code.   Did you explore Radoslaw's suggestion that the URL needs to be encoded?&lt;/P&gt;</description>
      <pubDate>Sat, 18 Apr 2020 02:17:53 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Real-User-Monitoring/Java-rest-service-for-user-sessions-help/m-p/111547#M895</guid>
      <dc:creator>Joe_Hoffman</dc:creator>
      <dc:date>2020-04-18T02:17:53Z</dc:date>
    </item>
    <item>
      <title>Re: Java rest service for user sessions help</title>
      <link>https://community.dynatrace.com/t5/Real-User-Monitoring/Java-rest-service-for-user-sessions-help/m-p/111548#M896</link>
      <description>&lt;P&gt;1. Test the query in our Environment API OpenAPI page. There were some issues with it.&lt;/P&gt;&lt;P&gt;2. Copy the URL from the resulting curl command when you get it working&lt;/P&gt;&lt;P&gt;3. Change your code slightly when setting the headers:&lt;/P&gt;&lt;P&gt;conn.setRequestProperty("accept", "application/json");&lt;/P&gt;&lt;P&gt;conn.setRequestProperty("Authorization", "Api-Token **********************");&lt;/P&gt;&lt;P&gt;accept in lowercase and space rather than "=" after "Api-Token".&lt;/P&gt;&lt;P&gt;I got it working after making these changes and using the URLEncoded URL from the OpenAPI page with this query:&lt;/P&gt;&lt;P&gt;SELECT endTime as time, userSessionId, SUM(useraction.visuallyCompleteTime) AS 'Server Processing Time' FROM usersession WHERE (userId='Full Quote User 1' OR internalUserId='Full Quote User' or userId='Full Quote User 2' or userId='Full Quote User 3' or userId='Full Quote User') and userActionCount &amp;gt; 25 and userActionCount &amp;lt; 50 GROUP BY endTime, userSessionId&lt;/P&gt;&lt;P&gt;4. After you get it working like this, add the URLEncoder as suggested by @Radoslaw S.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Apr 2020 18:17:30 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Real-User-Monitoring/Java-rest-service-for-user-sessions-help/m-p/111548#M896</guid>
      <dc:creator>dave_mauney</dc:creator>
      <dc:date>2020-04-21T18:17:30Z</dc:date>
    </item>
    <item>
      <title>Re: Java rest service for user sessions help</title>
      <link>https://community.dynatrace.com/t5/Real-User-Monitoring/Java-rest-service-for-user-sessions-help/m-p/111549#M897</link>
      <description>&lt;P&gt;Please read my comment earlier.  You need to remove the "=" after Api-Token".&lt;/P&gt;</description>
      <pubDate>Wed, 22 Apr 2020 12:08:55 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Real-User-Monitoring/Java-rest-service-for-user-sessions-help/m-p/111549#M897</guid>
      <dc:creator>dave_mauney</dc:creator>
      <dc:date>2020-04-22T12:08:55Z</dc:date>
    </item>
  </channel>
</rss>

