Showing posts with label how to. Show all posts
Showing posts with label how to. Show all posts

Tuesday, 19 January 2016

Rest Template: Could Not Extract Response – No Suitable HttpMessageConverter Found for Response Type [X] and Content Type

When invoking a web service using RestTemplate:-

restTemplate.getForObject("http://www.server.com/api", Bean[].class));
… the following exception occurs:-

Exception in thread "main" org.springframework.web.client.RestClientException:
Could not extract response: no suitable HttpMessageConverter found for response
type [class [LMyBean;] and content type [application/json;charset=UTF-8]
at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:1110)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:1572)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:1530)
at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:1237)



SOLUTION

If the content type is JSON, add the following dependency:-

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.6.0</version>
</dependency>


Saturday, 21 November 2015

java.lang.UnsupportedClassVersionError: com/typesafe/config/ConfigException : Unsupported major.minor version 52.0

java.lang.UnsupportedClassVersionError: com/typesafe/config/ConfigException : Unsupported major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at com.typesafe.sbt.web.SbtWeb$$anonfun$com$typesafe$sbt$web$SbtWeb$$load$1.apply(SbtWeb.scala:535)
    at com.typesafe.sbt.web.SbtWeb$$anonfun$com$typesafe$sbt$web$SbtWeb$$load$1.apply(SbtWeb.scala:535)
    at scala.Option.fold(Option.scala:157)
    at com.typesafe.sbt.web.SbtWeb$.com$typesafe$sbt$web$SbtWeb$$load(SbtWeb.scala:549)
    at com.typesafe.sbt.web.SbtWeb$$anonfun$globalSettings$1$$anonfun$apply$1.apply(SbtWeb.scala:143)
    at com.typesafe.sbt.web.SbtWeb$$anonfun$globalSettings$1$$anonfun$apply$1.apply(SbtWeb.scala:143)
    at scala.Function1$$anonfun$andThen$1.apply(Function1.scala:55)
    at sbt.Project$.setProject(Project.scala:319)
    at sbt.BuiltinCommands$.doLoadProject(Main.scala:484)
    at sbt.BuiltinCommands$$anonfun$loadProjectImpl$2.apply(Main.scala:475)
    at sbt.BuiltinCommands$$anonfun$loadProjectImpl$2.apply(Main.scala:475)
    at sbt.Command$$anonfun$applyEffect$1$$anonfun$apply$2.apply(Command.scala:58)
    at sbt.Command$$anonfun$applyEffect$1$$anonfun$apply$2.apply(Command.scala:58)
    at sbt.Command$$anonfun$applyEffect$2$$anonfun$apply$3.apply(Command.scala:60)
    at sbt.Command$$anonfun$applyEffect$2$$anonfun$apply$3.apply(Command.scala:60)
    at sbt.Command$.process(Command.scala:92)
    at sbt.MainLoop$$anonfun$1$$anonfun$apply$1.apply(MainLoop.scala:98)
    at sbt.MainLoop$$anonfun$1$$anonfun$apply$1.apply(MainLoop.scala:98)
    at sbt.State$$anon$1.process(State.scala:184)
    at sbt.MainLoop$$anonfun$1.apply(MainLoop.scala:98)
    at sbt.MainLoop$$anonfun$1.apply(MainLoop.scala:98)
    at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
    at sbt.MainLoop$.next(MainLoop.scala:98)
    at sbt.MainLoop$.run(MainLoop.scala:91)
    at sbt.MainLoop$$anonfun$runWithNewLog$1.apply(MainLoop.scala:70)
    at sbt.MainLoop$$anonfun$runWithNewLog$1.apply(MainLoop.scala:65)
    at sbt.Using.apply(Using.scala:24)
    at sbt.MainLoop$.runWithNewLog(MainLoop.scala:65)
    at sbt.MainLoop$.runAndClearLast(MainLoop.scala:48)
    at sbt.MainLoop$.runLoggedLoop(MainLoop.scala:32)
    at sbt.MainLoop$.runLogged(MainLoop.scala:24)
    at sbt.StandardMain$.runManaged(Main.scala:53)
    at sbt.xMain.run(Main.scala:28)
    at xsbt.boot.Launch$$anonfun$run$1.apply(Launch.scala:109)
    at xsbt.boot.Launch$.withContextLoader(Launch.scala:128)
    at xsbt.boot.Launch$.run(Launch.scala:109)
    at xsbt.boot.Launch$$anonfun$apply$1.apply(Launch.scala:35)
    at xsbt.boot.Launch$.launch(Launch.scala:117)
    at xsbt.boot.Launch$.apply(Launch.scala:18)
    at xsbt.boot.Boot$.runImpl(Boot.scala:41)
    at xsbt.boot.Boot$.main(Boot.scala:17)
    at xsbt.boot.Boot.main(Boot.scala)
