I'm trying to login to google using HtmlUnit in an app in GAE.
However, I keep getting this error:
Exception invoking jsxGet_cookie
Which is because
Caused by: java.lang.IllegalArgumentException: Invalid port: -1
at org.apache.http.cookie.CookieOrigin.<init>(CookieOrigin.java:58)
at com.gargoylesoftware.htmlunit.CookieManager.getCookies(CookieManager.java:127)
at com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument.jsxGet_cookie(HTMLDocument.java:638)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:100)
at net.sourceforge.htmlunit.corejs.javascript.MemberBox.invoke(MemberBox.java:172)
... 94 more
This occurs when running in GAE and in my computer.
Has anybody ever seen this kind of error before?
How can I change the default Port?
Are there any workarounds?
Change the URL you are fetching to include the default port 80. Example: http://www.cnn.com becomes http://www.cnn.com:80. There's also a workaround involving overriding classes but I prefer to clarify the URL.
I had that problem at first (I have a GWT+GAE app) and I was using this very simple code and I got the js cookie exception and the port:-1 exception
WebClient webClient = Holder.get();
HtmlPage page=null;
try {
page = webClient.getPage(url);
System.out.println("CRAWLER DONE");
} 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();
}
// appengine hack because it's single threaded
String pageContent = page.asXml();
webClient.closeAllWindows();
return pageContent;
then I tried the following,
webClient.setCssEnabled(false);
webClient.setThrowExceptionOnFailingStatusCode(false);
webClient.setThrowExceptionOnScriptError(false);
And it just miracusly worked. cheers.
Related
I tried to implement google login in my project but it is giving me unknown host error after signing in with gmail username and password & then pressing the allow button. I have also kept android.playService.plus in build hint. Are other build hints necessary too? I didn't find proper documentation or blog to apply it as well.My code is as follow:
if (googleLogin.isNativeLoginSupported()) {
if (!googleLogin.isUserLoggedIn()) {
googleLogin.doLogin();
}
AccessToken at = googleLogin.getAccessToken();
System.out.println("token " + at.getToken()); // this value is null
} else {
if (!googleLogin.isUserLoggedIn()) {
googleLogin.doLogin();
System.out.println("not logged in : not native login");
}
}
googleLogin.setCallback(new LoginCallback() {
#Override
public void loginFailed(String errorMessage) {
Dialog.show("Login Faild", "Retry Login", "Retry", null);
google_signIn(res);
}
#Override
public void loginSuccessful() {
System.out.println("successfull");
new NewForm(res).show();
}
});
Error:
Received exception: Unknown host
java.lang.Throwable: Unknown host
at javafx.scene.web.WebEngine$LoadWorker.describeError(WebEngine.java:1402)
at javafx.scene.web.WebEngine$LoadWorker.dispatchLoadEvent(WebEngine.java:1341)
at javafx.scene.web.WebEngine$LoadWorker.access$1100(WebEngine.java:1219)
at javafx.scene.web.WebEngine$PageLoadListener.dispatchLoadEvent(WebEngine.java:1206)
at com.sun.webkit.WebPage.fireLoadEvent(WebPage.java:2387)
at com.sun.webkit.WebPage.fwkFireLoadEvent(WebPage.java:2231)
at com.sun.webkit.network.URLLoader.twkDidFail(Native Method)
at com.sun.webkit.network.URLLoader.notifyDidFail(URLLoader.java:843)
at com.sun.webkit.network.URLLoader.lambda$didFail$93(URLLoader.java:826)
at com.sun.webkit.network.URLLoader$$Lambda$197/728465605.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$164(PlatformImpl.java:292)
at com.sun.javafx.application.PlatformImpl$$Lambda$63/2017575979.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(PlatformImpl.java:291)
at com.sun.javafx.application.PlatformImpl$$Lambda$62/1811810557.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$141(WinApplication.java:102)
at com.sun.glass.ui.win.WinApplication$$Lambda$54/5182121.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
On the simulator we need to use web login as there is no native login and it uses a web page which might not look great.
On the device native login is used and should feel seamless. It's important to check devices for this sort of functionality as they behave very differently.
when sending a message through a JMS topic, I often get the following warning:
2016-07-22 14:32:02,418 WARN [org.apache.activemq.artemis.jms.client] (Finalizer) AMQ122000: I''m closing a JMS connection you left open. Please make sure you close all JMS connections explicitly before letting them go out of scope! see stacktrace to find out where it was created: java.lang.Exception
at org.apache.activemq.artemis.jms.client.ActiveMQConnection.<init>(ActiveMQConnection.java:155)
at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnectionInternal(ActiveMQConnectionFactory.java:750)
at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createContext(ActiveMQConnectionFactory.java:255)
at org.wildfly.extension.messaging.activemq.deployment.JMSContextProducer$JMSContextWrapper.create(JMSContextProducer.java:195)
at org.wildfly.extension.messaging.activemq.deployment.JMSContextProducer$JMSContextWrapper.getDelegate(JMSContextProducer.java:235)
at org.wildfly.extension.messaging.activemq.deployment.JMSContextProducer$JMSContextWrapper.createProducer(JMSContextProducer.java:270)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:139)
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:295)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:249)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:236)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:395)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:202)
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:221)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
My code:
#Inject
#JMSConnectionFactory("java:/ConnectionFactory")
private JMSContext context;
#Resource(lookup = "java:/jms/topic/MyTopic", type = Long.class)
private Topic topic;
public void sendMessage(Event event) {
try {
context.createProducer().send(topic, 1L);
} catch (Exception e) {;
log.error("Error while sending message to the JMS topic. Will retry later.", e);
}
}
Any idea? I couldn't find anything on google yet.
According to JMSContext javadoc, the connection should be automatically closed when it's managed by the application server.
I think the message clearly explains the problem. Probably you just need to call close() or some sort on the producer you created.
Edit:
Actually, it is not the produced that needs closing, but the context.
From the doc (https://docs.oracle.com/javaee/7/api/javax/jms/JMSContext.html):
All these JMSContext objects are application-managed and must be
closed when no longer needed by calling their close method.
About the producer, it says (https://docs.oracle.com/javaee/7/api/javax/jms/JMSProducer.html):
Instances of JMSProducer are intended to be lightweight objects which
can be created freely and which do not consume significant resources.
This interface therefore does not provide a close method.
I'm trying to write to cloud bigtable in my app engine servlet. I copied the BigTableHelper from https://github.com/GoogleCloudPlatform/cloud-bigtable-examples/blob/master/java/managed-vm-gae/gae-bigtable-hello/src/main/java/com.example.cloud.bigtable.helloworld/BigtableHelper.java, and in my servlet I simply did the following.
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
try (Table t = BigtableHelper.getConnection().getTable(BigtableHelper.TEST_TABLE)) {
Put put = new Put(Bytes.toBytes("row1"));
put.addColumn(BigtableHelper.RAW_UPDATE_FAMILY, BigtableHelper.RAW_UPDATE_QUALIFIER,
Bytes.toBytes("testdata"));
t.put(put);
} catch (IOException e) {
log("writeToBigtable", e);
}
}
The put failed with error.
java.io.IOException: Failed to perform operation. Operation='put', projectId='myprojectid', tableName='test_table', rowKey='row1' at com.google.cloud.bigtable.hbase.BigtableTable.put(BigtableTable.java:288) at ...
Caused by: com.google.bigtable.repackaged.com.google.common.util.concurrent.UncheckedExecutionException: io.grpc.StatusRuntimeException: UNKNOWN at io.grpc.stub.Calls.getUnchecked(Calls.java:117) at io.grpc.stub.Calls.blockingUnaryCall(Calls.java:129) at com.google.cloud.bigtable.grpc.BigtableGrpcClient.mutateRow(BigtableGrpcClient.java:210) at com.google.cloud.bigtable.hbase.BigtableTable.put(BigtableTable.java:285) ... 32 more
Caused by: io.grpc.StatusRuntimeException: UNKNOWN at io.grpc.Status.asRuntimeException(Status.java:428) at io.grpc.stub.Calls$UnaryStreamToFuture.onClose(Calls.java:324) at io.grpc.ChannelImpl$CallImpl$ClientStreamListenerImpl$3.run(ChannelImpl.java:402) at io.grpc.SerializingExecutor$TaskRunner.run(SerializingExecutor.java:154) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) ... 1 more
Caused by: java.nio.channels.ClosedChannelException
BigtableHelper.getConnection() didn't throw an exception, I assume the it connect successfully. Is there anything wrong with the put statement? What could cause this problem? Thanks!
We have updated examples for interacting with Cloud Bigtable from Google App Engine Flex and Standard using Java 8 here:
https://github.com/googlecloudplatform/java-docs-samples/tree/master/appengine-java8/bigtable
https://github.com/GoogleCloudPlatform/cloud-bigtable-examples/tree/master/java/gae-flexible-helloworld
I've implemented JSend NSCA to send passive checks to Nagios like below:
public static void main(String[] args) {
NagiosSettings nagiosSettings = new NagiosSettingsBuilder()
.withNagiosHost("192.168.1.20")
.withPassword("nagiosadmin")
.withPort(5666)
.withConnectionTimeout(5000)
.withResponseTimeout(15000)
.create();
NagiosPassiveCheckSender sender = new NagiosPassiveCheckSender(
nagiosSettings);
MessagePayload payload = new MessagePayloadBuilder()
.withHostname("localhost")
.withLevel(Level.CRITICAL)
.withServiceName("Test Service Name")
.withMessage("Test Message")
.create();
try {
sender.send(payload);
} catch (NagiosException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
But I had the following errors:
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:432)
at java.net.Socket.connect(Socket.java:529)
at com.googlecode.jsendnsca.core.NagiosPassiveCheckSender.send(NagiosPassiveCheckSender.java:69)
at app.QuickStart.main(QuickStart.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Nagios Username and password are: nagiosadmin/nagiosadmin.
The IPserver for nagios is 192.168.1.20.
Thank you.
Can you try a quick telnet test
From your command line run
telnet 192.168.1.20 5666
If the response is
Connecting To 192.168.1.20...Could not open connection to the host, on port 5666: Connect failed
Then the NSCA daemon is either
not running
running on a different port other than 5666
BTW, Im the project lead for jsendnsca. In future, you can post questions like this at
https://code.google.com/p/jsendnsca/issues/list
and create an issue
I was trying to read through the mails in my gmail account using java mail API. This is the code:
import java.util.*;
import java.io.*;
import java.awt.*;
import javax.mail.*;
import javax.mail.search.FlagTerm;
import javax.mail.Flags.Flag;
public class MailPharser {
/**
* #param args
*/
public void mailRead()
{
Folder inbox;
// TODO Auto-generated method stub
Properties props = System.getProperties();
props.setProperty("mail.store.protocol", "imaps");
try
{
Session session = Session.getDefaultInstance(props, null);
Store store = session.getStore("imaps");
store.connect("imap.gmail.com","<mailid#gmail.com>", "<password>");
inbox = store.getFolder("Inbox");
System.out.println("No of Unread Messages : " + inbox.getUnreadMessageCount());
}
catch (Exception ex)
{ System.out.println("Error caught"); ex.printStackTrace(); }
}
public static void main(String[] args) {
MailPharser mp = new MailPharser();
mp.mailRead();
}
}
While running, i am getting the below error:
javax.mail.MessagingException: Connection reset;
nested exception is:
java.net.SocketException: Connection reset
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:670)
at javax.mail.Service.connect(Service.java:295)
at javax.mail.Service.connect(Service.java:176)
at MailPharser.mailRead(MailPharser.java:26)
at MailPharser.main(MailPharser.java:40)
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at com.sun.net.ssl.internal.ssl.InputRecord.readFully(Unknown Source)
at com.sun.net.ssl.internal.ssl.InputRecord.read(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:548)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:352)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:233)
at com.sun.mail.iap.Protocol.<init>(Protocol.java:113)
at com.sun.mail.imap.protocol.IMAPProtocol.<init>(IMAPProtocol.java:111)
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:637)
... 4 more
I added trace and see that the connect call is failing. Am i doing anything wrong? any help would do. thanks in advance...
It's probably a network problem unrelated to JavaMail, e.g., a proxy or firewall between you and Gmail.
If you want to find out whether it's your code that's broken or the network that's broken, you can test using the code that comes with JavaMail. If the JavaMail code works, then you know there's something wrong with your code, and you can use the JavaMail code in the FAQ to improve your code.
If you discover that it's a network problem, the JavaMail FAQ also has tips for debugging it further.