Thursday 31 August 2017

Tomcat - Change tomcat accessing port

           Change tomcat accessing port


  • Goto tomcat>conf folder
  • Edit server.xml
  • Search "Connector port"
  • Replace "8080" by your port number
  • Restart tomcat server.
You are done!.


=====================================

Navigate to /tomcat-root/conf folder. Within you will find the server.xml file.
Open the server.xml in your preferred editor. Search the below similar statement (not exactly same as below will differ)
    <Connector port="8080" protocol="HTTP/1.1" 
           connectionTimeout="20000" 
           redirectPort="8443" />
Going to give the port number to 9090
     <Connector port="9090" protocol="HTTP/1.1" 
           connectionTimeout="20000" 
           redirectPort="8443" />
Save the file and restart the server. Now the tomcat will listen at port 9090


===================================================================

Several ports (8005, 8080, 8009) required by Tomcat Server at localhost are already in use



If you are running on windows try this in the command line prompt:
netstat -ano
This will show all ports in use and the process id PID # of the process that is using that port. Then Ctrl+Alt+Del and open Task Manager to see which process is that.
You can then choose either to close/stop it or configure your server to use another port. To check if the new choosen port (let's say 8010) is available do this:
netstat -ano | grep 8010
If it does not return any lines then you are fine.
To change the port go to the Server view, open server.xml and change the port there. Mine has this entry:
Connector port="8010" protocol="AJP/1.3" redirectPort="8443"

========================================================================

Port 80 is being used by SYSTEM (PID 4), what is that?


check for services running on 

netstat -o -n -a |findstr 0.0.:8080

--------------------------------
Also, try stopping "SQL Server Reporting Services (MSSQLSERVER)", that apparently defaults to 80. I did that and port 80 freed up. PID identified the culprit as "System", but apparently that System can mean multiple things.
--------------------------------------------------------

There are many services, which can listen port 80 on windows.
Luckily you can detect and stop them all running simple console command:
NET stop HTTP

Disable Unnecessary System Services Locally

  1. Open the Computer Management interface.
  2. In the console tree, expand Services and Applications and select Services.
  3. From the right-hand pane, select a service to disable. Right-click on the selected service and select Properties.
  4. The Properties dialog box for the selected services will appear. From the Startup type: drop down menu, select Disabled.
    Dd277425.w2kab190(en-us,TechNet.10).gif
  5. Under Service status: click on the Stop button.
  6. Click the OK button.

===================================================


  1. Select “Default Web Site” from the left tree in IIS manager.
  2. Click Bindings from the right sidebar to open a dialog box.
  3. Select “http” record from the grid and hit Edit.
  4. Enter your choice of port number in “Port” Text box and hit OK.





==============================

Tuesday 29 August 2017

C++ Basics- oops concepts

                                  c++


   To support the principles of object-oriented programming, all OOP languages
have three traits in common:

1) encapsulation,
2) polymorphism,
3) inheritance.



1)Encapsulation :=>

 Encapsulation is the mechanism that binds together code and the data it manipulates, and keeps both safe from outside interference and misuse.


  => When code and data are linked together in this fashion, an object is
created


=> Each  time you define a new type of object, you are creating a new data type


2) Polymorphism=>

    which is characterized by the phrase "one interface, multiple methods."

   In simple terms, polymorphism is the  attribute that allows one interface to control access to a general class of actions.

=>       Polymorphism helps reduce complexity by allowing the same interface to be used to access a general class of actions. It is the compiler's job to select the specific action
(i.e., method)


3)  Inheritance  =>


Inheritance is the process by which one object can acquire the properties of another object.
This is important because it supports the concept of classification.






********************************************************************

iostream


=>  there is no .h extension to the iostream. The reason is that <iostream>      is one of the new-style headers defined by Standard C++.

=>  New-style headers do not use the .h extension.

******************************************************
using namespace std;


=>    This tells the compiler to use the std namespace.

=>    Namespaces are a recent addition  to C++.

=>   A namespace creates a declarative region in which various program elements
can be placed.

=>  Namespaces help in the organization of large programs.


=>   The using  statement informs the compiler that you want to use the std namespace.

=> This is the  namespace in which the entire Standard C++ library is declared. By using the std  namespace you simplify access to the standard library.


**************************************************************************
Function overloading =>



 One way that C++ achieves polymorphism is through the use of function overloading.

In C++, two or more functions can share the same name as long as their parameter
declarations are different. In this situation, the functions that share the same name are said to be overloaded, and the process is referred to as function overloading.