[error] java.lang.UnsupportedClassVersionError: com/typesafe/config/ConfigException : Unsupported major.minor version 52.0
[error] Use 'last' for the full log.

solution:

Still you are using java7. You can download java8. If you already install java8 make sure it is active.You can change java version using bellow commands.

How To Change Java Version 

 

$ sudo update-alternatives --config java

There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1061      auto mode
  1            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1051      manual mode

Press enter to keep the current choice[*], or type selection number: 2

update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
to provide /usr/bin/java (java) in manual mode
 
 Now you can check you java version using below command

java -version




Friday, 6 November 2015

java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

When i run my project ,I get exception

 ClassNotFoundException : org.springframework.web.context.ContextLoaderListener

java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1858)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1709)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:506)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:488)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:115)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4919)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5517)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1574)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1564)
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)



Solution:    Step 1: 

                    Firstly right click on project and goto build path or  .Click on deployment Assembly now you see screen as  below . click on  add button. 








Step 2: Now click on Java Build Path Entries and press Next Button





Step 3:  Now add Maven Dependencies on click Finish Button.

           


 

Step 4:    Apply maven dependencies.

     




I hope Now you can run your project successfully.





Related Post :


Spring Tutorial


Spring MVC EXample





Friday, 25 September 2015

dpkg was interrupted you must manually run dpkg configure a to correct the problem ubuntu

dpkg was interrupted you must manually run dpkg configure a to correct the problem ubuntu:

 when i run command

   $ sudo apt-get install <package-name>

there comes error 

dpkg was interrupted you must manually run dpkg configure

 

Solution: 

step 1:

run command

sudo dpkg --configure -a

 Step 2:

Now you can run

sudo apt-get install <package-name>


 

Friday, 18 September 2015

Tigase 5.2 and Spark Authentication failed

The messages noted during the login on tigase.0.log are:


