I am trying to write code in Processing (basically Java) that will get the information from the table here: http://science.nasa.gov/iSat/iSAT-text-only/
I have not started writing the code specific to the table yet because I can't even get this to run. I get the error "type String is ambiguous." I cannot find any duplicate of String nor can I think of any other reason for this error.
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.*;
import java.net.*;
WebClient client = new WebClient(BrowserVersion.CHROME);
try {
java.lang.String url = "http://science.nasa.gov/iSat/iSAT-text-only/";
Page page = client.getPage(url);
println(page.getWebResponse().getContentAsString());
}
catch(IOException e) {
println("oops!");
}
UPDATE:
I modified the code slightly and got it to get the information I want using the following code in eclipse:
WebClient client = new WebClient();
String url = "http://science.nasa.gov/iSat/iSAT-text-only/";
HtmlPage page = null;
try {
page = (HtmlPage) client.getPage(url);
} catch (FailingHttpStatusCodeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
client.waitForBackgroundJavaScript(10000);
System.out.print(page.asXml());
but it still throws the ambiguous String error in Processing.
Bizarrely, manually importing java.lang.String fixed the error.
Related
I'm trying to make an application for my school website (reggienet.illinoisstate.edu), but I'm having trouble getting entering the login and having it stored in the cookies that I am logged in. I've scoured the web and tried everything I could find, but nothing is working I'm totally lost.
Here is the code that I have right now
public void login()
{
HtmlPage currentPage = null;
Scanner keyboard = new Scanner(System.in);
WebClient webClient = new WebClient();
try
{
webClient = reggieLogin(webClient, keyboard);
}
catch (Exception e)
{
e.printStackTrace();
}
try
{
currentPage = webClient.getPage(""https://reggienet.illinoisstate.edu/portal"");
}
catch (FailingHttpStatusCodeException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (MalformedURLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
String pageSource = currentPage.asXml();
System.out.print(pageSource);
}
private WebClient reggieLogin(WebClient webClient, Scanner keyboard) throws Exception
{
webClient.getOptions().setJavaScriptEnabled(false);
HtmlPage currentPage = webClient.getPage("https://account.illinoisstate.edu/centrallogin/"); //Load page at the STRING address.
HtmlInput username = currentPage.getElementByName("username"); //Find element called loginuser for username
System.out.print("ULID: ");
username.setValueAttribute(keyboard.nextLine()); //Set value for username
HtmlInput password = currentPage.getElementByName("password"); //Find element called loginpassword for password
System.out.print("Password: ");
password.setValueAttribute(keyboard.nextLine()); //Set value for password
HtmlButtonInput submitBtn = currentPage.getElementByName("submit"); //Find element called Submit to submit form.
currentPage = submitBtn.click(); //Click on the button.
return webClient;
}
Can anybody offer any help, or can anybody see what's wrong with this code?
Consider using the Selenium library to interact with websites. It has methods for editing browser cookies. Here is a link to its java documentation.
I would like to leverage nested object indexing in Elastic Search. I know how to do that with PUT requests through curl (https://www.elastic.co/guide/en/elasticsearch/guide/current/nested-mapping.html) but I would like to do that through Java API instead.
Here is how I create dynamically my index
public void index(AnObject obj){
Client client = elasticService.getES();
// generate json
if (client != null){
try {
byte[] json = JSON.serializeAsBytes(obj);
IndexResponse response = client.prepareIndex("titan", "objIndex", obj.getUuid())
.setSource(json)
.get();
} catch (ElasticsearchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
and here is how I update it
public void updateIndex(AnObject obj){
Client client = elasticService.getES();
// generate json
if (client != null){
try {
byte[] json = JSON.serializeAsBytes(obj);
UpdateResponse response = client.prepareUpdate("titan", "objIndex", obj.getUuid())
.setDoc(json)
.get();
} catch (ElasticsearchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
I wonder if there is a way to set my index through Java so that specific or all of the embedded objects are mapped as nested
If that is not possible is it possible to configure Elastic search default mapping to index everything as datatype nested?
Any help is appreciated! Thanks!
I am trying to browse a uri that is more indepth than just the .com domain here's the code. But its claiming there's a syntax exception and when i throw it it still doesn't work.
import java.awt.Desktop;
import java.net.URI;
class Gui {
public static void main(String[] args) throws Exception {
URI GoogleplusURL = new URI("https://plus.google.com//u//0//115793082536946778715//posts");
Desktop.getDesktop().browse(GoogleplusURL);
}
}
There is no problem with your code.
Following format of code will help you understand the issue. Your code can throw two type of exception
URISyntaxException -- When you use invalid url syntax
Example: replace your url with https://plus.google.com/u/0/115793082536946778715/^posts
IOException -- This will occur when url is not valid
public static void main(String[] args) {
URI GoogleplusURL;
try {
GoogleplusURL = new URI("https://plus.google.com/u/0/115793082536946778715/posts");
Desktop.getDesktop().browse(GoogleplusURL);
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
In case you worrying about url is not working ? try to change your url
From: https://plus.google.com//u//0//115793082536946778715//posts
To: https://plus.google.com/u/0/115793082536946778715/posts
I am creating java files from json Objects using a library called jsonschema2pojo-core.jar. It successfully creates the required files for me. Now I need to access the newly(dynamically) created file and creates its instance to use it further.
But as the newly created class is still not in the classpath I am unable to do this. Tried to do my part of research and figured out that Eclipse jars allows such refresh only in plugin projects. Can anyone suggest some thing for this?
public static void main(String[] args){
String fileName = "MyJavaFile";
POJOBuilder pojo = new POJOBuilder();
pojo.buildPOJO("file:///C:/mypath/myJSON.json", fileName); //generates the java file MyJavaFile.java
Object obj = null;
try {
obj = Class.forName("com.mypackage."+fileName).newInstance(); // Java file not available yet
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Can this be done through threads? I mean wait until the creation of the POJO is done and then start with the rest after that?
The Following Code is throwing the above warning:
Warning: failed to read path from javaldx
if((JButton)e.getSource()==helpButton)
{
System.out.println("-------------Help Button is pressed..----------------------");
URL helpDocument=NewCellTrenderGUILauncher.class.getClass().getResource("/G1-G2Help.doc");
System.out.println("URL Constructed-->"+helpDocument.toString());
File helpDocPath=null;
try
{
System.out.println("URI constructed from URL="+helpDocument.toURI());
helpDocPath = new File(helpDocument.toURI());
System.out.println("File Path Constructed from URI="+helpDocPath.toString());
} catch (URISyntaxException e2)
{
// TODO Auto-generated catch block
System.err.println("\n\t***********************EXCEPTION*****************");
System.err.println("\tDue to--->"+e2);
System.err.println("\tExceptionType--->"+e2.getMessage());
e2.printStackTrace();
System.err.println("\t**************************************************");
}
if(Desktop.isDesktopSupported())
{
System.out.println("DesktopSupported is TRUE..!!");
try
{
Desktop.getDesktop().open(helpDocPath);
System.out.println("FileOpened From Desktop..!!");
} catch (IOException e1)
{
// TODO Auto-generated catch block
System.err.println("\n\t***********************EXCEPTION*****************");
System.err.println("\tDue to--->"+e1);
System.err.println("\tExceptionType--->"+e1.getMessage());
e1.printStackTrace();
System.err.println("\t**************************************************");
FileRenderer.openFile(helpDocPath.toString());
System.out.println("File opened from FileReneder..!!");
}
}
else
{
System.out.println("Desptop is Not Supported..!!!");
FileRenderer.openFile(helpDocPath.toString());
System.out.println("File opened from FileReneder..!!");
}
}
The above code throws warning on the development machine,but it creates the correct path and eventually opens the file correctly. But, in case of production environment, where the platform os is Windows, it throws a null pointer exception on the following line--->
URL helpDocument=NewCellTrenderGUILauncher.class.getClass().getResource("/G1-G2Help.doc");
Please help to rectify the error..
The getResourceAsStream will do the job easily.. Try it