samedi 25 juin 2016

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.(Windows)

Just cloned a project from github and while doing bundle install getting above for two or three gems. Not able to get proper solution. Tried some suggested solution but they are not working..

C:UsersMayuresh>d:

D:>cd MyWork

D:MyWork>cd ruby

D:MyWorkruby>git clone https://github.com/ging/vish

Cloning into 'vish'...
remote: Counting objects: 91613, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 91613 (delta 0), reused 0 (delta 0), pack-reused 91611
Receiving objects: 100% (91613/91613), 251.20 MiB | 87.00 KiB/s, done.
Resolving deltas: 100% (59935/59935), done.
Checking connectivity... done.
Checking out files: 100% (2689/2689), done.

D:MyWorkruby>dir

Volume in drive D is Eclectic
 Volume Serial Number is 64EA-C566

 Directory of D:MyWorkruby

06/25/2016  09:07 PM    <DIR>          .
06/25/2016  09:07 PM    <DIR>          ..
06/19/2016  11:44 AM    <DIR>          ELANCO_ATP_ATOPICA
06/17/2016  11:24 PM                90 hello_sinatra.rb
06/17/2016  11:22 PM                90 hello_sinatra.rb~
06/13/2016  12:48 AM               348 player_spec.rb
06/25/2016  04:37 PM    <DIR>          ruby-getting-started
06/12/2016  04:06 PM               325 scrabble.rb
06/12/2016  04:04 PM               289 scrabble.rb~
06/08/2016  01:58 AM               407 treasure_trove.rb
06/25/2016  09:41 PM    <DIR>          vish
               6 File(s)          1,549 bytes
               5 Dir(s)   1,427,271,680 bytes free

D:MyWorkruby>cd vish

D:MyWorkrubyvish>rails s

git://github.com/agordillo/scorm.git (at master@b3d47f9) is not yet checked out.
 Run `bundle install` first.

D:MyWorkrubyvish>bundle install

Fetching git://github.com/agordillo/scorm.git
Fetching git://github.com/ging/social_stream.git
Checking out files: 100% (1466/1466), done.
Fetching git://github.com/ebarra/paperclip-ffmpeg.git
Fetching git://github.com/ebarra/oai_repository.git
Fetching git://github.com/pahanix/delegates_attributes_to.git
Fetching git://github.com/galetahub/simple-captcha.git
Fetching git://github.com/randym/acts_as_xlsx.git
Fetching git://github.com/mojombo/god.git
Fetching git://github.com/rails/rails.git
Checking out files: 100% (2433/2433), done.
Fetching gem metadata from http://rubygems.org/..........
Fetching version metadata from http://rubygems.org/...
Fetching dependency metadata from http://rubygems.org/..
Resolving dependencies..................
Installing rake 10.5.0
Installing Ascii85 1.0.2
Using i18n 0.7.0
Using multi_json 1.11.2
Installing builder 3.0.4
Using erubis 2.7.0
Installing journey 1.0.4
Installing rack 1.4.7
Installing hike 1.2.3
Using tilt 1.4.1
Installing mime-types 1.25.1
Installing polyglot 0.3.5
Installing arel 3.0.3
Installing tzinfo 0.3.46
Using bundler 1.11.2
Using json 1.8.3
Using thor 0.19.1
Installing htmlentities 4.3.4
Installing nokogiri 1.5.11
Installing rubyzip 1.0.0
Installing afm 0.2.2
Installing rmagick 2.13.2 with native extensions

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    C:/Ruby22/bin/ruby.exe -r ./siteconf20160625-1860-1ntnc6k.rb extconf.rb
checking for Ruby version >= 1.8.5... yes
Invalid drive specification.
Unable to get ImageMagick version
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=C:/Ruby22/bin/$(RUBY_BASE_NAME)

extconf failed, exit code 1

Gem files will remain installed in C:/Ruby22/lib/ruby/gems/2.2.0/gems/rmagick-2.
13.2 for inspection.
Results logged to C:/Ruby22/lib/ruby/gems/2.2.0/extensions/x86-mingw32/2.2.0/rma
gick-2.13.2/gem_make.out
Installing bcrypt 3.1.11
Installing sass 3.4.21
Installing cancan 1.6.10
Installing highline 1.7.8
Installing jruby-pageant 1.1.1
Installing ffi 1.9.10
Installing coderay 1.1.1
Using coffee-script-source 1.10.0
Using execjs 2.6.0
Installing deep_merge 1.0.1
Using delegates_attributes_to 0.0.1 from git://github.com/pahanix/delegates_attr
ibutes_to.git (at 69704cb@69704cb)
Installing descriptive_statistics 2.4.0
Installing detect_language 1.0.5
Using orm_adapter 0.5.0
Installing diff-lcs 1.1.3
Installing multipart-post 2.0.0
Installing forgery 0.6.0
Installing hashie 2.1.2
Using god 0.13.5 from git://github.com/mojombo/god.git (at a0602dd@a0602dd)
Installing hashery 2.1.1
Installing jwt 1.4.1
Installing kgio 2.10.0 with native extensions

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    C:/Ruby22/bin/ruby.exe -r ./siteconf20160625-1860-1i5gmei.rb extconf.rb
checking for CLOCK_MONOTONIC in time.h... yes
checking for clockid_t in time.h... yes
checking for clock_gettime() in -lrt... no
checking for t_open() in -lnsl... no
checking for socket() in -lsocket... no
checking for poll() in poll.h... no
checking for getaddrinfo() in sys/types.h,sys/socket.h,netdb.h... no
getaddrinfo required
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=C:/Ruby22/bin/$(RUBY_BASE_NAME)
        --with-rtlib
        --without-rtlib
        --with-nsllib
        --without-nsllib
        --with-socketlib
        --without-socketlib

extconf failed, exit code 1

Gem files will remain installed in C:/Ruby22/lib/ruby/gems/2.2.0/gems/kgio-2.10.
0 for inspection.
Results logged to C:/Ruby22/lib/ruby/gems/2.2.0/extensions/x86-mingw32/2.2.0/kgi
o-2.10.0/gem_make.out
Installing ruby-imagespec 0.2.0
Installing method_source 0.8.2
Installing modernizr-rails 2.7.1
Installing multi_xml 0.5.5
Installing mysql2 0.3.16 with native extensions

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    C:/Ruby22/bin/ruby.exe -r ./siteconf20160625-1860-1iw3agb.rb extconf.rb
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... no
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=C:/Ruby22/bin/$(RUBY_BASE_NAME)
        --with-mysql-dir
        --without-mysql-dir
        --with-mysql-include
        --without-mysql-include=${mysql-dir}/include
        --with-mysql-lib
        --without-mysql-lib=${mysql-dir}/lib
        --with-mysql-config
        --without-mysql-config
        --with-mysql-dir
        --without-mysql-dir
        --with-mysql-include
        --without-mysql-include=${mysql-dir}/include
        --with-mysql-lib
        --without-mysql-lib=${mysql-dir}/lib
        --with-mysqlclientlib
        --without-mysqlclientlib
        --with-mlib
        --without-mlib
        --with-mysqlclientlib
        --without-mysqlclientlib
        --with-zlib
        --without-zlib
        --with-mysqlclientlib
        --without-mysqlclientlib
        --with-socketlib
        --without-socketlib
        --with-mysqlclientlib
        --without-mysqlclientlib
        --with-nsllib
        --without-nsllib
        --with-mysqlclientlib
        --without-mysqlclientlib
        --with-mygcclib
        --without-mygcclib
        --with-mysqlclientlib
        --without-mysqlclientlib

extconf failed, exit code 1