18.085 [ConnectionOpenThread]  ConnectionManager$ConnectionListenerImpl.accept()  FINEST: Accept called for service: null@null
2014-04-29 23:46:18.086 [ConnectionOpenThread]  ConnectionManager.serviceStarted()  FINER: [[c2s]] Connection started: null, type: accept, Socket: nullSocket[addr=/192.168.10.40,port=55458,localport=5222], jid: null
2014-04-29 23:46:18.104 [pool-11-thread-4]  ClientConnectionManager.xmppStreamOpened()  FINER: Stream opened: {xmlns:stream=http://etherx.jabber.org/streams, to=192.168.10.40, xmlns=jabber:client, version=1.0}
2014-04-29 23:46:18.106 [pool-11-thread-4]  ConnectionManager.serviceStopped()  FINER:  [[c2s]] Connection stopped: c2s@space01.local/192.168.10.40_5222_192.168.10.40_55458, type: accept, Socket: c2s@space01.local/192.168.10.40_5222_192.168.10.40_55458 Socket[unconnected], jid: null
2014-04-29 23:46:18.108 [pool-11-thread-4]  ClientConnectionManager.xmppStreamClosed()  FINER: Stream closed: c2s@space01.local/192.168.10.40_5222_192.168.10.40_55458
2014-04-29 23:46:42.625 [hostnames]        UserRepoRepository.reload()        CONFIG:   All loaded items: {local=Domain: local, enabled: true, anonym: true, register: true, maxusers: 0, tls: false, s2sSecret: null, domainFilter: ALL}
2014-04-29 23:47:42.625 [hostnames]        UserRepoRepository.reload()        CONFIG:   All loaded items: {local=Domain: local, enabled: true, anonym: true, register: true, maxusers: 0, tls: false, s2sSecret: null, domainFilter: ALL}
2014-04-29 23:48:42.627 [hostnames]        UserRepoRepository.reload()        CONFIG:   All loaded items: {local=Domain: local, enabled: true, anonym: true, register: true, maxusers: 0, tls: false, s2sSecret: null, domainFilter: ALL}
2014-04-29 23:49:42.624 [hostnames]        UserRepoRepository.reload()        CONFIG:   All loaded items: {local=Domain: local, enabled: true, anonym: true, register: true, maxusers: 0, tls: false, s2sSecret: null, domainFilter: ALL}
2014-04-29 23:50:42.625 [hostnames]        UserRepoRepository.reload()        CONFIG:   All loaded items: {local=Domain: local, enabled: true, anonym: true, register: true, maxusers: 0, tls: false, s2sSecret: null, domainFilter: ALL}
2014-04-29 23:51:42.624 [hostnames]        UserRepoRepository.reload()        CONFIG:   All loaded items: {local=Domain: local, enabled: true, anonym: true, register: true, maxusers: 0, tls: false, s2sSecret: null, domainFilter: ALL}
2014-04-29 23:52:42.629 [hostnames]        UserRepoRepository.reload()        CONFIG:   All loaded items: {local=Domain: local, enabled: true, anonym: true, register: true, maxusers: 0, tls: false, s2sSecret: null, domainFilter: ALL}
2014-04-29 23:53:42.625 [hostnames]        UserRepoRepository.reload()        CONFIG:   All loaded items: {local=Domain: local, enabled: true, anonym: true, register: true, maxusers: 0, tls: false, s2sSecret: null, domainFilter: ALL}
2014-04-29 23:54:42.628 [hostnames]        UserRepoRepository.reload()        CONFIG:   All loaded items: {local=Domain: local, enabled: true, anonym: true, register: true, maxusers: 0, tls: false, s2sSecret: null, domainFilter: ALL}
2014-04-29 23:55:42.626 [hostnames]        UserRepoRepository.reload()        CONFIG:   All loaded items: {local=Domain: local, enabled: true, anonym: true, register: true, maxusers: 0, tls: false, s2sSecret: null, domainFilter: ALL}
2014-04-29 23:56:42.629 [hostnames]        UserRepoRepository.reload()        CONFIG:   All loaded items: {local=Domain: local, enabled: true, anonym: true, register: true, maxusers: 0, tls: false, s2sSecret: null, domainFilter: ALL}


Solution :

step 1:

init.propertis files make as

config-type=--gen-config-all
--admins=admin@localhost
--virt-hosts = localhost
--debug=server,xmpp.impl
--cluster-mode=false
--tigase-cache=false
--user-db=pgsql
--user-db-uri=jdbc:postgresql://localhost:5432/tigase?user=tigase

step 2:

Now in spark if there is ssl method is check then uncheck it and try for login now. I follow these steps and i am enable for login.



Friday, 4 September 2015

Ejabberd is not running in that node error

Hi, I'm trying to configure ejabberd without success.
Service is running at Debian Sid and when i type: # ejabberdctl register willian 123456
I get the output:

The node 'ejabberd@willian-notebook' is started with status: started
ejabberd is not running in that node
Check for error messages: ejabberd.log
or other files in that directory.
Error in ejabberd ctl process: 'error' badarg

LOGS
cat /var/log/ejabberd/ejabberd.log

C(<0.192.0>:ejabberd_captcha:331) : The option captcha_cmd is not configured, but some module wants to use the CAPTCHA feature.
=ERROR REPORT==== 2010-04-22 15:04:50 ===
E(<0.467.0>:ejabberd_listener:463) : Failed to open socket:
  {5222,ejabberd_c2s,[inet,{ip,{0,0,0,0}}]}
Reason: IP address and port number already used: 0.0.0.0 5222

    application: ejabberd
    exited: {bad_return,
                {{ejabberd_app,start,[normal,[]]},
                 {{eaddrinuse,{5222,{0,0,0,0},tcp}},
                  {child,undefined,
                      {5222,{0,0,0,0},tcp},
                      {ejabberd_listener,start,
                          [{5222,{0,0,0,0},tcp},
                           ejabberd_c2s,
                           [{access,c2s},
                            {shaper,c2s_shaper},
                            {max_stanza_size,65536},
                            starttls,
                            {certfile,"/etc/ejabberd/ejabberd.pem"}]]},
                      transient,brutal_kill,worker,
                      [ejabberd_listener]}}}}





Solution :



    I have encounter same problem many times. after some times i analysis that

 first run this command

ejabberdctl register admin localhost password

 
then configure ejabberd.cfg file
 
 ,so i remove the ejabberd from linux. and install again but my problem comes again.
 
after try 2-3 times i used purge( see what is difference between purge and remove )command for remove ejabberd and insall again and follow these 
 
tutorial . and it works 
 
 
 

 



Difference between “apt-get remove” or “apt-get purge”

Should I use apt-get remove or apt-get purge


apt-get remove :
        remove is identical to install except that packages are removed
        instead of installed. Note that removing a package leaves its
        configuration files on the system. If a plus sign is appended to the
        package name (with no intervening space), the identified package
        will be installed instead of removed.

apt-get  purge
        purge is identical to remove except that packages are removed and
        purged (any configuration files are deleted too).

I would tend to use purge if you tend to not want to keep any configuration files around.



Related Posts :

Linux Tutorial for Beginners

Importance command for Java developer

How to Empty a file  

Thursday, 3 September 2015

How to Empty a file

 Empty a file using command(terminal)

 Method 1.

$ > test.txt

  empty a file
 
for when you want to flush all content from a file without removing it.

Method 2.

 $  truncate -s0 1.txt





Related Posts :

Linux Tutorial for Beginners

Importance command for Java developer


Catch multiple Java exceptions in the same catch clause

 Can I catch multiple Java exceptions in the same catch clause


In a java application i need throw same custom exception when some exception arise.So i want to handle multiple exceptions in one catch clause.

for example

    try{

          // write java code here

          } catch( IOException e)
             {
      // write code here
        } catch(  SQLException e){

            // write code here
       }

This is possible since Java 7. The syntax for try-catch block is:


try {
  ...
} catch( IOException | SQLException ex ) {
  ...
}
Prior to Java 7 this was no possible. Remember though, if all the exceptions belong to the same class hierarchy, you can catch that (the base exception type). The only other way is to catch each exception in their own catch block.


Related Posts :

 

 Exception Interrupt Program    
Exception handling example 

Multiple Catch Block Example
 
Nested Try Blocks Example
 
Finally Block Example
 
Without catch block example

The Interface And Class Hierarchy For Collection 

 Java ArrayList Examples

Java Linkedlist Examples

Java ArrayList Examples

Java ArrayList Examples


Java Vector Examples

Java HashSet Examples

Java LinkedHashSet Examples

Java TreeSet Examples

Java Hashtable Examples

Java HashMap Examples

Java TreeMap Examples

 



Friday, 28 August 2015

java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.CommunicationException in cassandra

 I had got this exception many times when i had snapshot from cassandra. i try with different ways but there was no solutions. After many try i goto cassandra.yaml file and change rcp_ip address  after that i restart cassandra and it works properly . I  things this problem occur if some ip configure have issue or net connection down.


java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is:
    java.net.ConnectException: Connection refused: connect]
    at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:338)
    at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:248)
    at my.code.RemoteSimonManagerFactoryImpl.createSimonManager(RemoteSimonManagerFactoryImpl.java:24)
    at my.code.Demo.main(DemoAggregation.java:21)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is:
    java.net.ConnectException: Connection refused: connect]
    at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:101)
    at com.sun.jndi.toolkit.url.GenericURLContext.lookup(GenericURLContext.java:185)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at javax.management.remote.rmi.RMIConnector.findRMIServerJNDI(RMIConnector.java:1886)
    at javax.management.remote.rmi.RMIConnector.findRMIServer(RMIConnector.java:1856)
    at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:255)
    ... 9 more