************************************************************


Operator Overloading  =>

in C++, it is possible to use the << and >> operators to perform console I/O operations.

They can perform these extra operations because in the <iostream> header, these
operators are overloaded.

  When an operator is overloaded, it takes on an additional meaning relative to a certain class. However, it still retains all of its old meanings.



******************************************************************88

Constructors and Destructors



=>  C++ allows objects to initialize themselves when they are created.

=>  This automatic initialization is performed through the use of a constructor function.


=> A constructor function is a special function that is a member of a class and has the same name as that class.


=> most constructor functions will not output or input anything. They will simply perform various initializations.




 Destructor::::::




=>    An object's constructor is automatically called when the object is created. This means that it is called when the object's declaration is executed.



===>  The complement of the constructor is the destructor

=>   in many circumstances, an object will need to perform some action or actions when it is destroyed.


=> Local objects are created when their block is entered, and destroyed when the block is left. Global
objects are destroyed when the program terminates.

=> When an object is destroyed, its destructor (if it has one) is automatically called.


=>
                                                 . There are many reasons why a
destructor function may be needed. For example, an object may need to deallocate
memory that it had previously allocated or it may need to close a file that it had
opened. In C++, it is the destructor function that handles deactivation events. The
destructor has the same name as the constructor, but it is preceded by a ~.



************************************************************************

Linux Basics

UNIX : unix operating system was developed around 1960, at AT & T labs by dennis      ritch, after few years it made commerical

    ==>  then Richard stallmen decided to develop a new open source operating
        system, he is developer from MIT. he started a project GNU . which
        similar to whatever the facilites that offering by the UNIX os , they
       made all the required modules except the kernal,

 



LINUX  :   LInus Torvaldo , student form  elisinky university (finland) ,
          started a hobby of creating his own kernel version, In 25 Aug, 1991,
        he developed a terminal emulator (based on  Minix,it's just like unix
        terminal ,which used in universities for explanation purpose. ) he
         followed the architecture of the minix but he didn't used any code from      that) then  he posted a email in the minix user groups for feedback and
      suggesition, he annouced it's name as  "freax" => free, freak, x
      released 0.99 version of kernal , then some named it as LINUX kernal, then      Richard stallman used this kernal to complete his remaining project.
      then finally developed a free Open source Operating system under the
     (GPL) General Public License.... means anyone can use this freely ,
     and distribute to the other,modify also.


OS =>
        it's complicated/sophasticated a software ,
        which manages all the softwares and hardware resources.
   
    =>software which manages all the other resources...


Kernal ==>
           user space can't directly communicate with the hardware devices,
           only kernal have the privillage to communicate with the hardware
           components.
           we request the kernal with system calls..  kernal sends interrupts to           the hardware components to communicate .

       ==>  kernal is core of os.


shell==>

        ->   it is command interpretor
        ->   a software/program which acts as interface b/w the user and the
             kernel.


Library:=>
          It's binary file , a file which contains all the definitions of the
            functions , they are precompiled.
       
         => library files are created from the binary files.

            2 types of library files

     1)  Static :
                     extension:   libc.a


     2)  Dynamic :

                    extensions:     libc.so
                                  & libc.dll

  =>static linking:
                   
                      The address of the called function known to the main
     function at the time of compile time .this kind of linking is called
    static linking.

                    =>with static linking file size will be more becuase
                   it doesn't contain any seperate dll files so all files
                  are linked as a group so size of excutable file will be more.

                   => but one useful thing with static linking is ..executable                   files are portable (no dependency).

                 =>  statically linking will consume more memory. that's why
                 developers go for dynamic linking.

  =>Dynamic  linking:

                     The address of the called function known to the main
     function at the time of Run time .this kind of linking is called
    dynamic  linking.

                   => default linking is dynamic linking.

                   => in dynamic linking executable file size will be reduced


   ex:  printf is linked to the main function in dynamic linking.

=>   printf present in both  static libray & dynamic library
               
                   i)  libc.so
                   ii)  libc.a



==> Load time linking:
                      when executable file brought into memory for processing
                    at that time all the library files(a.out depends on)
                    are brought into memory



==> Run time linking :

                      link if necessary, otherwise don't link.


Commands: =>


$ cc -c 1.c    =>  compilation without linking

$ nm 1.o      =>  to know whether the fn defined or undefined

$ ldd a.out    =>  if it is dynamically linked then it
                   displays used shared library functions.

                    =>  list the libraries of a.out which depends on.