Gem files will remain installed in C:/Ruby22/lib/ruby/gems/2.2.0/gems/mysql2-0.3
.16 for inspection.
Results logged to C:/Ruby22/lib/ruby/gems/2.2.0/extensions/x86-mingw32/2.2.0/mys
ql2-0.3.16/gem_make.out
Installing oauth 0.5.1
Installing ruby-rc4 0.1.5
Installing ttfunk 1.4.0
Using pg 0.17.1
Installing power_assert 0.2.7
Installing slop 3.6.0
Installing win32console 1.3.2
Installing raindrops 0.16.0 with native extensions

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    C:/Ruby22/bin/ruby.exe -r ./siteconf20160625-1860-nrxioh.rb extconf.rb
checking for mmap() in sys/mman.h... no
mmap() not found
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=C:/Ruby22/bin/$(RUBY_BASE_NAME)
        --with-atomic_ops-dir
        --without-atomic_ops-dir
        --with-atomic_ops-include
        --without-atomic_ops-include=${atomic_ops-dir}/include
        --with-atomic_ops-lib
        --without-atomic_ops-lib=${atomic_ops-dir}/lib

extconf failed, exit code 1

Gem files will remain installed in C:/Ruby22/lib/ruby/gems/2.2.0/gems/raindrops-
0.16.0 for inspection.
Results logged to C:/Ruby22/lib/ruby/gems/2.2.0/extensions/x86-mingw32/2.2.0/rai
ndrops-0.16.0/gem_make.out
Installing redis 3.0.7
Installing riddle 1.5.12
Installing rspec-core 2.9.0
Installing rspec-mocks 2.9.0
Installing websocket 1.2.2
Using simple_captcha 0.1.6 from git://github.com/galetahub/simple-captcha.git (a
t 2602bf1@2602bf1)
Installing stringex 1.5.1
Installing sqlite3 1.3.9
Installing faker 1.4.3
Installing i18n-js 2.1.2
Using activesupport 3.2.22.2 from git://github.com/rails/rails.git (at 3-2-stabl
e@54ebd0a)
Installing sitemap_generator 5.1.0
Installing rack-cache 1.6.1
Using rack-test 0.6.3
Installing rack-ssl 1.3.4
Installing warden 1.2.6
Installing rack-protection 1.5.3
Installing vegas 0.1.11
Installing sprockets 2.2.3
Installing rest-client 1.6.7
Installing treetop 1.4.15
Installing rdoc 3.12.2
Installing xpath 2.0.0
Installing sanitize 2.1.0
Installing axlsx 2.0.1
Using scorm 1.0.5 from git://github.com/agordillo/scorm.git (at master@b3d47f9)
An error occurred while installing rmagick (2.13.2), and Bundler cannot
continue.
Make sure that `gem install rmagick -v '2.13.2'` succeeds before bundling.

D:MyWorkrubyvish>

Measure CPU Load Difference Between Four Similar Javascript Functions

Why this is important to me

I have a site where I need to have a countdown timer running to show people how much time they have left to complete an action.

This timer will run for days and probably just use MomentJS to say something like "in 4 days" from MomentJS's to() function.

However when we have an hour left to go I'm going to switch over to a countdown by minutes timer, eventually when the minutes get low enough, I'm going to have a seconds timer involved. When we're getting down to the very last few minutes I'm going to even display milliseconds.


The problem

Pretty much there are two main techniques to animate the countdown timer.

  • setInterval()
  • requestAnimationFrame()

Well, right away I noticed that the requestAnimationFrame() method was much more smooth to the eye, it works great - especially when I'm displaying milliseconds. However it wasn't long when I noticed that my poor computer started to get a little warm. All of this "animation" is causing quite a load on my CPU. I tried to use CPU monitors, and looked around at ways to see how much load this puts on my CPU but, overall I can't really find a tool that gives me a clear graph of what kind of CPU load my little countdown timer is using.

So, I decided to find a way to limit the FPS and see if that would reduce my problem. And yes, it does. If you use setTimeout() in tandem with requestAnimationFrame() you can set a waiting time before you call your next function.

Which raises the question, if you're using setTimeout() - Why don't you just use setInterval() and forget about the extra optimization that requestAnimationFrame() gives you?

I did some looking around and found another method which simply checks to see if the right amount of interval time has passed since the last time requestAnimationFrame() called your function. I made some optimizations to how this code works and ended up with one of the two functions I'm trying to measure below.

In the end, I'd really like to have a more clear way to measure this - because the activity monitor on my mac is hardly reliable tool to give an accurate reading - and I can't find a way to measure just the code I'm running.

Chrome has some more tools, the profiler, and the timeline - which are both very helpful, but they don't give me the metric I'm looking for - CPU load.


The Code:

Here are four code snippets, which do exactly the same thing - all of them use:

  • MomentJS
  • CountdownJS
  • jQuery

The code is 100% identical, the only difference is how I am limiting the FPS of the animation.

I'd like to find a way to measure (as precisely as possible) the difference between the four functions in how much CPU load they are taking. And then I'd like to then change the FPS around to see if I can find an acceptable load for my application and then I can find the sweet spot - the right amount of FPS, during the different timer stages.

Technique 1 - setTimeout()

var now = moment(); // new Date().getTime();
var then = moment().add(60, 'seconds'); // new Date(now + 60 * 1000);

$(".now").text(moment(now).format('h:mm:ss a'));
$(".then").text(moment(then).format('h:mm:ss a'));
$(".duration").text(moment(now).to(then));

(function timerLoop() {
  setTimeout(function(){
    $(".difference").text(moment().to(then));
    $(".countdown").text(countdown(then, null, countdown.YEARS | countdown.MONTHS | countdown.DAYS | countdown.HOURS | countdown.MINUTES | countdown.SECONDS | countdown.MILLISECONDS).toString());
    requestAnimationFrame(timerLoop);
  }, 1000/30);
})();
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.min.js" type="text/javascript"></script>
<script src="https://cdn.rawgit.com/mckamey/countdownjs/master/countdown.min.js" type="text/javascript"></script>
<script src="https://code.jquery.com/jquery-3.0.0.min.js" type="text/javascript"></script>
<div>
  The time is now: <span class="now"></span>, a timer will go off <span class="duration"></span> at <span class="then"></span>
</div>
<div>The timer is set to go off <span class="difference"></span></div>
<div class="countdown"></div>

Technique 2 - Delta between intervals

var now = moment(); // new Date().getTime();
var then = moment().add(60, 'seconds'); // new Date(now + 60 * 1000);

$(".now").text(moment(now).format('h:mm:ss a'));
$(".then").text(moment(then).format('h:mm:ss a'));
$(".duration").text(moment(now).to(then));

var fps = 30;
var interval = 1000/fps;
var performanceTime = performance.now();
var performanceDelta;

(function updateCountdown(time) {
  performanceDelta = time - performanceTime;
  if (performanceDelta > interval) {
    performanceTime = time - (performanceDelta % interval);
    $(".difference").text(moment().to(then));
    $(".countdown").text(countdown(then, null, countdown.YEARS | countdown.MONTHS | countdown.DAYS | countdown.HOURS | countdown.MINUTES | countdown.SECONDS | countdown.MILLISECONDS).toString());
  }
  requestAnimationFrame(updateCountdown);
})();
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.min.js" type="text/javascript"></script>
<script src="https://cdn.rawgit.com/mckamey/countdownjs/master/countdown.min.js" type="text/javascript"></script>
<script src="https://code.jquery.com/jquery-3.0.0.min.js" type="text/javascript"></script>
<div>
  The time is now: <span class="now"></span>, a timer will go off <span class="duration"></span> at <span class="then"></span>
</div>
<div>The timer is set to go off <span class="difference"></span></div>
<div class="countdown"></div>

Technique 3 - setInterval()

var now = moment(); // new Date().getTime();
var then = moment().add(60, 'seconds'); // new Date(now + 60 * 1000);

$(".now").text(moment(now).format('h:mm:ss a'));
$(".then").text(moment(then).format('h:mm:ss a'));
$(".duration").text(moment(now).to(then));

var fps = 30;
var interval = 1000/fps;

