Run java application from eclipse - java

I have to try Push Notifications. I follow all the instructions from this link.
Now I have to run App.java(It's server part, not client part, so is not an android application), but I have a problem.
When I run as java application, Eclipse show me an error window
saying:"Selection does not contain a main type".
How can I fix this problem?
This is App.java class:
package com.hmkcode;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hmkcode.vo.Content;
public class App
{
public static void main( String[] args )
{
System.out.println( "Sending POST to GCM" );
String apiKey = "AIzaSyC..........";
Content content = createContent();
POST2GCM.post(apiKey, content);
}
public static Content createContent(){
Content c = new Content();
c.addRegId("APA91bE8R9nR.........");
c.createData("Test Title", "Test Message");
return c;
}
}

Related

JDA Will not register my event(Discord Bot Java)

I've been having a problem with registering JDA events. Everytime I start the bot, it shows this. Can someone help me with this please?
Here's my Main code:
import Events.Information;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.entities.ChannelType;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.MessageChannel;
import net.dv8tion.jda.api.events.ReadyEvent;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import javax.security.auth.login.LoginException;
public class Main {
public static String prefix = "!";
public static void main(String[] args) throws LoginException {
JDABuilder jda = JDABuilder.createDefault("I inserted bot key here");
jda.setActivity(Activity.watching("baldness"));
jda.addEventListeners(new Information());
jda.build();
}
}
Here's my Information class code:
package Events;
import com.sun.tools.javac.Main;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
public class Information {
public void onGuildMessageReceived(GuildMessageReceivedEvent e) {
String[] args = e.getMessage().getContentRaw().split("\\s+");
if (args[0].equals("!commands")) {
EmbedBuilder info = new EmbedBuilder();
info.setTitle("Commands");
info.setDescription("!info - Pops up with this!");
info.setColor(0xf45642);
info.setFooter("Bot created by Jason", e.getMember().getUser().getAvatarUrl());
e.getChannel().sendTyping().queue();
e.getChannel().sendMessage(info.build()).queue();
}
}
}
Here's my layering of classes and packages:
Image

Download .db file with Android DownloadManager

I am attempting to download a .db file from my organization's website within an Android application and have encountered difficulties. It says the download is unsuccessful.
Here is the code that handles the download:
package midamcorp.com.burgerkingapp;
import android.app.DownloadManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.widget.Toast;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
public class downloadReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context c, Intent i) {
File localDBFile = new File(c.getFilesDir(), "bk.db");
try {
DownloadManager manager = (DownloadManager) c.getSystemService(Context.DOWNLOAD_SERVICE);
Uri uriTest = Uri.parse("http://www.midamcorp.com/bk.db");
DownloadManager.Request request = new DownloadManager.Request(uriTest);
if (localDBFile.exists()) {
localDBFile.delete();
}
manager.enqueue(request);
// }
}
catch(Exception ex) {
Log.e("Error", ex.getMessage());
}
}
}
Furthermore, when I navigate to this file in my browser, I receive a 404 error; however, I know the path is correct. I have a feeling it has to do with the file extension (.db). How can I fix this?
Thanks!
Furthermore, when I navigate to this file in my browser, I receive a 404 error; however, I know the path is correct
It is not correct, because you are getting 404. URL is invalid or for any other reasons you are not able to reach it, and so is DownloadManager

ActiveMQ Handling Messages thru REST

I am new to ActiveMQ, we had a ActiveMQ Server else where location, we are unable to connect thru tcp socket, But able to cousume the message using REST command
http://admin:admin#localhost:8161/api/message?destination=queue://orders.input
I have 99K+ messages in ActiveMQ, need consume using REST command and need to store in a text file,
import static com.jayway.restassured.RestAssured.given;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.commons.codec.binary.Base64;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import com.dnb.e2e.automation.util.CommonUtil;
import com.dnb.e2e.automation.util.WebServiceUtil;
import com.jayway.restassured.RestAssured;
import com.jayway.restassured.config.SSLConfig;
import com.jayway.restassured.config.SessionConfig;
import com.jayway.restassured.response.Headers;
public class MQwithRest {
public static String getResponse() throws Exception
{
String url = "http://admin:admin#localhost:8161/api/message?destination=queue://SAMPLEQUEUE";
String response = "a";
while(response!=""){
try {
response = given().header("content-type", "application/json")
.request()
.config(RestAssured.config().sslConfig(new SSLConfig().allowAllHostnames()))
.when().get(url).asString();
System.out.println(response);
} catch (Exception e) {
e.printStackTrace();
}
}
return "empty";
}
public static void main(String args[]) throws Exception
{
System.out.println(MQwithRest.getResponse());
}
}
In the above code i am displaying consumed messages at output side. When I am implementing thru rest i am able to consume only one message at a time per session.
Can any body help for Consuming 99k+ message with in a single session using REST service?
You can also tunnel JMS client over HTTP.
That way, you can get bypass any non-HTTP restrictions in your network and still use the JMS terminology.
Using the rest web app bundled you are a bit limited to the semantics of retrieving messages. Anyway, you should be able to get all messages using plain HTTP/Rest anyway. Simply use a loop to get messages.