$ cc -static 1.o 2.o  =>  to link statically

$ file a.out   =>     to know whether it is dynamically linked or
                                            Statically  linked


**********   creation of library *********************************

ex:


        $ cc -c -fpic sum.c   (compilation without linking creates .o objective                                file)
        $ cc -c -fpic mul.c


        $ cc -shared -o libDynamic.so sum.o mul.o
     
        $ ar rcs libstatic.a  sum.o mul.o




  ********************    Process & Process management: **************

Process: =>
             application under execution is called process.


          ==> actually cpu excutes one process at a time.
         

       
Job concurrency/ Multi processing : =>


             => excuting multiple process at simultaneously/concurrently                         is called  multi processing.

             ==> this type of management is called cpu management.


cpu management =>

             =>  it's one of the resource manager.

             =>   execute all the process that are demanding the cpu in
                 efficient manner is called cpu management.

 efficient way means::
       
               ->  fair cpu sharing
               ->  response time
               ->  starvation       : demanding cpu but cpu not given
                                    :-> less starvation time is better
                                    -> we can minimize by Round dropping manner


               ->  throuput
               ->  turn around time : time gap b/w process loading and
                                      release(terminating).
               ->  wait time should be better



states of process::=>

           
   -> Ready/Runnable : the job needs nothing but cpu

   -> Delay/sleep    : in delay state it's not demand the cpu for the given
                       amount of delay time.

   -> suspended      : the job is interrupted from excution by interrupts, will
                       excute if resumed.

   -> wait/pending   :  the job is in waiting state
                     
                       -> the job is pending for i/o operations
                       -> event completion


***********   PCB (process control block) ************************


-> those many process/jobs, those many pcb's present

-> life of pcb  is equal to life of job.

->  cpu manager creates pcb's

-> when job is exited then pcb is released.

-> for each process there is unique process id present.

-> the switching of pcb is called   -> pcb switching
                                   
                                    -> process switching
                                   
                                    -> context switching



************************   bound ************************************

cpu bound ==>

             if a process in it's life time ,  if it present most of the time

            ready queue is called cpu bound.



i/o bound ==>
               if a process in it's life time, if it not demand cpu then

                it is called i/o bound.




->  for process manager  i/o bounds jobs are better....



************************************************************************


  prototypes  =>


1.         pid_t  fork(void);

2.         pid_t wait(int *status);

3.         pid_t waitpid(pid_t pid,int *status , int options);

4.         int  kill(pid_t pid,int sig_num);

5.        sighandler_t  signal(int signum, sighandler_t handler);

6.         int system(const char *command);

7.        int  getrlimit( int resource, struct rlimit *rlim);

8.         int setrlimit(int resource, const struct rlimit *rlim);

9.         int execl( const char *path, const char *arg,...);

10         int execlp(const char *path, const char *arg,...);

11     int execle(const char *path , const char *arg,... , char *const envp[]);

12        int  execv(const char *path , char *const argv[]);

13         int execvp(const char *file , char *const argv[]);

14    int  execve(const char *filename , char *const argv[],char *const envp[]);








Web Services - SOAP & REST


 A Web Service is an application deployed on a machine (server). 

 Web services accept incoming requests from client and send response to client in either plain text, JSON or XML format.

web services is they are language independent. So a web service written in Python can be requested from a client written in Java, C#, Ruby etc.

Web services are classified into two categories:
  • SOAP – In SOAP-based web services both client and service transfer SOAP messages to communicate.
  • REST – While in REST-style services both client and service usually transfer raw XML to communicate.
Java provides API for creating both SOAP and REST-style web services
JAX-WS – JAX-WS (Java API for XML Web Services) is a Java API for creating both SOAP and REST-style web services. There is a common misconception that JAX-WS is only for SOAP-based services, which is not true. Using JAX-WS you can create both SOAP and REST-style services
JAX-RS – JAX-RS (Java API for RESTful Web Services) is a Java API to write RESTful web services easily