setInterval(function updateCountdown() {
    $(".difference").text(moment().to(then));
    $(".countdown").text(countdown(then, null, countdown.YEARS | countdown.MONTHS | countdown.DAYS | countdown.HOURS | countdown.MINUTES | countdown.SECONDS | countdown.MILLISECONDS).toString());
}, interval);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.min.js" type="text/javascript"></script>
<script src="https://cdn.rawgit.com/mckamey/countdownjs/master/countdown.min.js" type="text/javascript"></script>
<script src="https://code.jquery.com/jquery-3.0.0.min.js" type="text/javascript"></script>
<div>
  The time is now: <span class="now"></span>, a timer will go off <span class="duration"></span> at <span class="then"></span>
</div>
<div>The timer is set to go off <span class="difference"></span></div>
<div class="countdown"></div>

It would also be interesting to see a completely un-throttled version like so:

Technique 4 - No throttle

var now = moment(); // new Date().getTime();
var then = moment().add(60, 'seconds'); // new Date(now + 60 * 1000);

$(".now").text(moment(now).format('h:mm:ss a'));
$(".then").text(moment(then).format('h:mm:ss a'));
$(".duration").text(moment(now).to(then));
(function timerLoop() {
  $(".difference").text(moment().to(then));
  $(".countdown").text(countdown(then, null, countdown.YEARS | countdown.MONTHS | countdown.DAYS | countdown.HOURS | countdown.MINUTES | countdown.SECONDS | countdown.MILLISECONDS).toString());
  requestAnimationFrame(timerLoop);
})();

// CountdownJS: http://countdownjs.org/
// MomentJS: http://momentjs.com/
// jQuery: https://jquery.com/
// Rawgit: http://rawgit.com/
// Light reading about the requestAnimationFrame pattern:
// http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/
// https://css-tricks.com/using-requestanimationframe/
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.min.js" type="text/javascript"></script>
<script src="https://cdn.rawgit.com/mckamey/countdownjs/master/countdown.min.js" type="text/javascript"></script>
<script src="https://code.jquery.com/jquery-3.0.0.min.js" type="text/javascript"></script>
<div>
  The time is now: <span class="now"></span>, a timer will go off <span class="duration"></span> at <span class="then"></span>
</div>
<div>The timer is set to go off <span class="difference"></span></div>
<div class="countdown"></div>

Simply Put: How does one measure the CPU load difference between four similar javascript functions?

Does anyone already know which of these is going to be more performant? (I know that is not really a word)

How to unregister ForceLoadContentObserver?

Am new For Android am having doubt regarding how to unregister ForceLoadContentObserver in onDestroy method Here let me explain my problem briefly i use cursolader and Cursor recyclerviewadapter for whenever data changes in sqlite db but i feel like am leaking memory because am not unregistering the ForceLoadContentObserver how can i do this . Here Let me post my Code:

This is the activity where am using ForceLoadContentObserver:

