server interview questions
Top server frequently asked interview questions
I have a web application that runs a query on an api, gets new information, changes the variables in the database and sends emails if needed (compares old and new variables).
I work with Ubuntu Server, and I tried several variations to run this.
my controller looks like this:
class Cli_only extends CI_Controller {
public function __construct() {
parent::__construct();
is_cli() OR show_404(); // If cronjob !
$this->load->model('kas_model');
// Sets the server not to have a time out.
ini_set('max_execution_time', 0);
ini_set('memory_limit', '-1');
// Expand the array displays
ini_set('xdebug.var_display_max_depth', 5);
ini_set('xdebug.var_display_max_children', 256);
ini_set('xdebug.var_display_max_data', 1024);
}
// This function has to run every day using a corn job.
public function cron_job(){
// does stuff...
}
So at first I tried using the regular 'curl' command on my cronjob:
15 15 * * * http://10.0.1.666/tools/Cli_only/cron_job
and I got this error in the log file:
Dec 6 15:30:01 MYserver CRON[1134]: (root) CMD (curl http://10.0.1.66/tools/Cli_only/cron_job)
Dec 6 15:30:02 MYserver CRON[1133]: (CRON) info (No MTA installed, discarding output)
running a quick google on this and I noticed that I have to install "postfix" on my server, and I did. I restarted cron and get:
Dec 6 16:26:01 MYserver cron[2663]: (root) RELOAD (crontabs/root)
Dec 6 16:26:01 MYserver CRON[2703]: (root) CMD (curl http://10.0.1.666/tools/Cli_only/cron_job)
Dec 6 16:26:01 MYserver postfix/pickup[2479]: 23430102E11: uid=0 from=<root>
Dec 6 16:26:01 MYserver postfix/cleanup[2707]: 23430102E11: message-id=<20151206142601.23430102E11@MYserver>
Dec 6 16:26:01 MYserver postfix/qmgr[2480]: 23430102E11: from=<root@MYserver>, size=2058, nrcpt=1 (queue active)
Dec 6 16:26:01 MYserver postfix/local[2709]: 23430102E11: to=<root@MYserver>, orig_to=<root>, relay=local, delay=0.02, delays=0.01/0/0/0, dsn=2.0.0, status=sent (delivered to mailbox)
Dec 6 16:26:01 MYserver postfix/qmgr[2480]: 23430102E11: removed
Still, no changes on the DB - and if there were - CodeIgniter has a working mailing configurations that should work from just running the URL.
I tried running things like this:
14 16 * * * wget -O - http://10.0.1.666/tools/Cli_only/cron_job >/dev/null 2>&1
14 16 * * * curl -O - http://10.0.1.666/tools/Cli_only/cron_job >/dev/null 2>&1
14 16 * * * GET -O - http://10.0.1.666/tools/Cli_only/cron_job >/dev/null 2>&1
which I don't really know what they do - and still don't work.
EDIT:
Just for being clear, if I run the controller on my browser, everything works perfectly!
This is all of my code in the controller, the cron_job() function is right after the __construct() function:
<?php
class Cli_only extends CI_Controller {
public function __construct() {
parent::__construct();
is_cli() OR show_404(); // If cronjob !
//if (!$this->input->is_cli_request()) show_error('Direct access is not allowed');
$this->load->model('kas_model');
// Sets the server not to have a time out.
ini_set('max_execution_time', 0);
ini_set('memory_limit', '-1');
// Expand the array displays
ini_set('xdebug.var_display_max_depth', 5);
ini_set('xdebug.var_display_max_children', 256);
ini_set('xdebug.var_display_max_data', 1024);
}
// This function has to run every day using a corn job.
public function cron_job(){
// 1. Run the query that gets the table data from the DB('from kas table')
$data['table'] = $this->kas_model->get_kas_table();
// 2. Go through each row.
foreach ( $data['table'] as $row ) {
// 3.1. But first, get vars!
$kas_id = $row->kas_id;
$kas_key = $row->kas_key;
$kas_id_aaa = $row->kas_id_aaa;
$kas_id_bbb = $row->kas_id_bbb;
$kas_rank1_aaa = $row->kas_rank1_aaa;
$kas_rank2_aaa = $row->kas_rank2_aaa;
$kas_rank1_bbb = $row->kas_rank1_bbb;
$kas_rank2_bbb = $row->kas_rank2_bbb;
// 3.2. move to yesterday to make place for a new query result.
$this->kas_model->move_tod_to_yes($kas_id, $kas_rank2_aaa, $kas_rank2_bbb);
// 3.3. Run the key query again for today on each one of the keys and insert to DB.
if ( ($kas_id_aaa != 0) || ( !empty($kas_id_aaa) ) ) {
$aaa_rank_today = $this->get_rank_aaa_by_id_and_kw($kas_id_aaa, $kas_key);
}
if ( ($kas_id_bbb != 0) || ( !empty($kas_id_bbb) ) ) {
$bbb_rank_today = $this->get_rank_bbb_by_id_and_kw($kas_id_bbb, $kas_key);
}
// 3.4. Add the new rank to rank2 in the DB.
$this->kas_model->add_new_today($kas_id, $aaa_rank_today, $bbb_rank_today);
// 4. Check difference as Sag described :
$msg = '';
$send = FALSE;
// First if: aaa
if ( ($aaa_rank_today > 10 ) && ( $kas_rank2_aaa < 30 ) && ( ( abs( $aaa_rank_today - $kas_rank2_aaa ) ) > 10) ) {
$msg .= 'aaa:<br> ( (Today > 10 ) && ( Yesterday < 30 ) && ( ( |Today - Yesterday| > 10) ) ==> True. <br><br>';
$send = TRUE;
}
// Second if: aaa
if ( ( ($kas_rank2_aaa < 5) && ($aaa_rank_today > 10) ) || ( ($aaa_rank_today < 5) && ($kas_rank2_aaa > 10) ) ) {
$msg .= 'aaa: <br> ( ( (Yesterday < 5) && (Today > 10) ) || ( (Today < 5) && (Yesterday > 10) ) ) ==> True. <br> <br>';
$send = TRUE;
}
// First if: bbb
if ( ($bbb_rank_today > 10 ) && ( $kas_rank2_bbb < 30 ) && ( ( abs( $bbb_rank_today - $kas_rank2_bbb ) ) > 10) ) {
$msg .= 'bbb: <br> ( (Today > 10 ) && ( Yesterday < 30 ) && ( ( |Today - Yesterday| > 10) ) ==> True. <br><br>';
$send = TRUE;
}
// Second if: bbb
if ( ( ($kas_rank2_bbb < 5) && ($bbb_rank_today > 10) ) || ( ($bbb_rank_today < 5) && ($kas_rank2_bbb > 10) ) ) {
$msg .= 'bbb: <br> ( ( (Yesterday < 5) && (Today > 10) ) || ( (Today < 5) && (Yesterday > 10) ) ) ==> True. <br> <br>';
$send = TRUE;
}
$this->send_mail($kas_id_aaa, $kas_id_bbb, $msg, $send, $aaa_rank_today, $bbb_rank_today, $kas_rank2_aaa, $kas_rank2_bbb, $kas_key);
}
}
// Gets aaa categorys Ranking by ID.
public function get_rank_aaa_by_id_and_kw($id, $key, $query_country){
$key_for_url = rawurlencode($key);
$found = FALSE;
$i = 0;
// Create a stream for Json. That's how the code knows what to expect to get.
$context_opts = array(
'http' => array(
'method' => "GET",
'header' => "Accepts: categorylication/json\r\n"
));
$context = stream_context_create($context_opts);
while ($found == FALSE) {
// aaa Query
$json_query_aaa = "https://api.example.com:666/aaa/ajax/research_key?category_id=$id&term=$key_for_url&page_index=$i&country=$query_country&auth_token=tokentokentoken";
// Get the Json
$json_query_aaa = file_get_contents($json_query_aaa, false, $context);
// Turn Json to a PHP array
$json_query_aaa = json_decode($json_query_aaa, true);
// Finally, the main categorys array.
$json_query_aaa = $json_query_aaa['key']['phone_categorys']['category_list'];
if ( count($json_query_aaa) > 2 ) {
for ( $j=0; $j<count($json_query_aaa); $j++ ) {
if ( $json_query_aaa[$j]['id'] == $id ) {
$found = TRUE;
$rank = $json_query_aaa[$j]['rank'] + 1;
break;
}
if ($found == TRUE){
break;
}
}
$i++;
} else {
$rank = "none";
break;
}
}
return $rank;
}
// Gets bbb categorys Ranking by ID.
public function get_rank_bbb_by_id_and_kw($id, $key, $query_country){
$key_for_url = rawurlencode($key);
$found = FALSE;
$i = 0;
// Create a stream for Json. That's how the code knows what to expect to get.
$context_opts = array(
'http' => array(
'method' => "GET",
'header' => "Accepts: categorylication/json\r\n"
));
$context = stream_context_create($context_opts);
while ($found == FALSE) {
// aaa Query
$json_query_bbb = "https://api.example.com:666/bbb/research_key?category_id=$id&term=$key_for_url&page_index=$i&country=$query_country&auth_token=tokentokentoken";
// Get the Json
$json_query_bbb = file_get_contents($json_query_bbb, false, $context);
// Turn Json to a PHP array
$json_query_bbb = json_decode($json_query_bbb, true);
// Finally, the main categorys array.
$json_query_bbb = $json_query_bbb['key']['phone_categorys']['category_list'];
if ( count($json_query_bbb) > 2 ) {
for ( $j=0; $j<count($json_query_bbb); $j++ ) {
if ( $json_query_bbb[$j]['id'] == $id ) {
$found = TRUE;
$rank = $json_query_bbb[$j]['rank']+1;
}
}
$i++;
} else {
$rank = "none";
break;
}
}
return $rank;
}
// Sends to email the results
public function send_mail($id_aaa, $id_bbb, $msg, $send, $aaa_rank_today, $bbb_rank_today, $aaa_rank_yesterday, $bbb_rank_yesterday, $kas_key){
if ($send) {
$ci = get_instance();
$config['protocol'] = "smtp";
$config['smtp_host'] = "ssl://smtp.gmail.com";
$config['smtp_port'] = "465";
$config['smtp_user'] = "myEmail@example.pro";
$config['smtp_pass'] = "assword";
$config['charset'] = "utf-8";
$config['mailtype'] = "html";
$config['newline'] = "\r\n";
$config['crlf'] = "\r\n";
$config['validate'] = FALSE;
$ci->load->library('email');
$ci->email->initialize($config);
$ci->email->from('myEmail@example.pro', 'key Alerting System (KAS)');
$list = array('myEmail.do@gmail.com', 'sag@example.pro');
$ci->email->to($list);
$this->email->reply_to('no-reply@example.pro', 'KAS Alert');
$ci->email->subject('KAS Alert!');
$ci->email->message("key: $kas_key <br/><br/> aaa ID:$id_aaa <br> bbb ID: $id_bbb <br><br><br> $msg<br><br> aaa Rank Today: $aaa_rank_today<br> aaa Rank Yesterday: $aaa_rank_yesterday<br><br> bbb Rank Today: $bbb_rank_today<br> bbb Rank Yesterday: $bbb_rank_yesterday");
$ci->email->send();
}
}
function test(){
echo 'banana';
}
}
EDIT #2:
This works fine when not having is_cli() OR show_404();
in the construct function. But I do want this controller to work only from a cronjob
I get the same result with:
if (!$this->input->is_cli_request()) show_error('Direct access is not allowed');
Source: (StackOverflow)
I don't know why I got this error every time I tried to open the page:
2013/04/06 17:52:19 [error] 5040#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET /info.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "localhost:8080"
Source: (StackOverflow)
I've been trying to setup an ipython server following several tutorials (since none was exactly my case). A couple days ago, I did manage to get it to the point where it was launching but then was not able to access it via url. Today it's not launching anymore and I can't find much about this specific error I get:
Traceback (most recent call last):
File "/usr/local/bin/ipython", line 9, in <module>
load_entry_point('ipython==4.0.0-dev', 'console_scripts', 'ipython')()
File "/usr/local/lib/python2.7/dist-packages/ipython-4.0.0_dev-py2.7.egg/IPython/__init__.py", line 118, in start_ipython
return launch_new_instance(argv=argv, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/traitlets-4.0.0-py2.7.egg/traitlets/config/application.py", line 591, in launch_instance
app.initialize(argv)
File "<string>", line 2, in initialize
File "/usr/local/lib/python2.7/dist-packages/traitlets-4.0.0-py2.7.egg/traitlets/config/application.py", line 75, in catch_config_error
return method(app, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/ipython-4.0.0_dev-py2.7.egg/IPython/terminal/ipapp.py", line 302, in initialize
super(TerminalIPythonApp, self).initialize(argv)
File "<string>", line 2, in initialize
File "/usr/local/lib/python2.7/dist-packages/traitlets-4.0.0-py2.7.egg/traitlets/config/application.py", line 75, in catch_config_error
return method(app, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/ipython-4.0.0_dev-py2.7.egg/IPython/core/application.py", line 386, in initialize
self.parse_command_line(argv)
File "/usr/local/lib/python2.7/dist-packages/ipython-4.0.0_dev-py2.7.egg/IPython/terminal/ipapp.py", line 297, in parse_command_line
return super(TerminalIPythonApp, self).parse_command_line(argv)
File "<string>", line 2, in parse_command_line
File "/usr/local/lib/python2.7/dist-packages/traitlets-4.0.0-py2.7.egg/traitlets/config/application.py", line 75, in catch_config_error
return method(app, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/traitlets-4.0.0-py2.7.egg/traitlets/config/application.py", line 487, in parse_command_line
return self.initialize_subcommand(subc, subargv)
File "<string>", line 2, in initialize_subcommand
File "/usr/local/lib/python2.7/dist-packages/traitlets-4.0.0-py2.7.egg/traitlets/config/application.py", line 75, in catch_config_error
return method(app, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/traitlets-4.0.0-py2.7.egg/traitlets/config/application.py", line 418, in initialize_subcommand
subapp = import_item(subapp)
File "build/bdist.linux-x86_64/egg/ipython_genutils/importstring.py", line 31, in import_item
ImportError: No module named notebook.notebookapp
So about the setup, I have installed the anaconda distrib of ipython, pyzmq & tornado libraries. I have created a profile nbserver and the config file is as follows - ipython.config.py:
c = get_config()
c.IPKernalApp.pylab = 'inline'
c.NotebookApp.certfile = u'/home/ludo/.ipython/profile_nbserver/mycert.pem'
c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False
c.NotebookApp.password = u'sha1:e6cb2aa9a[...]'
c.NotebookApp.port = 9999
c.NotebookManager.notebook_dir = u'/var/www/ipynb/'
c.NotebookApp.base_project_url = '/ipynb/'
c.NotebookApp.base_kernel_url = '/ipynb/'
c.NotebookApp.webapp_settings = {'static_url_prefix':'/ipynb/static/'}
I really don't know where to look for clues anymore - and I'm probably lacking a greater understanding of how all this works to figure it out. My ultimate goal is to then use the answer to this question on SO to complete a setup behind apache and eventually connect it to colaboratory - but seems like it should launch first.
Many thanks for any help :)
Source: (StackOverflow)
I have an app written on Firebase. Security rules and client side code aren't quite enough to make my app work. I need to connect a server to do a few tasks:
- Cleaning up denormalized data that's challenging to clean up using
onDisconnect
handlers
- Building additional indexes of my data that go beyond what I can do
with
queries
Source: (StackOverflow)
I want to run a very simple HTTP server. Every GET request to example.com
should get index.html
served to it but as a regular HTML page (i.e., same experience as when you read normal web pages).
Using the code below, I can read the content of index.html
. How do I serve index.html
as a regular web page?
var http = require('http');
var fs = require('fs');
var index = fs.readFileSync('index.html');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end(index);
}).listen(9615);
One suggestion below is complicated and requires me to write a get
line for each resource (CSS, JavaScript, images) file I want to use.
How can I serve a single HTML page with some images, CSS and JavaScript?
Source: (StackOverflow)
I get this error when trying to access localhost via a browser.
AH01630: client denied by server configuration
I checked my site folder permissions using:
sudo chmod 777 -R *
Here is my configuration file:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /home/user-name/www/myproject
<Directory />
Options FollowSymLinks
AllowOverride all
Allow from all
</Directory>
<Location />
Allow from all
Order Deny,Allow
</Location>
<Directory /home/user-name/www/myproject/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride all
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride all
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
Source: (StackOverflow)
UPDATE: Since this post has gotten a lot of attention over the years, I've listed the top solutions per platform at the bottom of this post.
Original post:
I want my node.js server to run in the background, i.e.: when I close my terminal I want my server to keep running. I've googled this and came up with this tutorial, however it doesn't work as intended. So instead of using that daemon script, I thought I just used the output redirection (the 2>&1 >> file
part), but this too does not exit - I get a blank line in my terminal, like it's waiting for output/errors.
I've also tried to put the process in the background, but as soon as I close my terminal the process is killed as well.
So how can I leave it running when I shut down my local computer?
Top solutions:
Source: (StackOverflow)
I just installeed Postgres, but it seems to have installed 9.3 and I'd like to start with 9.4
I simply did apt-get install postgresql from a new Ubuntu 14.04.1 machine.
http://www.postgresql.org/download/linux/ubuntu/
says you can do:
apt-get install postgresql-9.4
but when I try that I get:
E: Couldn't find any package by regex 'postgresql-9.4
Okay, so I try the section below where you add the PostgreSQL Apt Repository but that can't find anything either.
Is 9.4 not in the package managers yet? Am I doing something horribly wrong?
Source: (StackOverflow)
Also is the web server root directory the place where you put your site files and later acces them with localhost/file_name in the browser?
Source: (StackOverflow)
I want to deploy EJB ear in a server but I am really confused about choosing a server among tomcat
, TomEE
and TomEE Plus
.
- What are the differences between
Tomcat & TomEE?
- What are the new features in
TomEE and TomEE Plus?
- In which case(s) does it make sense to go for
TomEE and TomEE Plus?
so I need some suggestions in order to be able to make an informed decision.
Source: (StackOverflow)
Working on a system which will store more than 4 million
records per day
.
To reduce I/O and increase speed I change the storage from database to file. So data will change to json and directly written to file.
More Info
The system is ppc
system written by PHP which show banner in several sites with their own servers through an iframe.
whenever this banner load in any site, I'll store one record of it's info in file (was an insert to database before) and update tow fields in tow tables in database.
Issue
When visits go up and reach almost 3000 visit per minute, iframe loading speed reduce significantly, further more sometimes cause printing server timeout in iframe.
I'm looking for ways to reduce resource using and increasing loading speed and also preventing timeout.
Any help will be highly appreciated...
Source: (StackOverflow)
I write a server which handles events and uncaught exceptions during handling the event must not terminate the server.
The server is a single non-threaded python process.
I want to terminate on these errors types:
- KeyboardInterrupt
- MemoryError
- ...
The list of built in exceptions is long: https://docs.python.org/2/library/exceptions.html
I don't want to re-invent this exception handling, since I guess it was done several times before.
How to proceed?
- Have a white-list: A list of exceptions which are ok and processing the next event is the right choice
- Have a black-list: A list of exceptions which indicate that terminating the server is the right choice.
Hint: This question is not about running a unix daemon in background. It is not about double fork and not about redirecting stdin/stdout :-)
Source: (StackOverflow)
Why am i getting this error?
shibly@mybox:~/blog$ rails server
/home/shibly/.gem/ruby/2.2.4/gems/bundler-1.11.2/lib/bundler/runtime.rb:80:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'uglifier'. (Bundler::GemRequireError)
from /home/shibly/.gem/ruby/2.2.4/gems/bundler-1.11.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
from /home/shibly/.gem/ruby/2.2.4/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `each'
from /home/shibly/.gem/ruby/2.2.4/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `block in require'
from /home/shibly/.gem/ruby/2.2.4/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `each'
from /home/shibly/.gem/ruby/2.2.4/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `require'
from /home/shibly/.gem/ruby/2.2.4/gems/bundler-1.11.2/lib/bundler.rb:99:in `require'
from /home/shibly/blog/config/application.rb:7:in `<top (required)>'
from /home/shibly/.gem/ruby/2.2.4/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:78:in `require'
from /home/shibly/.gem/ruby/2.2.4/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:78:in `block in server'
from /home/shibly/.gem/ruby/2.2.4/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:75:in `tap'
from /home/shibly/.gem/ruby/2.2.4/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:75:in `server'
from /home/shibly/.gem/ruby/2.2.4/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /home/shibly/.gem/ruby/2.2.4/gems/railties-4.2.5/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:9:in `require'
from bin/rails:9:in `<main>
Source: (StackOverflow)
I am unable to reach the Android Server on the emulator from a program on my desktop, how do I solve it?
Some code (from How to find LAN ip address of android device?):
public static ArrayList<String> getSelfIP(){
try {
ArrayList<String> ipList = new ArrayList<>();
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()) {
ipList.add(inetAddress.getHostAddress().toString());
}
}
}
return ipList;
} catch (SocketException ex) {}
return null;
}
The result is [fe80::5054:ff:fe12:3456%eth0, 10.0.2.15]
What do I have to configure or do to make the emulator reachable by my desktop programs?
I have done the following:
> adb forward tcp:50000 tcp:50000
However, I am unable to access the server through localhost:50000.
Source: (StackOverflow)
I'm trying to adapt the example provided here for Smack 4.1.0. and getting a little confused.
Specifically I'm struggling to understand what the GcmPacketExtension should now extend, how the constructor should work and how the Providermanager.addExtensionProvider should be updated to tie in with it.
I'm sure someone must have done this before but I can't find any examples
and I seem to be going round in circles using just the documentation.
Any help would be much appreciated, I'm sure the answer is very simple!
Current Code (is compiling but not running):
static {
ProviderManager.addExtensionProvider(GCM_ELEMENT_NAME, GCM_NAMESPACE, new ExtensionElementProvider<ExtensionElement>() {
@Override
public DefaultExtensionElement parse(XmlPullParser parser,int initialDepth) throws org.xmlpull.v1.XmlPullParserException,
IOException {
String json = parser.nextText();
return new GcmPacketExtension(json);
}
});
}
and:
private static final class GcmPacketExtension extends DefaultExtensionElement {
private final String json;
public GcmPacketExtension(String json) {
super(GCM_ELEMENT_NAME, GCM_NAMESPACE);
this.json = json;
}
public String getJson() {
return json;
}
@Override
public String toXML() {
return String.format("<%s xmlns=\"%s\">%s</%s>",
GCM_ELEMENT_NAME, GCM_NAMESPACE,
StringUtils.escapeForXML(json), GCM_ELEMENT_NAME);
}
public Stanza toPacket() {
Message message = new Message();
message.addExtension(this);
return message;
}
}
Current exception:
Exception in thread "main" java.lang.NoClassDefFoundError: de/measite/minidns/DNSCache
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.jivesoftware.smack.SmackInitialization.loadSmackClass(SmackInitialization.java:213)
at org.jivesoftware.smack.SmackInitialization.parseClassesToLoad(SmackInitialization.java:193)
at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitialization.java:163)
at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitialization.java:148)
at org.jivesoftware.smack.SmackInitialization.<clinit>(SmackInitialization.java:116)
at org.jivesoftware.smack.SmackConfiguration.getVersion(SmackConfiguration.java:96)
at org.jivesoftware.smack.provider.ProviderManager.<clinit>(ProviderManager.java:121)
at SmackCcsClient.<clinit>(SmackCcsClient.java:58)
Caused by: java.lang.ClassNotFoundException: de.measite.minidns.DNSCache
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 10 more
Source: (StackOverflow)