===================================================================
SOAP (Simple Object Access Protocol
REST (Representation State Transfer)

What is payload?
When data is sent over the Internet, each unit transmitted includes both header information and the actual data being sent. The header identifies the source and destination of the packet, while the actual data is referred to as the payload. In general, payload is the data that is carried on behalf of an application and the data received by the destination system.
<name>Arin</name>
or
"name": "Arin"


sending data over the network in Json format is cheaper than sending it in Xml format in terms of payload.

Here is the first benefit or advantages of REST over SOAP.

SOAP only support XML, but REST supports different format like text, JSON, XML etc


SOAP supports only XML, but it also has its own advantages.






  1. SOAP is a protocol. REST is an architectural style.
  2. SOAP stands for Simple Object Access Protocol. REST stands for REpresentational State Transfer.
  3. SOAP can't use REST because it is a protocol. REST can use SOAP web services because it is a concept and can use any protocol like HTTP, SOAP.
  4. SOAP uses services interfaces to expose the business logic. REST uses URI to expose business logic.
  5. In Java JAX-WS is the java API for SOAP web services. In Java JAX-RS is the java API for RESTful web services.
  6. SOAP defines standards to be strictly followed. REST does not define too much standards like SOAP.
  7. SOAP requires more bandwidth and resource than REST. REST requires less bandwidth and resource than SOAP.
  8. SOAP defines its own security. RESTful web services inherits security measures from the underlying transport.
  9. SOAP permits XML data format only. REST permits different data format such as Plain text, HTML, XML, JSON etc.
  10. SOAP is less preferred than REST. REST more preferred than SOAP.
=====================================================================

Why Rest?
  • Since REST uses standard HTTP it is much simpler in just about ever way.
  • REST permits many different data formats where as SOAP only permits XML.
  • REST allows better support for browser clients due to it’s support for JSON.
  • REST has better performance and scalability. REST reads can be cached, SOAP based reads cannot be cached.
  • If security is not a major concern and we have limited resources. Or we want to create an API that will be easily used by other developers publicly then we should go with REST web services.
  • If we need Stateless CRUD operations.
Why SOAP?
  • WS-Security: While SOAP supports SSL (just like REST) it also supports WS-Security which adds some enterprise security features.
  • WS-AtomicTransaction: Need ACID Transactions over a service, you’re going to need SOAP.
  • WS-ReliableMessaging: If your application needs Asynchronous processing and a guaranteed level of reliability and security. Rest doesn’t have a standard messaging system and expects clients to deal with communication failures by retrying.
  • SOAP is highly secure as it defines its own security.
  • If the security is a major concern and the resources are not limited then we should use SOAP web services. Like if we are creating a web service for banking related work then we should go with SOAP as here high security is needed.
enter image description here

======================================================================

REST fundamentals
  • Everything in REST is considered as a resource.
  • Every resource is identified by an URI.
  • Uses uniform interfaces. Resources are handled uing POST, GET, PUT, DELETE operations which are similar to Create, Read, update and Delete(CRUD) operations.
  • Be stateless. Every request is an independent request. Each request from client to server must contain all the information necessary to understand the request.
  • Communications are done via representations. E.g. XML, JSON RESTful Web Services A RESTFul web services are based on HTTP methods and the concept of REST. A RESTFul web service typically defines the base URI for the services, the supported MIME-types (XML, text, JSON, user-defined, ...) and the set of operations (POST, GET, PUT, DELETE) which are supported.
SOAP fundamentals
  • WSDL defines contract between client and service and is static by its nature.
  • SOAP builds an XML based protocol on top of HTTP or sometimes TCP/IP.
  • SOAP describes functions, and types of data.
  • SOAP is a successor of XML-RPC and is very similar, but describes a standard way to communicate.
  • Several programming languages have native support for SOAP, you typically feed it a web service URL and you can call its web service functions without the need of specific code.
  • Binary data that is sent must be encoded first into a format such as base64 encoded.
  • Has several protocols and technologies relating to it: WSDL, XSDs, SOAP, WS-Addressing.
SOAP vs REST?
One of the major benefits of SOAP is that you have a WSDL service description. You can pretty much discover the service automatically and generate a useable client proxy from that service description (generate the service calls, the necessary data types for the methods and so forth). Note that with version 2.0, WSDL supports all HTTP verbs and can be used to document RESTful services as well, but there is a less verbose alternative in WADL (Web Application Description Language) for that purpose.
With RESTful services, message security is provided by the transport protocol (HTTPS), and is point-to-point only. It doesn’t have a standard messaging system and expects clients to deal with communication failures by retrying. SOAP has successful/retry logic built in and provides end-to-end reliability even through SOAP intermediaries.
One of the major benefits of RESTful API is that it is flexible for data representation, for example you could serialize your data in either XML or JSON format. RESTful APIs are cleaner or easier to understand because they add an element of using standardised URIs and gives importance to HTTP verb used (i.e. GET, POST, PUT and DELETE).
RESTful services are also lightweight, that is they don’t have a lot of extra xml markup. To invoke RESTful API all you need is a browser or HTTP stack and pretty much every device or machine connected to a network has that.
Advantages of REST
  • Since REST uses standard HTTP it is much simpler in just about ever way. Creating clients, developing APIs, the documentation is much easier to understand and there aren’t very many things that REST doesn’t do easier/better than SOAP.
  • REST permits many different data formats where as SOAP only permits XML. While this may seem like it adds complexity to REST because you need to handle multiple formats, in my experience it has actually been quite beneficial. JSON usually is a better fit for data and parses much faster. REST allows better support for browser clients due to it’s support for JSON.
  • REST has better performance and scalability. REST reads can be cached, SOAP based reads cannot be cached.
  • No expensive tools require to interact with the Web service
  • Smaller learning curve
  • Efficient (SOAP uses XML for all messages, REST can use smaller message formats)
  • Fast (no extensive processing required)
  • Closer to other Web technologies in design philosophy
Advantages of SOAP
  • WS-Security : While SOAP supports SSL (just like REST) it also supports WS-Security which adds some enterprise security features. Supports identity through intermediaries, not just point to point (SSL). It also provides a standard implementation of data integrity and data privacy. Calling it “Enterprise” isn’t to say it’s more secure, it simply supports some security tools that typical internet services have no need for, in fact they are really only needed in a few “enterprise” scenarios.
  • WS-AtomicTransaction : Need ACID Transactions over a service, you’re going to need SOAP. While REST supports transactions, it isn’t as comprehensive and isn’t ACID compliant. Fortunately ACID transactions almost never make sense over the internet. REST is limited by HTTP itself which can’t provide two-phase commit across distributed transactional resources, but SOAP can. Internet apps generally don’t need this level of transactional reliability, enterprise apps sometimes do.
  • WS-ReliableMessaging : Rest doesn’t have a standard messaging system and expects clients to deal with communication failures by retrying. SOAP has successful/retry logic built in and provides end-to-end reliability even through SOAP intermediaries.
  • Language, platform, and transport independent (REST requires use of HTTP)
  • Works well in distributed enterprise environments (REST assumes direct point-to-point communication)
  • Standardized
  • Provides significant pre-build extensibility in the form of the WS standards
  • Built-in error handling
  • Automation when used with certain language products
Where to use REST
areas where REST works really well for are:
  • Limited bandwidth and resources: remember the return structure is really in any format (developer defined). Plus, any browser can be used because the REST approach uses the standard GET, PUT, POST, and DELETE verbs. Again, remember that REST can also use the XMLHttpRequest object that most modern browsers support today, which adds an extra bonus of AJAX.
  • Totally stateless operations: if an operation needs to be continued, then REST is not the best approach and SOAP may fit it better. However, if you need stateless CRUD (Create, Read, Update, and Delete) operations, then REST is it.
  • Caching situations: if the information can be cached because of the totally stateless operation of the REST approach, this is perfect.
Where to use SOAP
areas where SOAP works as a great solutionare:
  • Asynchronous processing and invocation: if your application needs a guaranteed level of reliability and security then SOAP 1.2 offers additional standards to ensure this type of operation. Things like WSRM – WS-Reliable Messaging.
  • Formal contracts: if both sides (provider and consumer) have to agree on the exchange format then SOAP 1.2 gives the rigid specifications for this type of interaction.
  • Stateful operations: if the application needs contextual information and conversational state management then SOAP 1.2 has the additional specification in the WS structure to support those things (Security, Transactions, Coordination, etc). Comparatively, the REST approach would make the developers build this custom plumbing.

=====================================================================

SOAP
  1. SOAP is a protocol.
  2. SOAP stands for Simple Object Access Protocol.
  3. SOAP can't use REST because it is a protocol.
  4. SOAP uses services interfaces to expose the business logic.
  5. SOAP defines standards to be strictly followed.
  6. SOAP requires more bandwidth and resource than REST.
  7. SOAP defines its own security.
  8. SOAP permits XML data format only.
  9. SOAP is less preferred than REST.
REST
  1. REST is an architectural style.
  2. REST stands for Representational State Transfer.
  3. REST can use SOAP web services because it is a concept and can use any protocol like HTTP, SOAP.
  4. REST uses URI to expose business logic.
  5. REST does not define too much standards like SOAP.
  6. REST requires less bandwidth and resource than SOAP.
  7. RESTful web services inherits security measures from the underlying transport.
  8. REST permits different data format such as Plain text, HTML, XML, JSON etc.
  9. REST more preferred than SOAP.
==========================================================================