public class Customer extends AppCompatActivity implements LoaderManager.LoaderCallbacks<Cursor>,SearchView.OnQueryTextListener {
    private static final int customer = 1;
    RecyclerView recyclerView;
    TimeTrackerDAO timetrackerdaoobj;
    Cursor c;
    String mCurFilter;
    CustomerListAdapter customerlistadapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_customer);
        this.runOnUiThread(new Runnable() {
            @Override
            public void run() {

                Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
                setSupportActionBar(toolbar);
                recyclerView = (RecyclerView) findViewById(R.id.customer_recyclerview);

                FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
                timetrackerdaoobj = new TimeTrackerDAO(getApplicationContext());
                fab.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Intent intent = new Intent(getApplicationContext(), CustomerDetails.class);
                        startActivity(intent);
                    }
                });
                if (getSupportActionBar()!=null) {
                    getSupportActionBar().setDisplayShowHomeEnabled(true);
                    toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
                    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            Intent intent = new Intent(getApplicationContext(), DashBoard.class);
                            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                            startActivity(intent);
                        }
                    });
                }
            }
        });

        getLoaderManager().initLoader(customer, null, this);

             }

             @Override
             public Loader<Cursor> onCreateLoader(int id, Bundle args) {
                 return new CursorLoader(getApplicationContext(), TimeTrackerDAO.DB_Timetracker, null, null, null, null) {

                   ForceLoadContentObserver    mObserver = new ForceLoadContentObserver();

                     @Override
                     public Cursor loadInBackground() {

                         if (mCurFilter != null) {
                             c = timetrackerdaoobj.SearchCustomerList(mCurFilter);
                         } else{
                             c = timetrackerdaoobj.CustomerList();
                         if (c != null) {
                             c.getCount();
                             c.registerContentObserver(mObserver);
                             c.setNotificationUri(getContext().getContentResolver(), getUri());
                         }
                     }
                         return c;
                     }

                 };


             }

             @Override
             public void onLoadFinished(Loader<Cursor> loader,final Cursor data) {
                 this.runOnUiThread(new Runnable() {
                     @Override
                     public void run() {
                LinearLayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
                 layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                 recyclerView.setLayoutManager(layoutManager);
                 customerlistadapter = new CustomerListAdapter(getApplicationContext(), data);
                 recyclerView.setAdapter(customerlistadapter);
                 customerlistadapter.setOnItemClickListener(new CustomerListAdapter.OnItemClickListener() {
                     @Override
                     public void onItemClicked(Cursor cursor) {
                         Integer webid=cursor.getInt(cursor.getColumnIndex(CustomerModel.Customer_WebID));
                         if(webid<=0){
                             Toast.makeText(getApplicationContext(),"Please Sync The Data Before Editing",Toast.LENGTH_SHORT).show();
                         }
                         else {
                         Integer id = cursor.getInt(cursor.getColumnIndex(CustomerModel.CustomerPrimaryID));Bundle bundle = new Bundle();
                         String CreatedDateTime=cursor.getString(cursor.getColumnIndex(CustomerModel.Customer_CreatedAt
                         ));
                         Integer timeflag=cursor.getInt(cursor.getColumnIndex(CustomerModel.Customer_TimeFlag));
                         Integer Createdby=cursor.getInt(cursor.getColumnIndex(CustomerModel.Customer_CreateByID));
                            String Createdbyname=cursor.getString(cursor.getColumnIndex(CustomerModel.Customer_CreatedBy));
                             bundle.putInt("webid",webid);
                             bundle.putInt("customerid", id);
                             bundle.putInt("createdbys",Createdby);
                             bundle.putInt("timeflag",timeflag);
                             bundle.putString("createdbyname",Createdbyname);
                             bundle.putString("createdby",CreatedDateTime);
                         Intent intent = new Intent(getApplicationContext(), CustomerView.class);
                         intent.putExtras(bundle);
                         startActivity(intent);
                     }
                     }
                 });}});
            customerlistadapter.swapCursor(data);

             }

             @Override
             protected void onResume() {
                 super.onResume();

             }

             @Override
             public void onLoaderReset(Loader<Cursor> loader) {
                   customerlistadapter.swapCursor(null);

             }

    @Override
    protected void onDestroy() {
        super.onDestroy();

    }

    @Override
             public boolean onCreateOptionsMenu(Menu menu) {
                 MenuInflater inflater = getMenuInflater();
                 inflater.inflate(R.menu.sync, menu);
                 MenuItem searchItem = menu.findItem(R.id.searchcustomer);
               SearchView  msearchview=(SearchView) MenuItemCompat.getActionView(searchItem);
                msearchview.setOnQueryTextListener(this);
                 return super.onCreateOptionsMenu(menu);
             }

             @Override
             public boolean onOptionsItemSelected(MenuItem item) {
                 switch (item.getItemId()) {
                     case R.id.sync:
                        OnClick();

                 return true;
                     case R.id.searchcustomer:

                 }
                 return super.onOptionsItemSelected(item);
             }

    @Override
    public boolean onQueryTextSubmit(String query) {
        return false;
    }

    @Override
    public boolean onQueryTextChange(String newText) {
        mCurFilter = !TextUtils.isEmpty(newText) ? newText : null;
        getLoaderManager().restartLoader(0, null, this);
        return false;
    }


    public class CustomerDetail extends AsyncTask<String, String, String> {
                 String JsonResponse = null;

                 @Override
                 protected String doInBackground(String... params) {
                     HttpURLConnection urlConnection = null;
                     String JsonDATA = params[0];
                     byte[] post = JsonDATA.getBytes();
                     int request_post = post.length;
                     BufferedReader reader = null;
                     try {
                         Thread.sleep(2000);
                         URL url = new URL("http://xxx");
                         urlConnection = (HttpURLConnection) url.openConnection();
                         urlConnection.setRequestMethod("POST");
                         urlConnection.setRequestProperty("Content-Type", "application/json");
                         urlConnection.setRequestProperty("charset", "utf-8");
                         urlConnection.setRequestProperty("Content-Length", Integer.toString(request_post));
                         urlConnection.setDoOutput(true);
                         OutputStreamWriter writer = new OutputStreamWriter(urlConnection.getOutputStream());
                         writer.write(JsonDATA);
                         writer.close();
                         int response = urlConnection.getResponseCode();
                         if (response >= 400 && response <= 499) {
                             Log.e("", "HTTPx Response: " + response + " - " + urlConnection.getResponseMessage());
                             InputStream in = new BufferedInputStream(urlConnection.getErrorStream());
                         }
                         InputStream inputStream = urlConnection.getInputStream();
                         StringBuilder buffer = new StringBuilder();
                         if (inputStream == null) {
                             return null;
                         }
                         reader = new BufferedReader(new InputStreamReader(inputStream));
                         String inputLine;
                         while ((inputLine = reader.readLine()) != null)
                             buffer.append(inputLine + "n");
                         if (buffer.length() == 0) {
                             // Stream was empty. No point in parsing.
                             return null;
                         }
                         JsonResponse = buffer.toString();
                         Log.i("response", JsonResponse);
                         return JsonResponse;


                     } catch (IOException e) {
                         e.printStackTrace();
                     } catch (InterruptedException e) {
                         e.printStackTrace();
                     } finally {
                         if (urlConnection != null) {
                             urlConnection.disconnect();
                         }
                         if (reader != null) {
                             try {
                                 reader.close();
                             } catch (final IOException e) {
                                 Log.e("", "Error closing stream", e);
                             }
                         }
                     }
                     return null;
                 }

                 @Override
                 protected void onPostExecute(String s) {
                     super.onPostExecute(s);
                     CustomerModel customerModel=new CustomerModel();
                     try {
                         JSONArray jsonArray=new JSONArray(s);
                         for(int i=0;i<jsonArray.length();i++) {
                            JSONObject jsonObject=jsonArray.getJSONObject(i);
                             int webid=jsonObject.getInt("WebID");
                             int appid=jsonObject.getInt("AppID");
                             customerModel.setFlag(0);
                             customerModel.setCustomerID(webid);
                             customerModel.setID(appid);
                             timetrackerdaoobj.UpdateWebCustomer(customerModel);
                             customerlistadapter.addModelClass(customerModel);

                         }

                     } catch (JSONException e) {
                         e.printStackTrace();
                     }

                 }
             }
    public class CustomerUpdate extends AsyncTask<String, String, String> {
        String JsonResponse = null;

        @Override
        protected String doInBackground(String... params) {
            HttpURLConnection urlConnection = null;
            String JsonDATA = params[0];
            byte[] post = JsonDATA.getBytes();
            int request_post = post.length;
            BufferedReader reader = null;
            try {
                Thread.sleep(2000);
                URL url = new URL("xxx");
                urlConnection = (HttpURLConnection) url.openConnection();
                urlConnection.setRequestMethod("POST");
                urlConnection.setRequestProperty("Content-Type", "application/json");
                urlConnection.setRequestProperty("charset", "utf-8");
                urlConnection.setRequestProperty("Content-Length", Integer.toString(request_post));
                urlConnection.setDoOutput(true);
                OutputStreamWriter writer = new OutputStreamWriter(urlConnection.getOutputStream());
                writer.write(JsonDATA);
                writer.close();
                int response = urlConnection.getResponseCode();
                if (response >= 400 && response <= 499) {
                    Log.e("", "HTTPx Response: " + response + " - " + urlConnection.getResponseMessage());
                    InputStream in = new BufferedInputStream(urlConnection.getErrorStream());
                }
                InputStream inputStream = urlConnection.getInputStream();
                StringBuilder buffer = new StringBuilder();
                if (inputStream == null) {
                    return null;
                }
                reader = new BufferedReader(new InputStreamReader(inputStream));
                String inputLine;
                while ((inputLine = reader.readLine()) != null)
                    buffer.append(inputLine + "n");
                if (buffer.length() == 0) {
                    // Stream was empty. No point in parsing.
                    return null;
                }
                JsonResponse = buffer.toString();
                Log.i("response", JsonResponse);
                if(JsonResponse.contains("Success")){
                    timetrackerdaoobj.UpdateCustomer();
                }
                return JsonResponse;


            } catch (IOException e) {
                e.printStackTrace();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } finally {
                if (urlConnection != null) {
                    urlConnection.disconnect();
                }
                if (reader != null) {
                    try {
                        reader.close();
                    } catch (final IOException e) {
                        Log.e("", "Error closing stream", e);
                    }
                }
            }
            return null;
        }

        @Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);

        }
    }
             public class CustomerList extends AsyncTask<String, Void, Void> {
                 ProgressDialog Dialog = new ProgressDialog(Customer.this);

                 @Override
                 protected void onPreExecute() {
                     super.onPreExecute();
                     Dialog.setMessage("Syncing Please Wait");
                     Dialog.show();

                 }


                 @Override
                 protected Void doInBackground(String... params) {


                     RequestQueue queuess = Volley.newRequestQueue(getApplicationContext());
                     JsonArrayRequest jsonObjRequestss = new JsonArrayRequest(Request.Method.GET, params[0], new JSONArray(),
                             new Response.Listener<JSONArray>() {
                                 @Override
                                 public void onResponse(JSONArray response) {
                                     String server_response = response.toString();
                                     try {
                                         CustomerModel customerModel=new CustomerModel();
                                         JSONArray jsonArray = new JSONArray(server_response);
                                         for (int i = 0; i < jsonArray.length(); i++) {
                                                JSONObject jsonObject = jsonArray.getJSONObject(i);
                                                customerModel.setCustomerID(jsonObject.getInt("CustomerID"));
                                                String customername=jsonObject.getString("CustomerName");
                                                String customerName=customername.substring(0, 1).toUpperCase() + customername.substring(1);
                                                customerModel.setCustomerName(customerName);
                                                customerModel.setMobileNumber(jsonObject.getString("MobileNo"));
                                                customerModel.setPhoneNumber(jsonObject.getString("PhoneNo"));
                                                customerModel.setEmailID(jsonObject.getString("EmailID"));
                                                customerModel.setCreatedat(jsonObject.getString("CreatedDatetime"));
                                                customerModel.setLastModifiedAt(jsonObject.getString("LastModifiedDatetime"));
                                                int id=jsonObject.getInt("Status");
                                                customerModel.setTimeFlag(1);
                                                customerModel.setCreatedBy(jsonObject.getInt("CreatedBy"));
                                                customerModel.setLastModifiedBy(jsonObject.getInt("LastModifiedBy"));
                                             if(id==1){
                                                 customerModel.setStatus("Active");
                                                 customerModel.setStatusID(1);
                                             }
                                             else{
                                                 customerModel.setStatus("In Active");
                                                 customerModel.setStatusID(0);
                                             }
                                           String datetime=jsonObject.getString("LastModifiedDatetime");
                                             customerModel.setLastModifiedFlag(datetime);
                                             timetrackerdaoobj.CustomerInsertorUpdate(customerModel);
                                            customerlistadapter.addModelClass(customerModel);
                                          }


                                     } catch (JSONException e) {
                                         e.printStackTrace();
                                     }

                                 }
                             },
                             new Response.ErrorListener() {
                                 @Override
                                 public void onErrorResponse(VolleyError error) {
                                     Log.e("error", "");
                                 }
                             });

                     //Creating request queue

                     queuess.add(jsonObjRequestss);

                     return null;
                 } @Override
                   protected void onPostExecute(Void modleobjs) {
                     super.onPostExecute(modleobjs);


                     Dialog.hide();

                 }
             }


    public void OnClick(){
        this.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                 String datetime=timetrackerdaoobj.DateTime();
                  String CustomerListUrl="http://172.16.7.55:8080/Rest/TimeTracker/restcustomergetlistbydate/ " + datetime;
                if(datetime.equals("")){
                     new CustomerList().execute(CustomerListUrl);
                    Log.d("url", CustomerListUrl);
                }
                else{
                    CustomerListUrl=CustomerListUrl.replace(" ", "%20");
                    new CustomerList().execute(CustomerListUrl);
                    Log.d("url", CustomerListUrl);
                }
                List<CustomerModel> listobj;
                listobj = timetrackerdaoobj.Listtoserver();
                Gson gson = new Gson();
                String gsonString = gson.toJson(listobj);
                int id=timetrackerdaoobj.getServerCunt();
                int updateid=timetrackerdaoobj.getUpdateCount();

                List<CustomerModel>listupdatted;
                listupdatted=timetrackerdaoobj.EditListtoserver();
                String gsonupdatestring=gson.toJson(listupdatted);
                if(updateid>0){
                    new CustomerUpdate().execute(gsonupdatestring);
                }
                if(id>0) {
                    new CustomerDetail().execute(gsonString);
                }
                else{
                    Log.d("no records","No Records");
                }

            }
        });
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        Intent intent = new Intent(getApplicationContext(), DashBoard.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
    }

}

