Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
So, there is no any problem to make xmlhttp request to QV server from Java. But there is one requirement to make it done - the session should be authorised on the QV server with credentials of Windows OS user who is allowed to make such request.
I have such user. I've done this with VBScript and QVSRemote.Client object as a prototype.
I'm trying to do the same on Java. Does anybody have an idea how to make it work in Java? I need just getTicket method implementation for this.
Here it is:
import com.sun.deploy.xml.XMLParser;
import java.io.*;
import java.net.*;
import java.util.Properties;
publicclass Main {
public static void main(String[] argv) throws Exception {
byte[] b = new byte[1];
Properties systemSettings = System.getProperties();
systemSettings.put("http.proxyHost","qlickview.server.com");
systemSettings.put("http.proxyPort", "80");
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("Domain\\User","Password".toCharArray());
}
});
String url = "http://qlikview.server.com/qvajaxzfc/GetTicket.aspx?";
String charset = "UTF-8";
URLConnection urlConnection = new URL(url).openConnection();
urlConnection.setUseCaches(false);
urlConnection.setDoOutput(true); // Triggers POST.
urlConnection.setRequestProperty("accept-charset", charset);
urlConnection.setRequestProperty("content-type","application/x-www-form-urlencoded");
OutputStreamWriter writer = null;
try {
writer = new OutputStreamWriter(urlConnection.getOutputStream(), charset);
writer.write("<Globalmethod=\"GetTicket\"><UserId>blablabla</UserId><GroupList></GroupList><GroupListIsNames>true</GroupListIsNames></Global>");// Write POST query string (if any needed).
} finally {
if (writer != null) try { writer.close(); } catch (IOException logOrIgnore) {}
}
String resultXMLstr = convertStreamToString(urlConnection.getInputStream());XMLParser parser = new XMLParser(resultXMLstr);
System.out.println(parser.parse().getNested().getNested().toString());
}
public static String convertStreamToString(InputStream is) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
return sb.toString();
}
}
Here it is:
import com.sun.deploy.xml.XMLParser;
import java.io.*;
import java.net.*;
import java.util.Properties;
publicclass Main {
public static void main(String[] argv) throws Exception {
byte[] b = new byte[1];
Properties systemSettings = System.getProperties();
systemSettings.put("http.proxyHost","qlickview.server.com");
systemSettings.put("http.proxyPort", "80");
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("Domain\\User","Password".toCharArray());
}
});
String url = "http://qlikview.server.com/qvajaxzfc/GetTicket.aspx?";
String charset = "UTF-8";
URLConnection urlConnection = new URL(url).openConnection();
urlConnection.setUseCaches(false);
urlConnection.setDoOutput(true); // Triggers POST.
urlConnection.setRequestProperty("accept-charset", charset);
urlConnection.setRequestProperty("content-type","application/x-www-form-urlencoded");
OutputStreamWriter writer = null;
try {
writer = new OutputStreamWriter(urlConnection.getOutputStream(), charset);
writer.write("<Globalmethod=\"GetTicket\"><UserId>blablabla</UserId><GroupList></GroupList><GroupListIsNames>true</GroupListIsNames></Global>");// Write POST query string (if any needed).
} finally {
if (writer != null) try { writer.close(); } catch (IOException logOrIgnore) {}
}
String resultXMLstr = convertStreamToString(urlConnection.getInputStream());XMLParser parser = new XMLParser(resultXMLstr);
System.out.println(parser.parse().getNested().getNested().toString());
}
public static String convertStreamToString(InputStream is) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
return sb.toString();
}
}
HI Nick,
I'm trying your code on QlikView 11 server, but I'm getting a 400-bad request error. Kindly give some idea how to resolve this?
Is there configuration that I need to sertup?
Thanks,
Arnold
Hi Arnold,
you are getting bad request error because xml creation in the code has tippfehler; should be
writer.write("<Global method=...
regards