C2DM not being send- No subject alternative DNS name matching android.clients.google.com found - google-app-engine

Hi I have the following code which is supposed to c2dm to an android device. When I run it on my local machine, I get an error
stating: Exception in thread "main"
javax.net.ssl.SSLHandshakeException:
java.security.cert.CertificateException: No subject alternative DNS
name matching android.clients.google.com found.
Does anyone
public class MessageUtil
{
private final static String AUTH = "authentication";
private static final String UPDATE_CLIENT_AUTH = "Update-Client-Auth";
public static final String PARAM_REGISTRATION_ID = "registration_id";
public static final String PARAM_DELAY_WHILE_IDLE = "delay_while_idle";
public static final String PARAM_COLLAPSE_KEY = "collapse_key";
private static final String UTF8 = "UTF-8";
public static void main(String args[]) throws IOException
{
String auth_token=AuthenticationUtil.token;
String registrationId="c2dmregistration id of the device";
String message_title="Test";
int response=sendMessage(auth_token, registrationId,message_title);
System.out.println(response);
}
public static int sendMessage(String auth_token, String registrationId,String message_title) throws IOException
{
URL url = new URL("https://android.clients.google.com/c2dm/send");
StringBuilder postDataBuilder = new StringBuilder();
postDataBuilder.append(PARAM_REGISTRATION_ID).append("=").append(registrationId);
postDataBuilder.append("&").append(PARAM_COLLAPSE_KEY).append("=").append("0");
postDataBuilder.append("&").append("data.payload").append("=").append(URLEncoder.encode(message_title, UTF8));
byte[] postData = postDataBuilder.toString().getBytes(UTF8);
HttpURLConnection conn= (HttpURLConnection)url.openConnection();
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
conn.setRequestProperty("Content-Length",Integer.toString(postData.length));
conn.setRequestProperty("Authorization", "GoogleLogin auth="+ auth_token);
OutputStream out = conn.getOutputStream();
out.write(postData);
out.close();
int responseCode = conn.getResponseCode();
return responseCode;
}
}
When I run this code, I'm getting the following error:
Exception in thread "main" javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No subject alternative DNS name matching android.clients.google.com found.
at sun.security.ssl.Alerts.getSSLException(Unknown Source)
at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
at sun.security.ssl.ClientHandshaker.serverCertificate(Unknown Source)
at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source)
at sun.security.ssl.Handshaker.processLoop(Unknown Source)
at sun.security.ssl.Handshaker.process_record(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(Unknown Source)
at com.metalclub.mobile.inbox.MessageUtil.sendMessage(MessageUtil.java:45)
at com.metalclub.mobile.inbox.MessageUtil.main(MessageUtil.java:24)
Caused by: java.security.cert.CertificateException: No subject alternative DNS name matching android.clients.google.com found.
at sun.security.util.HostnameChecker.matchDNS(Unknown Source)
at sun.security.util.HostnameChecker.match(Unknown Source)
at sun.security.ssl.X509TrustManagerImpl.checkIdentity(Unknown Source)
at sun.security.ssl.X509TrustManagerImpl.checkTrusted(Unknown Source)
at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source)
... 14 more

You're sending the message to the wrong API endpoint. The correct URL is https://android.apis.google.com/c2dm/send

Related

Flink pattern getting issue with Arralist in alert code?

