While dealing with XStream if you had to create mapper classes and write a parser you would want use a shortcut for solution.
For the next time i will follow the below path
1) Create xsd file for the given xml using IntelliJ Idea
2) Create Jaxb classes for the generated xsd file : http://goo.gl/uOjSAz
3) in the generated you need to put add : @XStreamAlias( "xml_tag_name_for_classs" ) for each class or attribute when you see the @XmlRootElement(name = "xml_tag_name_for_the _item_or_class")
this will remove all undefined field exceptions of the XStream
If you get duplicate field exception add the @XStreamImplicit for the related field in the class
(I use copy paste for this job and if you have selected the third item in the first step you will have only one java file and replacing annotations will be easier. I have tried the other 2 options too for you)
4) in the parser class you need to xstream.processAnnotations(Your_class_name.class); Otherwise XStream will not recognize your annotations..Somethings are stupid still waits commands to do its work :/
In the end Parser class will be something like below
public class DataSharingParser {
public static void main(String[] args) {
try {
XStream xstream = new XStream(new DomDriver());
//xstream.autodetectAnnotations(true);
xstream.processAnnotations(Root.class);
xstream.processAnnotations(Root.Data.class);
xstream.processAnnotations(Root.Error.class);
xstream.processAnnotations(Root.Header.class);
xstream.processAnnotations(Root.Data.CustomerDataShareOptionList.class);
xstream.processAnnotations(Root.Data.CustomerDataShareOptionList.SharingPercentageList.class);
xstream.processAnnotations(Root.Data.CustomerDataShareOptionList.DataShareOptionList.class);
xstream.processAnnotations(Root.Data.CustomerDataShareOptionList.DataShareOptionList.SubscriptionList.class);
xstream.processAnnotations(Root.Error.MsgList.class);
xstream.processAnnotations(Root.Error.MsgList.Msg.class);
xstream.processAnnotations(Root.Error.MsgList.Msg.Valuelist.class);
Path xmlPath = Paths.get("C:\\somewhere_in_there\\src", "your_lovely.xml");
byte[] wikiArray = Files.readAllBytes(xmlPath);
String asString = new String(wikiArray, "UTF-8");
Root root = (Root) xstream.fromXML(asString);
Root.Data data = root.getData();
...more parsing sources goes below...
} catch (IOException e) {
System.out.println(e);
}
System.exit(0);
}
}
Note: You may not trust the xstream.autodetectAnnotations(true); while using XStream-1.4.7 and java 1.7
Wednesday, January 28, 2015
Thursday, October 23, 2014
Send json data from command line example
Command line example for sending JSON data:
$ curl -i -X POST -H "Content-Type:application/json" -d '{ "recordId" : "0000108", "itemOrigin" : "South Korea" }' http://localhost:8080/stocks
or send json request from browser (Postman - A Chrome extension)
#!/bin/bash wget --header='X-Real-IP: 12.12.12.12' --header='User-Agent: Mozilla/5.0 Gecko/2010 Firefox/5' --header='Content-Type: application/json' --header='ganita-token:573652060cf21c7e32f933c8' - 'https://preprod.lojika.net/api/v2/trips/feed?groupResults=true&searchTripId=492d04c9e4b0e8158db4b4b1&timeFilter=SAVED' & wget --header='X-Real-IP: 12.12.12.12' --header='User-Agent: Mozilla/5.0 Gecko/2010 Firefox/5' --header='Content-Type: application/json' --header='ganita-token:58ca8374e4b01bd251a550d1' - 'https://preprod.lojika.net/api/v2/trips/feed?groupResults=true&searchTripId=492d0809e4b0e8158db4bc7a&timeFilter=SAVED' &
Tuesday, October 21, 2014
Missing spring boot maven dependencies,spring boot maven exception,Spring boot maven error
Add this lines to the spring-boot's pom.xml
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.7</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.7</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.1.2</version>
</dependency>
Thursday, October 9, 2014
Spring Examples & Logging Exceptions
Add the lovely missing dependency to pom.xml for the below exception while dealing with Spring Examples
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.9</version>
<scope>runtime</scope>
</dependency>
Regards!
C:\Users\ssunel\Downloads\gs-consuming-rest-master\gs-consuming-rest-master\complete>java -jar target\gs-consuming-rest-0.1.0.jar
Failed to instantiate SLF4J LoggerFactory
Reported exception:
java.lang.NoClassDefFoundError: ch/qos/logback/core/joran/spi/JoranException
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:129)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:108)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:302)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:276)
at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:156)
at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:132)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:274)
at org.springframework.http.client.support.HttpAccessor.<init>(HttpAccessor.java:47)
at org.springframework.http.client.support.InterceptingHttpAccessor.<init>(InterceptingHttpAccessor.java:35)
at org.springframework.web.client.RestTemplate.<init>(RestTemplate.java:154)
at hello.Application.main(Application.java:8)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: ch.qos.logback.core.joran.spi.JoranException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.springframework.boot.loader.LaunchedURLClassLoader.doLoadClass(LaunchedURLClassLoader.java:168)
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:134)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 17 more
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: ch/qos/logback/core/joran/spi/JoranException
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:129)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:108)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:302)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:276)
at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:156)
at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:132)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:274)
at org.springframework.http.client.support.HttpAccessor.<init>(HttpAccessor.java:47)
at org.springframework.http.client.support.InterceptingHttpAccessor.<init>(InterceptingHttpAccessor.java:35)
at org.springframework.web.client.RestTemplate.<init>(RestTemplate.java:154)
at hello.Application.main(Application.java:8)
... 6 more
Caused by: java.lang.ClassNotFoundException: ch.qos.logback.core.joran.spi.JoranException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.springframework.boot.loader.LaunchedURLClassLoader.doLoadClass(LaunchedURLClassLoader.java:168)
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:134)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 17 more
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.9</version>
<scope>runtime</scope>
</dependency>
Regards!
C:\Users\ssunel\Downloads\gs-consuming-rest-master\gs-consuming-rest-master\complete>java -jar target\gs-consuming-rest-0.1.0.jar
Failed to instantiate SLF4J LoggerFactory
Reported exception:
java.lang.NoClassDefFoundError: ch/qos/logback/core/joran/spi/JoranException
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:129)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:108)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:302)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:276)
at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:156)
at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:132)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:274)
at org.springframework.http.client.support.HttpAccessor.<init>(HttpAccessor.java:47)
at org.springframework.http.client.support.InterceptingHttpAccessor.<init>(InterceptingHttpAccessor.java:35)
at org.springframework.web.client.RestTemplate.<init>(RestTemplate.java:154)
at hello.Application.main(Application.java:8)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: ch.qos.logback.core.joran.spi.JoranException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.springframework.boot.loader.LaunchedURLClassLoader.doLoadClass(LaunchedURLClassLoader.java:168)
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:134)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 17 more
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: ch/qos/logback/core/joran/spi/JoranException
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:129)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:108)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:302)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:276)
at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:156)
at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:132)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:274)
at org.springframework.http.client.support.HttpAccessor.<init>(HttpAccessor.java:47)
at org.springframework.http.client.support.InterceptingHttpAccessor.<init>(InterceptingHttpAccessor.java:35)
at org.springframework.web.client.RestTemplate.<init>(RestTemplate.java:154)
at hello.Application.main(Application.java:8)
... 6 more
Caused by: java.lang.ClassNotFoundException: ch.qos.logback.core.joran.spi.JoranException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.springframework.boot.loader.LaunchedURLClassLoader.doLoadClass(LaunchedURLClassLoader.java:168)
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:134)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 17 more
Sunday, December 15, 2013
Connect to remote db with SQLPLUS
sqlplus usernamee/passwordd@'(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=123.123.123.123)(PORT=1521)))(CONNECT_DATA=(SID=MY_REMOTE_DB_SID)))'
sqlplus usernamee/passwordd@'(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=123.123.123.123)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=MY_REMOTE_DB_SERVICE_NAME)))'
sqlplus usernamee/passwordd@'(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=123.123.123.123)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=MY_REMOTE_DB_SERVICE_NAME)))'
Subscribe to:
Posts (Atom)