Here is the CursorRecyclerViewAdapter:

package Adapters;

public abstract class CursorRecycleViewAdapter<VH extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<VH> {

    private Context mContext;

    private Cursor mCursor;

    private boolean mDataValid;

    private int mRowIdColumn;

    private DataSetObserver mDataSetObserver;

    public CursorRecycleViewAdapter(Context context, Cursor cursor) {
        mContext = context;
        mCursor = cursor;
        mDataValid = cursor != null;
        mRowIdColumn = mDataValid ? mCursor.getColumnIndex("_id") : -1;
        mDataSetObserver = new NotifyingDataSetObserver();
        if (mCursor != null) {
            mCursor.registerDataSetObserver(mDataSetObserver);
        }
    }

    public Cursor getCursor() {
        return mCursor;
    }

    @Override
    public int getItemCount() {
        if (mDataValid && mCursor != null) {
            return mCursor.getCount();
        }
        return 0;
    }

    public Cursor getItem(final int position) {
        if (this.mCursor != null && !this.mCursor.isClosed()) {
            this.mCursor.moveToPosition(position);
        }

        return this.mCursor;
    }

    @Override
    public long getItemId(int position) {
        if (mDataValid && mCursor != null && mCursor.moveToPosition(position)) {
            return mCursor.getLong(mRowIdColumn);
        }
        return 0;
    }

    @Override
    public void setHasStableIds(boolean hasStableIds) {
        super.setHasStableIds(true);
    }

    public abstract void onBindViewHolder(VH viewHolder, Cursor cursor);

    @Override
    public void onBindViewHolder(VH viewHolder, int position) {
        if (!mDataValid) {
            throw new IllegalStateException("this should only be called when the cursor is valid");
        }
        if (!mCursor.moveToPosition(position)) {
            throw new IllegalStateException("couldn't move cursor to position " + position);
        }
        onBindViewHolder(viewHolder, mCursor);
    }

    /**
     * Change the underlying cursor to a new cursor. If there is an existing cursor it will be
     * closed.
     */
    public void changeCursor(Cursor cursor) {
        Cursor old = swapCursor(cursor);
        if (old != null) {
            old.close();
        }
    }

    /**
     * Swap in a new Cursor, returning the old Cursor.  Unlike
     * {@link #changeCursor(Cursor)}, the returned old Cursor is <em>not</em>
     * closed.
     */
    public Cursor swapCursor(Cursor newCursor) {
        if (newCursor == mCursor) {
            return null;
        }
        final Cursor oldCursor = mCursor;
        if (oldCursor != null && mDataSetObserver != null) {
            oldCursor.unregisterDataSetObserver(mDataSetObserver);
        }
        mCursor = newCursor;
        if (mCursor != null) {
            if (mDataSetObserver != null) {
                mCursor.registerDataSetObserver(mDataSetObserver);
            }
            mRowIdColumn = newCursor.getColumnIndexOrThrow("_id");
            mDataValid = true;
            notifyDataSetChanged();
        } else {
            mRowIdColumn = -1;
            mDataValid = false;
            notifyDataSetChanged();
            //There is no notifyDataSetInvalidated() method in RecyclerView.Adapter
        }
        return oldCursor;
    }

    private class NotifyingDataSetObserver extends DataSetObserver {
        @Override
        public void onChanged() {
            super.onChanged();
            mDataValid = true;
            notifyDataSetChanged();
        }

        @Override
        public void onInvalidated() {
            super.onInvalidated();
            mDataValid = false;
            notifyDataSetChanged();
            //There is no notifyDataSetInvalidated() method in RecyclerView.Adapter
        }
    }
}

Is it the efficient way my primay doubt is how to unregister the ContentObsever used in my activity One More info am not using Content Provider

Google App Engine - Java 8 and JSP Files: compilation error

I just configured my Eclipse Mars with JDK8 and Google Eclipse Plugin. As reported by the documentation itself, the JDK8 is usable if the project compliance is set to JDK7, which I have done.

It seems that the project works fine if is limited to Servlet endpoints, but if there are any JSP files there is a problem starting the dev-server.

Here a simple guide on how to reproduce the problem.

  • Create a new App Engine Maven Project (I used "appengine-skeleton-archetype" archetype)
  • Create a new JSP file (inside the webapp folder) with a content of your choice
  • In web.xml change the welcome-file to index.jsp
  • Start the dev-server

The JSP file I made is very simple, is just template-created by Eclipse:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
    Here!
</body>
</html>

If you don't want to edit the <welcome-file> configuration you can simply invoke the JSP you made by url

If you have a configuration like mine (Eclipse with JDK8), starting the dev-server you should get something like this