I followed this example and implemented with kafka json same sample data.
consumer sample data {"temperature" : 28,"machineName":"xyz"}
DataStream<Alert> patternStream = CEP.pattern(inputEventStream, warningPattern)
.flatSelect(new PatternFlatSelectFunction<TemperatureEvent, Alert>() {
private static final long serialVersionUID = 1L;
#Override
public void flatSelect(Map<String, List<TemperatureEvent>> event, Collector<Alert> out) throws Exception {
new Alert("Temperature Rise Detected:" + ((TemperatureEvent) event.get("first")).getTemperature()
+ " on machine name:" + ((MonitoringEvent) event.get("first")).getMachineName());
}
Now i am getting issue with ArrayList cast
Exception in thread "main" org.apache.flink.runtime.client.JobExecutionException: Job execution failed.
at org.apache.flink.runtime.jobmaster.JobResult.toJobExecutionResult(JobResult.java:146)
at org.apache.flink.runtime.minicluster.MiniCluster.executeJobBlocking(MiniCluster.java:647)
at org.apache.flink.streaming.api.environment.LocalStreamEnvironment.execute(LocalStreamEnvironment.java:123)
at Test.KafkaApp.main(KafkaApp.java:61)
Caused by: java.lang.ClassCastException: java.util.ArrayList cannot be cast to Test.TemperatureEvent
at Test.KafkaApp$2.flatSelect(KafkaApp.java:53)
at org.apache.flink.cep.operator.FlatSelectCepOperator.processMatchedSequences(FlatSelectCepOperator.java:66)
at org.apache.flink.cep.operator.AbstractKeyedCEPPatternOperator.processEvent(AbstractKeyedCEPPatternOperator.java:382)
at org.apache.flink.cep.operator.AbstractKeyedCEPPatternOperator.processElement(AbstractKeyedCEPPatternOperator.java:198)
at org.apache.flink.streaming.runtime.io.StreamInputProcessor.processInput(StreamInputProcessor.java:202)
at org.apache.flink.streaming.runtime.tasks.OneInputStreamTask.run(OneInputStreamTask.java:105)
at org.apache.flink.streaming.runtime.tasks.StreamTask.invoke(StreamTask.java:300)
at org.apache.flink.runtime.taskmanager.Task.run(Task.java:704)
at java.lang.Thread.run(Unknown Source)
Your code contains two problems:
First of all flatSelect receives a Map<String, List<TemperatureEvent>>. This means that you get potentially multiple TemperatureEvents per pattern. Thus, you have to select which one you want.
You don't add any Alerts to the Collector<Alert>. A flat map function does not return values but outputs them via a Collector<Alert>
Without compiling, I think this should do the trick
DataStream<Alert> patternStream = CEP.pattern(inputEventStream, warningPattern)
.flatSelect(
new PatternFlatSelectFunction<TemperatureEvent, Alert>() {
private static final long serialVersionUID = 1L;
#Override
public void flatSelect(Map<String, List<TemperatureEvent>> event, Collector<Alert> out) throws Exception {
TemperatureEvent temperatureEvent = event.get("first").get(0);
out.collect(new Alert("Temperature Rise Detected:" + temperatureEvent.getTemperature() + " on machine name:" + temperatureEvent.getMachineName()));
}
});
By the way, the linked code from the O'Reilly repository won't compile with Flink. The PatternSelectFunction has the wrong signature.

TypeInformation for Apache Flink 1.3.2 BatchTableEnvironment's translate method

I tried a couple of flink translate() functions in Apache Flink 1.3.2: One is from BatchTableEnvironment and one is from StreamTableEnvironment. The program gave me the errors and I got lost. The following program throws an Exception when run (don't know what TypeInformation it needs). It just uses the type information that should match exactly what the result needs. But it does not work, any help? I think I provided all the details...the
import org.apache.flink.api.common.typeinfo.TypeInformation;
import org.apache.flink.api.java.DataSet;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.table.api.BatchTableEnvironment;
import org.apache.flink.table.api.Table;
import org.apache.flink.table.api.TableEnvironment;
/**
*
* #author Paul Z. Wu Oct 28, 2017
*/
public class TableEnv {
public static void main(String s[]) throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tEnv = TableEnvironment.getTableEnvironment(env);
DataSet<WC> input = env.fromElements(
new WC("Hello", 1),
new WC("Ciao", 1),
new WC("Hello", 1));
tEnv.registerDataSetInternal("abc", input);
Table table = tEnv.scan("abc");
Table wordCounts = table
.groupBy("word")
.select("word, count.sum as count");
System.out.println(wordCounts.getSchema());
DataSet<WC> a = tEnv.translate(wordCounts, TypeInformation.of(WC.class));
a.print();
}
public static class WC {
public WC(String word, int count) {
this.word = word;
this.count = count;
}
public WC() {
} // empty constructor to satisfy POJO requirements
public String word;
public int count;
}
}
The exception is:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/flink/api/scala/typeutils/CaseClassTypeInfo
at org.apache.flink.table.codegen.CodeGenUtils$.fieldAccessorFor(CodeGenUtils.scala:236)
at org.apache.flink.table.codegen.CodeGenerator.org$apache$flink$table$codegen$CodeGenerator$$generateFieldAccess(CodeGenerator.scala:1654)
at org.apache.flink.table.codegen.CodeGenerator.org$apache$flink$table$codegen$CodeGenerator$$generateInputAccess(CodeGenerator.scala:1602)
at org.apache.flink.table.codegen.CodeGenerator$$anonfun$23.apply(CodeGenerator.scala:875)
at org.apache.flink.table.codegen.CodeGenerator$$anonfun$23.apply(CodeGenerator.scala:874)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
at scala.collection.mutable.ArrayOps$ofInt.foreach(ArrayOps.scala:234)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:245)
at scala.collection.mutable.ArrayOps$ofInt.map(ArrayOps.scala:234)
at org.apache.flink.table.codegen.CodeGenerator.generateConverterResultExpression(CodeGenerator.scala:874)
at org.apache.flink.table.plan.nodes.CommonScan$class.generatedConversionFunction(CommonScan.scala:57)
at org.apache.flink.table.plan.nodes.dataset.DataSetScan.generatedConversionFunction(DataSetScan.scala:36)
at org.apache.flink.table.plan.nodes.dataset.BatchScan$class.convertToInternalRow(BatchScan.scala:48)
at org.apache.flink.table.plan.nodes.dataset.DataSetScan.convertToInternalRow(DataSetScan.scala:36)
at org.apache.flink.table.plan.nodes.dataset.DataSetScan.translateToPlan(DataSetScan.scala:65)
at org.apache.flink.table.api.BatchTableEnvironment.translate(BatchTableEnvironment.scala:350)
at org.apache.flink.table.api.BatchTableEnvironment.translate(BatchTableEnvironment.scala:329)
at com.att.ariso.TableEnv.main(TableEnv.java:39)
Caused by: java.lang.ClassNotFoundException: org.apache.flink.api.scala.typeutils.CaseClassTypeInfo
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 20 more
------------------------
Need a runtime library flink-scala.

IOException while trying to read the file

me and my friend are creating android application for our studies which works like KeePass.
The problem is that this application works on my friend phone with Android 4.0.3 and on my phone with Android 4.4.2 KitKat it doesn't. Why?
I can create database file with no exceptions, but when I try to log in it throws IOException. We think that this exception might be thrown by FileInputStream but we don't have any idea why.
Here is the code where the exception appears:
public void onClickLogon(View view){
_db = null;
FileInputStream fis = null;
try {
fis = openFileInput(this.login.getText().toString() + ".db");
_db = (PasswordDatabase) com.example.tomus.passwordwalletbeta.Security.decrypt(fis, this.login.getText().toString(), this.password.getText().toString());
fis.close();
if(_db==null){
this.info.setText("Wrong informations.");
}
else {
Intent intent = new Intent(MainActivity.this, LoggedActivity.class);
Bundle bundle = new Bundle();
bundle.putSerializable("db", _db);
bundle.putString("login", login.getText().toString());
bundle.putString("password", password.getText().toString());
intent.putExtras(bundle);
this.login.setText("");
this.password.setText("");
startActivity(intent);
}
} catch (InvalidKeyException | NoSuchPaddingException | NoSuchAlgorithmException e) {
this.info.setText("Wrong informations.");
} catch (FileNotFoundException e) {
this.info.setText("FileNotFound");
} catch (IOException e) {
this.info.setText("IOException");
}
}
#Edit: Here is error log, now I can see that file cannot be found. Was there any changes to creating files or pathing in 4.4.2?
Process: com.example.tomus.passwordwalletbeta, PID: 5495
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3857)
at android.view.View.performClick(View.java:4487)
at android.view.View$PerformClick.run(View.java:18746)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5077)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at android.view.View$1.onClick(View.java:3852)
at android.view.View.performClick(View.java:4487)
at android.view.View$PerformClick.run(View.java:18746)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5077)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.io.StreamCorruptedException
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:2070)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:371)
at com.example.tomus.passwordwalletbeta.Security.decrypt(Security.java:82)
at com.example.tomus.passwordwalletbeta.MainActivity.onClickLogon(MainActivity.java:74)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at android.view.View$1.onClick(View.java:3852)
at android.view.View.performClick(View.java:4487)
at android.view.View$PerformClick.run(View.java:18746)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5077)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)