Caused by: java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is:
    java.net.ConnectException: Connection refused: connect
    at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:601)
    at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:198)
    at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:184)
    at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:322)
    at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
    at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:97)


Related Posts

How do I delete all data in a Cassandra column family ?

Wednesday, 26 August 2015

How to delete a non-empty directory in Terminal?

rm -rf myfolder

It deletes all files and folders contained in the myfolder directory.

Add sudo at the beginning of the command :

In case user doesn't have the permission to delete the folder:

sudo rm -rf myfolder

Otherwise, without sudo you will be returned permission denied. And it's a good practice to try not to use -f while deleting a directory:

sudo rm -r myfolder

Note: this is assuming you are already on the same level of the folder you want to delete in terminal, if not:

sudo rm -r /path/to/myfolder
FYI: you can use letters -f, -r, -v:

-f = to ignore non-existent files, never prompt
-r = to remove directories and their contents recursively
-v = to explain what is being done

How do I delete all data in a Cassandra column family ?


We can truncate  all rows from cassandra tables using truncate


Example:

cqlsh: test > TRUNCATE test.users ;



 

How to Convert Java Timestamp to MySQL timestamp vice versa


How to Insert java time in mysql timestamp

java.util.Date date = new Date();


Timestamp timestamp = new Timestamp(date.getTime());

preparedStatement.setTimestamp(1, timestamp);