giu 25, 2016 6:04:18 PM com.google.appengine.tools.development.SystemPropertiesManager setSystemProperties
INFORMAZIONI: Overwriting system property key 'java.util.logging.config.file', value 'C:UsersNicola.m2repositorycomgoogleappengineappengine-java-sdk1.9.38appengine-java-sdkappengine-java-sdk-1.9.38configsdklogging.properties' with value 'WEB-INF/logging.properties' from 'C:UsersNicolaworkspace_neon.metadata.pluginsorg.eclipse.wst.server.coretmp1testWEB-INFappengine-web.xml'
giu 25, 2016 6:04:18 PM com.google.apphosting.utils.jetty.JettyLogger info
INFORMAZIONI: Logging to JettyLogger(null) via com.google.apphosting.utils.jetty.JettyLogger
giu 25, 2016 6:04:19 PM com.google.appengine.tools.development.DevAppServerImpl setServerTimeZone
AVVERTENZA: Unable to set the TimeZone to UTC (this is expected if running on JDK 8)
giu 25, 2016 6:04:19 PM com.google.apphosting.utils.jetty.JettyLogger info
INFORMAZIONI: jetty-6.1.x
giu 25, 2016 6:04:21 PM com.google.apphosting.utils.jetty.JettyLogger info
INFORMAZIONI: Started SelectChannelConnector@127.0.0.1:8888
giu 25, 2016 6:04:21 PM com.google.appengine.tools.development.JettyContainerService startHotDeployScanner
INFORMAZIONI: Full scan of the web app in place every 5s.
giu 25, 2016 6:04:21 PM com.google.appengine.tools.development.AbstractModule startup
INFORMAZIONI: Module instance default is running at http://localhost:8888/
giu 25, 2016 6:04:21 PM com.google.appengine.tools.development.AbstractModule startup
INFORMAZIONI: The admin console is running at http://localhost:8888/_ah/admin
giu 25, 2016 6:04:21 PM com.google.appengine.tools.development.DevAppServerImpl doStart
INFORMAZIONI: Dev App Server is now running
giu 25, 2016 6:04:22 PM org.apache.jasper.compiler.JDTCompiler$1 findType
GRAVE: Compilation error
org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException
    at org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader.<init>(ClassFileReader.java:342)
    at org.apache.jasper.compiler.JDTCompiler$1.findType(JDTCompiler.java:206)
    at org.apache.jasper.compiler.JDTCompiler$1.findType(JDTCompiler.java:163)
    at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.askForType(LookupEnvironment.java:96)
    at org.eclipse.jdt.internal.compiler.lookup.UnresolvedReferenceBinding.resolve(UnresolvedReferenceBinding.java:49)
    at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.resolveType(BinaryTypeBinding.java:97)
    at org.eclipse.jdt.internal.compiler.lookup.PackageBinding.getTypeOrPackage(PackageBinding.java:167)
    at org.eclipse.jdt.internal.compiler.lookup.Scope.getType(Scope.java:2187)
    at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:974)
    at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1164)
    at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.resolve(CompilationUnitDeclaration.java:366)
    at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:623)
    at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:392)
    at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:429)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:349)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
    at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    at com.google.appengine.tools.development.PrivilegedJspServlet.access$101(PrivilegedJspServlet.java:23)
    at com.google.appengine.tools.development.PrivilegedJspServlet$2.run(PrivilegedJspServlet.java:61)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.google.appengine.tools.development.PrivilegedJspServlet.service(PrivilegedJspServlet.java:58)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:63)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectRequest(DevAppServerModulesFilter.java:366)
    at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectModuleRequest(DevAppServerModulesFilter.java:349)
    at com.google.appengine.tools.development.DevAppServerModulesFilter.doFilter(DevAppServerModulesFilter.java:116)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
    at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:98)
    at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:327)
    at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:126)
    at com.google.appengine.tools.development.StaticFileUtils.serveWelcomeFileAsForward(StaticFileUtils.java:84)
    at com.google.appengine.tools.development.LocalResourceFileServlet.maybeServeWelcomeFile(LocalResourceFileServlet.java:260)
    at com.google.appengine.tools.development.LocalResourceFileServlet.doGet(LocalResourceFileServlet.java:120)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:128)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:63)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:50)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectRequest(DevAppServerModulesFilter.java:366)
    at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectModuleRequest(DevAppServerModulesFilter.java:349)
    at com.google.appengine.tools.development.DevAppServerModulesFilter.doFilter(DevAppServerModulesFilter.java:116)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
    at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:98)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:511)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)

giu 25, 2016 6:04:22 PM com.google.apphosting.utils.jetty.JettyLogger warn
AVVERTENZA: /
org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: 1 in the generated java file
The type java.io.ObjectInputStream cannot be resolved. It is indirectly referenced from required .class files

Stacktrace:
    at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
    at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
    at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:349)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
    at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    at com.google.appengine.tools.development.PrivilegedJspServlet.access$101(PrivilegedJspServlet.java:23)
    at com.google.appengine.tools.development.PrivilegedJspServlet$2.run(PrivilegedJspServlet.java:61)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.google.appengine.tools.development.PrivilegedJspServlet.service(PrivilegedJspServlet.java:58)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:63)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectRequest(DevAppServerModulesFilter.java:366)
    at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectModuleRequest(DevAppServerModulesFilter.java:349)
    at com.google.appengine.tools.development.DevAppServerModulesFilter.doFilter(DevAppServerModulesFilter.java:116)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
    at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:98)
    at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:327)
    at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:126)
    at com.google.appengine.tools.development.StaticFileUtils.serveWelcomeFileAsForward(StaticFileUtils.java:84)
    at com.google.appengine.tools.development.LocalResourceFileServlet.maybeServeWelcomeFile(LocalResourceFileServlet.java:260)
    at com.google.appengine.tools.development.LocalResourceFileServlet.doGet(LocalResourceFileServlet.java:120)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:128)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:63)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:50)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectRequest(DevAppServerModulesFilter.java:366)
    at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectModuleRequest(DevAppServerModulesFilter.java:349)
    at com.google.appengine.tools.development.DevAppServerModulesFilter.doFilter(DevAppServerModulesFilter.java:116)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
    at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:98)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:511)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)

The are 2 differents error, but it seems to be related to each other

 Compilation error
org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException

and

org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: 1 in the generated java file
The type java.io.ObjectInputStream cannot be resolved. It is indirectly referenced from required .class files

I did some research and found the problem related to JDK8 with TomCat7, but with App Engine the dev-server is based on Jetty, so the proposed solution are not usable

Because the main project works (html pages, java servlets, ...) the problem seems to be confined to jsp files

Why am I getting a Psych error when trying to deploy with capistrano?

I am currently setting up capistrano in my Rails 3.2.13 app. I am getting the below error/details (including "control characters are not allowed at line 1 column 1"). I have done some searching for this but do not see anything related to me.

I am using rvm-capistrano and ruby 2.0.0-p195. I recently moved my app-required environment variables into .bashrc.

