diff --git a/apiTMDB.iml b/apiTMDB.iml new file mode 100644 index 0000000..31149be --- /dev/null +++ b/apiTMDB.iml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/out/production/apiTMDB/apiTMDB.class b/out/production/apiTMDB/apiTMDB.class new file mode 100644 index 0000000..b12d0e8 Binary files /dev/null and b/out/production/apiTMDB/apiTMDB.class differ diff --git a/out/production/apiTMDB/gui$1.class b/out/production/apiTMDB/gui$1.class new file mode 100644 index 0000000..aba6256 Binary files /dev/null and b/out/production/apiTMDB/gui$1.class differ diff --git a/out/production/apiTMDB/gui.class b/out/production/apiTMDB/gui.class new file mode 100644 index 0000000..2ba128b Binary files /dev/null and b/out/production/apiTMDB/gui.class differ diff --git a/out/production/apiTMDB/main.class b/out/production/apiTMDB/main.class new file mode 100644 index 0000000..d1814e9 Binary files /dev/null and b/out/production/apiTMDB/main.class differ diff --git a/src/apiTMDB.java b/src/apiTMDB.java new file mode 100644 index 0000000..b11eca6 --- /dev/null +++ b/src/apiTMDB.java @@ -0,0 +1,52 @@ +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.net.MalformedURLException; +import java.net.URL; +import java.nio.charset.Charset; + +public class apiTMDB { + private static final String apikey = "9fd90530b11447f5646f8e6fb4733fb4"; + + public apiTMDB(){ + String json=""; + try { + URL apiurl = new URL("https://api.themoviedb.org/3/movie/550?api_key=9fd90530b11447f5646f8e6fb4733fb4"); + BufferedReader myreader = new BufferedReader(new InputStreamReader(apiurl.openStream(), Charset.forName("UTF-8"))); + json = readAll(myreader); + + JSONParser pars = new JSONParser(); + + JSONObject jsonobj = (JSONObject) pars.parse(json); + System.out.println(jsonobj.get("id")); + + System.out.println(json); + } catch (MalformedURLException ex) { + ex.printStackTrace(); + } catch (IOException ex) { + ex.printStackTrace(); + } catch (ParseException e) { + e.printStackTrace(); + } + + + } + + private String readAll(Reader rd) throws IOException { + StringBuilder sb = new StringBuilder(); + int cp; + while ((cp = rd.read()) != -1) { + sb.append((char) cp); + } + return sb.toString(); + } + + + + +} diff --git a/src/gui.java b/src/gui.java new file mode 100644 index 0000000..6f6bc24 --- /dev/null +++ b/src/gui.java @@ -0,0 +1,98 @@ +import com.sun.jndi.toolkit.url.UrlUtil; +import com.sun.webkit.network.Util; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.net.Authenticator; +import java.net.MalformedURLException; +import java.net.PasswordAuthentication; +import java.net.URL; +import java.nio.charset.Charset; + +public class gui extends JFrame { + + JPasswordField passfield; + JTextField userfield; + + JLabel logininfo; + + public gui(){ + this.setTitle("TMDB api"); + this.setSize(500,500); + + addelements(); + addlisteners(); + + this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); + this.setVisible(true); + } + + private boolean setProxy(String authUser, String authPassword) { + Authenticator.setDefault( + new Authenticator() { + @Override + public PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication( + authUser, authPassword.toCharArray()); + } + } + ); + + //set https proxy + System.setProperty("jdk.http.auth.tunneling.disabledSchemes", ""); + System.setProperty("https.proxyUser", authUser); + System.setProperty("https.proxyPassword", authPassword); + System.setProperty("https.proxyHost", "proxy.htl-steyr.ac.at"); + System.setProperty("https.proxyPort", "8082"); + + //set http proxy + System.setProperty("http.proxyUser", authUser); + System.setProperty("http.proxyPassword", authPassword); + System.setProperty("http.proxyHost", "proxy.htl-steyr.ac.at"); + System.setProperty("http.proxyPort", "8082"); + + try { + new URL("http://google.com").openStream(); + new URL("https://google.com").openStream(); + return true; + } catch (IOException e1) { + return false; + } + } + + private void addlisteners(){ + passfield.addActionListener(e -> { + if(setProxy(userfield.getText(),String.copyValueOf(passfield.getPassword()))){ + logininfo.setText("logged in successfully"); + }else{ + logininfo.setText("loggin error!"); + } + new apiTMDB(); + +// + }); + } + + private void addelements(){ + this.setLayout(new BorderLayout()); + userfield = new JTextField(); + passfield = new JPasswordField(); + + logininfo = new JLabel("Not logged in yet"); + + JPanel authpanel = new JPanel(new GridLayout(2,2)); + authpanel.add(new JLabel("User:")); + authpanel.add(userfield); + authpanel.add(new JLabel("Password:")); + authpanel.add(passfield); + + this.add(logininfo,BorderLayout.SOUTH); + this.add(authpanel,BorderLayout.NORTH); + } +} diff --git a/src/main.java b/src/main.java new file mode 100644 index 0000000..c2200ec --- /dev/null +++ b/src/main.java @@ -0,0 +1,5 @@ +public class main { + public static void main(String[] args) { + new gui(); + } +}