UIMA Pipeline with Stanford NER

I have integrated Stanford NER in UIMA and developed a pipeline.
The pipeline contains a FileSystemCollectionReader,an NERAnnotator and a CasConsumer but the output so come isn't desired. In my input directory i have two files and after running the pipeline, i get two files as ouput but the second file is getting merged with the first file in second ouput. I don't know what's happening here.
The code for CasConsumer:
`
package org.gds.uima;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import org.apache.uima.UimaContext;
import org.apache.uima.analysis_component.AnalysisComponent_ImplBase;
import org.apache.uima.analysis_component.CasAnnotator_ImplBase;
import org.apache.uima.analysis_component.JCasAnnotator_ImplBase;
import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
import org.apache.uima.cas.CAS;
import org.apache.uima.cas.CASException;
import org.apache.uima.cas.Type;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.fit.component.CasConsumer_ImplBase;
import org.apache.uima.fit.component.JCasConsumer_ImplBase;
import org.apache.uima.fit.descriptor.ConfigurationParameter;
import org.apache.uima.fit.util.CasUtil;
import org.apache.uima.jcas.JCas;
import org.apache.uima.resource.ResourceInitializationException;
public class CasConsumer extends JCasConsumer_ImplBase
{
public final static String PARAM_OUTPUT="outputDir";
#ConfigurationParameter(name = PARAM_OUTPUT)
private String outputDirectory;
public final static String PARAM_ANNOTATION_TYPES = "annotationTypes";
enter code here
#ConfigurationParameter(name = PARAM_ANNOTATION_TYPES,defaultValue="String")
public List<String> annotationTypes;
public void initialize(final UimaContext context) throws ResourceInitializationException
{
super.initialize(context);
}
#Override
public void process(JCas jcas)
{
String original = jcas.getDocumentText();
try
{
String onlyText="";
JCas sofaText = jcas.getView(NERAnnotator.SOFA_NAME);
onlyText = sofaText.getDocumentText();
String name = UUID.randomUUID().toString().substring(20);
File outputDir = new File(this.outputDirectory+"/"+name);
System.out.print("Saving file to "+outputDir.getAbsolutePath());
FileOutputStream fos = new FileOutputStream(outputDir.getAbsoluteFile());
PrintWriter pw = new PrintWriter(fos);
pw.println(onlyText);
pw.close();
}
catch(CASException cae)
{
System.out.println(cae);
}
catch(FileNotFoundException fne)
{
System.out.print(fne);
}
}
}
`
}

Connecting two unix server's and push data from server to server using java program

I have create a java program that will connect to unix server1 (with user name pwd),now i need to connect another server (with username password) and execute command to push data from server 1 to server 2 using java program.
Server1 connection is working fine and i can execute some basic commands in it.
Code below
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Properties;
import net.neoremind.sshxcute.core.ConnBean;
import net.neoremind.sshxcute.core.Result;
import net.neoremind.sshxcute.core.SSHExec;
import net.neoremind.sshxcute.exception.TaskExecFailException;
import net.neoremind.sshxcute.task.CustomTask;
import net.neoremind.sshxcute.task.impl.ExecCommand;
public class UnixConnect {
// String hostName, String logFile, String userName, String password
static String[] host_names = null;
static String[] user_names = null;
static String[] pwd_text = null;
public void execCommand() throws TaskExecFailException {
ConnBean cb1 = new ConnBean("0.000.00.000", "***", "****");
SSHExec ssh1 = SSHExec.getInstance(cb1);
ssh1.connect();
String[] cmd = {"cd /apps/a/b/c/logs","tail -1 aLoadJob.log"};
CustomTask tasks = new ExecCommand(cmd);
Result res1 = ssh1.exec(tasks);
if (res1.isSuccess) {
/*System.out.println(res1.sysout)*/;
} else {
System.out.println("Return code: " + res1.sysout);
System.out.println("error message: " + res1.error_msg);
}
ssh1.disconnect();
}
/**
* #param args
*/
public static void main(String[] args) throws TaskExecFailException {
UnixConnect ob = new UnixConnect();
ob.execCommand();
}
}
In both Server i need to give username and password
This is a bit strange use case but I would do the following:
Implement bash script on server1 that would do all the job of transfering data to server2. Of course server1 has to be able to connecto server2
Use you program to invoke the bash script on server1.

Categories