Testng Boolean Assertions java.lang.ExceptionInInitializerError

I get this error while running the Testng program:
java.lang.ExceptionInInitializerError
at com.org.dnb.po.test.loginpagePOTest.verifyLoginpagecontrols(loginpagePOTest.java:58)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
I have two classes one for definition(class-1) and other is test(class-2)
Class 1 :
public static List<WebElement> unameBox1= driver.findElements(By.xpath(".//*[#id='username']"));
public static boolean unameboxIT = unameBox1.size() > 0;
Class2:
#Test(priority=1)
public void verifyLoginpagecontrols(){
Assert.assertTrue(unameboxIT); // Always goes into Exception as shown above
}
kindly help

Custom HighRepJobPolicy in Google App Engine development server

I am using a custom HighRepJobPolicy in the App Engine development server. The same class works fine when I use it in my unit tests:
LocalDatastoreServiceTestConfig datastoreConfig = new LocalDatastoreServiceTestConfig();
datastoreConfig.setAlternateHighRepJobPolicyClass(CustomHighRepJobPolicy.class);
But when I try to use this class in the Java development server by adding the JVM tag
-Ddatastore.high_replication_job_policy_class=foo.bar.CustomHighRepJobPolicy
I get a ClassNotFoundException:
Caused by: java.lang.ClassNotFoundException: foo.bar.CustomHighRepJobPolicy
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at com.google.appengine.tools.development.DevAppServerClassLoader.loadClass(DevAppServerClassLoader.java:87)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at com.google.appengine.api.datastore.dev.LocalDatastoreService.initHighRepJobPolicy(LocalDatastoreService.java:426)
... 66 more
Is this expected to work, or has anyone else tried this before? I ask because I could not find any information about this via Google, and the App Engine docs only mention the DefaultHighRepJobPolicy.
Looks like you were early to the party :
public class LocalCustomPolicyHighRepDatastoreTest {
private static final class CustomHighRepJobPolicy implements HighRepJobPolicy {
static int count = 0;
#Override
public boolean shouldApplyNewJob(Key entityGroup) {
// every other new job fails to apply
return count++ % 2 == 0;
}
#Override
public boolean shouldRollForwardExistingJob(Key entityGroup) {
// every other existing job fails to apply
return count++ % 2 == 0;
}
}
private final LocalServiceTestHelper helper =
new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig()
.setAlternateHighRepJobPolicyClass(CustomHighRepJobPolicy.class));
#Before
public void setUp() {
helper.setUp();
}
#After
public void tearDown() {
helper.tearDown();
}
#Test
public void testEventuallyConsistentGlobalQueryResult() {
DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
ds.put(new Entity("yam")); // applies
ds.put(new Entity("yam")); // does not apply
// first global query only sees the first Entity
assertEquals(1, ds.prepare(new Query("yam")).countEntities(withLimit(10)));
// second global query sees both Entities because we "groom" (attempt to
// apply unapplied jobs) after every query
assertEquals(2, ds.prepare(new Query("yam")).countEntities(withLimit(10)));
}
}

Resources