...      
* 2013-06-10 15:18:32 executing `deploy:assets:update_asset_mtimes'
      * executing "[ -e /home/deployer/apps/super_rad_app/shared/assets/manifest* ] && cat /home/deployer/apps/super_rad_app/shared/assets/manifest* || echo"
        servers: ["107.20.249.163"]
        [107.20.249.163] executing command
        command finished in 6238ms
    *** [deploy:update_code] rolling back
      * executing "rm -rf /home/deployer/apps/super_rad_app/releases/20130610221258; true"
        servers: ["107.20.249.163"]
        [107.20.249.163] executing command
     ** [out :: 107.20.249.163] Using /home/deployer/.rvm/gems/ruby-2.0.0-p195
        command finished in 6623ms
    /home/nate/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/psych.rb:205:in `parse': (<unknown>): control characters are not allowed at line 1 column 1 (Psych::SyntaxError)
        from /home/nate/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/psych.rb:205:in `parse_stream'
        from /home/nate/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/psych.rb:153:in `parse'
        from /home/nate/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/psych.rb:129:in `load'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/recipes/deploy/assets.rb:26:in `parse_manifest'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/configuration/namespaces.rb:191:in `method_missing'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/configuration/namespaces.rb:191:in `method_missing'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/recipes/deploy/assets.rb:93:in `block (3 levels) in load'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/configuration/execution.rb:138:in `instance_eval'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/configuration/execution.rb:138:in `invoke_task_directly'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/configuration/callbacks.rb:25:in `invoke_task_directly_with_callbacks'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/configuration/execution.rb:89:in `execute_task'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/configuration/execution.rb:101:in `find_and_execute_task'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/callback.rb:38:in `call'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/configuration/callbacks.rb:141:in `block in trigger'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/configuration/callbacks.rb:141:in `each'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/configuration/callbacks.rb:141:in `trigger'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/configuration/callbacks.rb:23:in `invoke_task_directly_with_callbacks'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/configuration/execution.rb:89:in `execute_task'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/configuration/execution.rb:101:in `find_and_execute_task'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/callback.rb:38:in `call'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/configuration/callbacks.rb:141:in `block in trigger'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/configuration/callbacks.rb:141:in `each'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/configuration/callbacks.rb:141:in `trigger'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/configuration/callbacks.rb:27:in `invoke_task_directly_with_callbacks'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/configuration/execution.rb:89:in `execute_task'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/configuration/namespaces.rb:191:in `method_missing'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/configuration/namespaces.rb:110:in `block in define_task'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/recipes/deploy.rb:234:in `block (3 levels) in load'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/configuration/execution.rb:56:in `transaction'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/configuration/namespaces.rb:191:in `method_missing'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/recipes/deploy.rb:233:in `block (2 levels) in load'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/configuration/execution.rb:138:in `instance_eval'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/configuration/execution.rb:138:in `invoke_task_directly'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/configuration/callbacks.rb:25:in `invoke_task_directly_with_callbacks'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/configuration/execution.rb:89:in `execute_task'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/configuration/namespaces.rb:191:in `method_missing'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/configuration/namespaces.rb:110:in `block in define_task'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/recipes/deploy.rb:201:in `block (2 levels) in load'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/configuration/execution.rb:138:in `instance_eval'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/configuration/execution.rb:138:in `invoke_task_directly'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/configuration/callbacks.rb:25:in `invoke_task_directly_with_callbacks'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/configuration/execution.rb:89:in `execute_task'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/configuration/execution.rb:101:in `find_and_execute_task'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/cli/execute.rb:46:in `block in execute_requested_actions'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/cli/execute.rb:45:in `each'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/cli/execute.rb:45:in `execute_requested_actions'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/cli/help.rb:19:in `execute_requested_actions_with_help'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/cli/execute.rb:34:in `execute!'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/lib/capistrano/cli/execute.rb:14:in `execute'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/gems/capistrano-2.15.4/bin/cap:4:in `<top (required)>'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/bin/cap:23:in `load'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/bin/cap:23:in `<main>'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/bin/ruby_noexec_wrapper:14:in `eval'
        from /home/nate/.rvm/gems/ruby-2.0.0-p195/bin/ruby_noexec_wrapper:14:in `<main>'

how can I get the action attribute in form tag to work correctly?

I know the tag form has an attribute called action and I know how action works, this is how I used it

<form method="post" action = "registerd.php">
</form>

The registerd.php page also exists as well. Now I am doing some validation in the tag form using php validation, but why does it jump to the registerd.php page without validating the values at first? is there any other solutions to this rather than using the header at the end of php code like :

header("location : registerd.php")

here is the whole code I'm writing Thank you very much in advance

<div id = "content">
            <?php
                $fnameErr = "";
                $lnameErr = "";
                $idErr = "";
                $placeErr = "";
                $dateErr = "";
                $emailErr = "";
                $pswErr = "";
                $file;
                $content = "";
                function test_input($data) {
                    $data = trim($data);
                    $data = stripslashes($data);
                    $data = htmlspecialchars($data);
                    return $data;
                }
                if(isset($_POST['register'])){
                    if(isset($_POST['firstname'])){
                        if(!empty($_POST['firstname'])){
                            if(strlen($_POST['firstname'])>1){
                                if(preg_match("/[a-zA-Z]+/", $_POST['firstname'])==1){
                                    $firstname = test_input($_POST['firstname']);
                                    $content .= "firstname:";
                                    $content .= $firstname; 
                                    $content .= " ";
                                }
                                else{   
                                    $fnameErr = "your first name should only include letters";
                                }
                            }
                            else{
                                $fnameErr = "your first name must be at least 2 characters";
                            }
                        }
                        else{
                            $fnameErr = "enter your first name";
                        }
                    }
                    else{
                        $fnameErr = "enter your first name";
                    }
                    if(isset($_POST['lastname'])){
                        if(!empty($_POST['lastname'])){
                            if(strlen($_POST['lastname'])>3){
                                if(preg_match("/[a-zA-Z]+/", $_POST['lastname'])==1){
                                    $lastname = test_input($_POST['lastname']);
                                    $content .= "lastname:";
                                    $content .= $lastname;
                                    $content .= " ";
                                }
                                else{
                                    $lnameErr = "your last name should only include letters";
                                }
                            }
                            else{
                                $lnameErr = "your last name must be at least 2 characters";
                            }
                        }
                        else{
                            $lnameErr = "enter your last name";
                        }
                    }
                    else{
                        $lnameErr = "enter your last name";
                    }

                    if(isset($_POST['idnum'])){
                        if(!empty($_POST['idnum'])){
                            if(strlen($_POST['idnum'])==10){
                                if(preg_match("/[0-9]{10}/", $_POST['idnum'])==1){
                                    $idnum = test_input($_POST['idnum']);
                                    $content .= "ID_No.:";
                                    $content .= $idnum;
                                    $content .= " ";
                                }
                                else{
                                    $idErr = "your ID number should only include digits";
                                }
                            }
                            else{
                                $idErr = "your ID number must be 10 digits";
                            }
                        }
                        else{
                            $idErr = "enter your ID number";
                        }
                    }
                    else{
                        $idErr = "enter your ID number";
                    }
                    if(isset($_POST['placeOfBirth'])){
                        if(!empty($_POST['placeOfBirth'])){
                            if(strlen($_POST['placeOfBirth'])>2){
                                if(preg_match("/[a-zA-Z]+/", $_POST['placeOfBirth'])==1){
                                    $placeOfBirth = test_input($_POST['placeOfBirth']);
                                    $content .= "placeOfBirth:";
                                    $content .= $placeOfBirth;
                                    $content .= " ";
                                }
                                else{
                                    $placeErr = "your place of birth should only include digits";
                                }
                            }
                            else{
                                $placeErr = "your place of birth must be at least 3 letters";
                            }
                        }
                    }   
                    if(isset($_POST['date'])){
                        if(!empty($_POST['date'])){
                            $date = test_input($_POST['date']);
                            $content .= "date:";
                            $content .= $date;
                            $content .= " ";
                        }
                        else{
                            $dateErr = "enter your date of birth";
                        }
                    }
                    else{
                        $dateErr = "enter your date of birth";
                    }


                    if(isset($_POST['email'])){
                        if(!empty($_POST['email'])){
                                $email = test_input($_POST['email']);
                                $content .= "email:";
                                $content .= $email;
                                $content .= " ";
                        }
                        else{
                            $emailErr = "enter your email";
                        }
                    }
                    else{
                        $emailErr = "enter your email";
                    }

                    if(isset($_POST['password'])){
                        if(!empty($_POST['password'])){
                                if(preg_match("/(?=.*d)(?=.*[a-z])(?=.*[A-Z])(?!.*s).*$/", $_POST['password'])==1){
                                    $password = test_input($_POST['password']);
                                    $content .= "password:";
                                    $content .= $password;
                                    $content .= " ";
                                }
                                else{
                                    $pswErr = "your password should have numbers, uppercase<br/> & lowercase letters";
                                }
                        }
                        else{
                            $pswErr = "enter your password";
                        }
                    }
                    else{
                        $pswErr = "enter your password";
                    }
                    if(file_exists($email.".txt")){
                        echo(
                            "<script>
                                alert('this email already exists!');
                            </script>"
                            );
                        $firstname = $lastname = $idnum = $date = $placeOfBirth = $password = "";
                    }
                    else{
                        $file = fopen($email.".txt","a+") or die("Unable to open file!");
                        fwrite($file, $content);
                        fclose($file);
                        header("location: registered.php");
                    }
                }
            ?>
            <fieldset id = "fieldset">
                <legend><h1 class = "reg" >Register Form</h1></legend>
                <form method="post" action="#" enctype = "multipart/form-data">
                <table class = "table">
                    <tr>
                        <td  class = "labels">
                            <p class = "star">*</p> First Name
                        </td>
                        <td><input class = "inclass" type="text" required="required" placeholder="Please enter your first name" id = "firstname" name="firstname" onclick = "colorBorder(this.id)"/></td>
                    </tr>
                    <td  class = "err">
                        <span>
                                <?php
                                    echo $fnameErr;
                                ?>
                        </span>
                    </td>
                    <tr>
                        <td class = "labels"><p class = "star">*</p> Last Name</td>
                        <td><input class = "inclass" type="text" required="required" placeholder="Please enter your last name" name="lastname" id = "lastname" onclick = "colorBorder(this.id)"/></td>
                    </tr>
                    <td  class = "err">
                        <span>
                                <?php
                                    echo $lnameErr;
                                ?>
                        </span>
                    </td>
                    <tr>
                        <td class = "labels">Gender</td>
                        <td>
                            <input class = "inclass" type="radio" name="gender" value="0" /><p class = "radio" >Male</p>
                            <input class = "inclass" type="radio" name="gender" value="1" /><p class = "radio" >Female</p>
                        </td>
                    </tr>
                    <tr>
                        <td class = "labels"><p class = "star">*</p> ID Number</td>
                        <td><input class = "inclass" type="text" id="idnum" required="required" placeholder="Please enter your ID number" name="idnum" onclick = "colorBorder(this.id)"/></td>
                    </tr>
                    <td  class = "err">
                        <span>
                                <?php
                                    echo $idErr;
                                ?>
                        </span>
                    </td>
                    <tr>
                        <td class = "labels">Place of Birth</td>
                        <td><input class = "inclass" type="text" placeholder="Please enter your place of birth" name="placeOfBirth" id = "place" onclick = "colorBorder(this.id)"/></td>
                    </tr>
                    <td  class = "err">
                        <span>
                                <?php
                                    echo $placeErr;
                                ?>
                        </span>
                    </td>
                    <tr>
                        <td class = "labels"><p class = "star">*</p> Date Of Birth</td>
                        <td><input class = "inclass" type="date" id = "date" name="date"/></td>
                    </tr>
                    <td  class = "err">
                        <span>
                                <?php
                                    echo $dateErr;
                                ?>
                        </span>
                    </td>
                    <tr>
                        <td class = "labels"><p class = "star">*</p> Email</td>
                        <td><input class = "inclass" type="email" required="required" placeholder="Please enter your email" name="email" id = "email" onclick = "colorBorder(this.id)"/></td>
                    </tr>
                    <td  class = "err">
                        <span>
                                <?php
                                    echo $emailErr;
                                ?>
                        </span>
                    </td>
                    <tr>
                        <td class = "labels"><p class = "star">*</p> Passwords</td>
                        <td><input class = "inclass" type="password" required="required" placeholder="Please enter your password" name="password" id = "password" onclick = "colorBorder(this.id)"/></td>
                    </tr>
                    <td  class = "err">
                        <span>
                                <?php
                                    echo $pswErr;
                                ?>
                        </span>
                    </td>
                    <tr>
                        <td><input type="submit" name="register" value="register" class="save"/></td>
                        <td><input type="reset" name = "reset" id = "reset"/></td>
                    </tr>
                </table>
                </form>
            </fieldset>
        </div>

Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'xaDataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xaDataSource' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'xaDataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'driverClassName' of bean class [org.postgresql.xa.PGXADataSource]: Bean property 'driverClassName' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1481)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1226)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1054)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:829)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5068)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5584)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:899)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:875)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1091)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1980)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

<?xml version="1.0" encoding="UTF-8"?>

http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd">

<bean id="requestHandler" class="org.dejach.marketServer.requesthandler.RequestHandler"  init-method="init">
    <property name="factory" ref="marketApiFactory"></property>
</bean>

<bean id="RequestProcessor" class="org.dejach.marketServer.processor.RequestProcessor">
    <property name="handler" ref="requestHandler" />
</bean>

<bean id="marketApiFactory" class="org.dejach.marketServer.processor.MarketApiFactory">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

<bean
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <value>WEB-INF/marketApi.properties</value>
    </property>
    <property name="nullValue" value="@null" />
</bean>

<bean id="properties"
    class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    <property name="location" value="WEB-INF/marketApi.properties" />
</bean>

<bean id="dataSource" class="org.postgresql.xa.PGXADataSource">
    <!-- <property name="pinGlobalTxToPhysicalConnection" value="true" /> -->
    <property name="driverClassName" value="org.postgresql.Driver" />
    <property name="url" value="${jdbcUrl}" />
    <property name="user" value="${username}" />
    <property name="password" value="${password}" />

</bean>

<!-- configure an Atomikos JTA-aware datasource -->
<bean id="xaDataSource" class="com.atomikos.jdbc.AtomikosDataSourceBean"
    init-method="init" destroy-method="close">
    <property name="uniqueResourceName" value="xaDatasource" />
    <property name="xaDataSource" ref="dataSource" />
    <property name="poolSize" value="${poolSize}" />
</bean>

<!-- http://fogbugz.atomikos.com/default.asp?community.6.702.5 -->
<bean id="userTransactionService" class="com.atomikos.icatch.config.UserTransactionServiceImp"
    init-method="init" destroy-method="shutdownForce">
    <constructor-arg>
        <props>
            <prop key="com.atomikos.icatch.log_base_name">${com.atomikos.icatch.log_base_name}</prop>
            <prop key="com.atomikos.icatch.log_base_dir">${com.atomikos.icatch.log_base_dir}</prop>
            <prop key="com.atomikos.icatch.max_timeout">3600000</prop>
        </props>
    </constructor-arg>
</bean>

<bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager"
    init-method="init" destroy-method="close" depends-on="userTransactionService">
    <property name="forceShutdown" value="false" />
    <property name="startupTransactionService" value="true" />
</bean>

<bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.J2eeUserTransaction">
    <property name="transactionTimeout" value="${transactionTimeout}" />
</bean>

<bean id="transactionManager"
    class="org.springframework.transaction.jta.JtaTransactionManager"
    depends-on="atomikosTransactionManager,atomikosUserTransaction">
    <property name="transactionManager" ref="atomikosTransactionManager" />
    <property name="userTransaction" ref="atomikosUserTransaction" />
    <property name="allowCustomIsolationLevels" value="true" />
</bean>

<bean id="jpaVendor"
    class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    <property name="showSql" value="${showSql}" />
    <property name="databasePlatform" value="${databasePlatform}" />
    <property name="generateDdl" value="${generateDdl}" />
    <property name="database" value="${database}" />
</bean>

<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="xaDataSource" />
    <property name="packagesToScan" value="${marketPackage}" />
    <property name="jpaVendorAdapter" ref="jpaVendor" />
    <property name="jpaProperties">
        <props>
            <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
            <prop key="hibernate.dialect">${hibernate.dialect}</prop>
        </props>
    </property>
</bean>


username=postgres
password=$$$$$$$
hibernate.hbm2ddl.auto=create
hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect

# package scan for entities
marketPackage=org.dejach
transactionTimeout=300
showSql=true
#databasePlatform=org.hibernate.dialect.MySQL5InnoDBDialect
databasePlatform=org.hibernate.dialect.PostgreSQLDialect
#database=org.springframework.orm.jpa.vendor.Database.MYSQL
#database=MYSQL
database=POSTGRESQL
generateDdl=false
poolSize=30
#XA datasource
#XADataSource=${mysqlDataSource}
XADataSource=${postgresqlDataSource}
#mysqlDataSource=com.mysql.jdbc.jdbc2.optional.MysqlXADataSource
postgresqlDataSource=org.postgresql.xa.PGXADataSource
H2xadatasource=org.h2.jdbcx.JdbcDataSource
postgresqlUrl = jdbc:postgresql://localhost:5432/ethiopianMarketdb
H2url=jdbc:h2:mem:testdb;MODE=MySQL;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
jdbcUrl=${postgresqlUrl}
blobFieldName=xmlData
#Atomikus properties
#see http://www.atomikos.com/Documentation/JtaProperties                                                                 com.atomikos.icatch.service=com.atomikos.icatch.standalone.UserTransactionServiceFactory


com.atomikos.icatch.console_file_name

#Specifies the console log level. Defaults to WARN. Should be one of: WARN,  INFO or DEBUG.
com.atomikos.icatch.log_base_name=tmlog
com.atomikos.icatch.log_base_dir=target
#com.atomikos.icatch.log_base_dir=/transactionLogs/
#com.atomikos.icatch.tm_unique_name=
com.atomikos.icatch.max_timeout=3600000