building an XML service parsing library - java

This is more of a design question I suppose. My company offers a web service to our client that spits data out in a custom xml format. I'd like to build a java library we can offer so our customers can just feed it the url and we will turn it into a set of POJOs built from the response.
I can obviously just create a library that will do some simple xml parsing and building of the POJOs but I'm looking to build something a bit more robust.
My brain is pulling me in a million directions, wondering if anyone has some pointers or some code to poke at. Was thinking about adding an Abdera extension, but it's not really a syndication format that fits the Abdera model. And most of the popular service libraries (twitter, facebook) all rely on standards format parsers, of which our format isn't.

Are you familiar with JAXB?
here is the tutorial: https://jaxb.dev.java.net/tutorial/

Related

Storing all data of a website on Apache Jena as RDF?

I am trying to build a web site build on semantic technologies. It is a CMS, to make it simple lets say it's a blog. I need to be able to do simple CRUD operations. All data will be saved on Jena like blog posts, user informations, blog categories etc.
I have a php system. Here is the path what i am planing to follow:
Use Apache Jena as RDF Store
Use Apache Jena for storing and retrieving the data.
Write a web service on java
Communicate through web service with PHP in JSON format to view, control the data.
My main focus is to build a web site on semantic technologies.
Is there anything wrong with my approach?
If not the main question is when a user made a blog post how will i create a relation with the blog post and user.
With mysql it was just a froeign key. How can i make a relations on Jena between new blog post and existing user?
I can't see anything wrong with your approach. Maybe I would suggest to use JSON-LD as an interchange format, because Jena can read it and write it directly instead of having to create your own converters to RDF (see https://jena.apache.org/documentation/io/).
Regarding the modeling question, I strongly recommend to have a look at the SIOC vocabulary (http://rdfs.org/sioc/spec/), which aims to represent exactly what you are looking for, and more.
Another hardcore solution would be to create the pages of the website in RDF (serialized in RDF/XML), and use XSL to generate the HTML version on demand for each page. It really depends on the size of your website.

How can I easily convert RDF triples to/from an idiomatic Java POJO business object?

I'm a Java developer just getting started with linked data/RDF. I can create triples, put them in a triple store, query them, etc, but it's very awkward. Most of my code is focused on the mechanics of RDF and I'd really like to work with this data in a way that's more idiomatic Java.
How can I convert a POJO to/from RDF triples with Jena without hand-coding everything?
I'd like something that can convert a pile of triples with a defined structure back and forth between a Java POJO and RDF. Like JAXB or and ORM does for XML and a relational database, respectively.
Also, I can't be locked in too closely a particular triple store. I'd really like something that works with the Apache Jena API, since that seems to be the closest to an "industry standard." Also the project architect told me to use that, since the triple stores they're investigating all support it.
Stuff I've looked at:
I try out one library that sort of does what I want, but it made some weird choices and I don't really think it will work for me.
Elmo/Alibaba also sounds promising, but it looks like it only works with the Sesame triple store and it also sounds like it may carry a big giant framework and/or server along with it. Has anyone had any success using it with Jena? I haven't actually tried it out.
There's Empire which is a partial implementation of JPA 1.0 for Object-Triple mapping. It supports Jena, Sesame, and Stardog out of the box, and is pretty easy to add support for other databases.
There's also Pinto which is more akin to Jackson. It's more lightweight than Empire and just does round-tripping to/from RDF & Java beans. It will soon be the engine inside of Empire.
Disclaimer: I'm the author of both.
Another possible tool to look at is OLGA - an Ontology SDK. See https://ecostruxure.github.io/OLGA/ .

Java XML to EDI design

I have a requirement to convert XML to EDI. I have searched a lot for open source free libraries which full fill my need, but could not find any.
So I decided to write my own logic.
Below are my requirements for an application I am going to execute.
Input of the application is: XML data
Output of the application is: EDI (Electronic Data Interchange) representation of the XML data.
I have to apply some business rules on XML data and generate the EDI representation.
Here is my design for the requirement:
The Java POJOs, here onwards these are Source POJOs, to represent the xml data. To load xml data into Source POJOs, I am using JAXB.
The Java POJOs, here onwards these are Target POJOs, to represent the EDI model.
A Java class, here onwards it is XmlToEDIBuilder, to code the business rules
Finally I am using FreeMarker Template to get the desired EDI structure out of Target POJOs.
Is my design looks good? Any suggestions would really help me.
Recently I had a project involving edifact parsing and generation.
I used http://www.smooks.org/ framework for that purpose.
Using the framework mentioned above your application logic steps might be the following:
parse XML to POJO
use precompiled smooks components and your POJO to build your desired edifact version
Smooks components could be extended in case some custom and/or client specific edifact format needed.
Here is the usage example to get you started: https://github.com/lunatech-labs/smooks-examples/blob/master/edifact-in-code-manipulation/src/main/java/example/Main.java

Communication model: C++ and Java

Pals,
I have a requirement to establish a communication channel between C++ and Java layer of my application for the exchange of objects and their properties.
I have got the following options:
XML / SOAP
Postgre SQL
Can you please advice me the Pros & Cons on these. Please share your experiences on the implementation complexities.
Thanks,
Gtk
If the option is between those I would choose XML
Object <=> XML
Java side Simple, C++ side XML Objects
Reason, its simpler for what you want, i.e. pass language objects and not Data Base
Ah, could you specify the communication channel between the apps ?
UPDATE
If you can use JSON I would recommend it instead of XML, here is why.
Another option would be JMS. There are C++ clients out there.
Every time I see XML I think RESTful web service. Both platforms you mentioned have some form of tooling to marshal & unmarshal XML. There are plenty of working examples out in the wild, so a Google/Bing search is good. A nice side-effect is once you have those interfaces built, anything can connect to them.
If you really want to bother with generating a WSDL, then feel free to go the SOAP route. However, speaking with several years of web service integration experience, RESTful is so gosh darned simple compared to anything else.
I would like to suggest a third option : YAML
You have parsing library in YAML for both java and C++. In my experience, it's easier to debug exchange in YAML that in XML (especially if you got full text field or cyclic data structure).
I depends of the kind of message you transfer.
If your message are individual entity that have a short live, I would go for XML, YAML or something similar.
If your message contains information that is going to be used later on and refer to information in previous messages, I would use a database.

How to extract data from a SOAP response in Java?

I have a client set up to send a request to the National Weather Service SOAP server. I am receiving the response that I expect, but I am unsure as to the best way to extract the data from it that I need.
For example, there is a lot of extra data in the XML (in the SOAPBody), but I only want to grab the data for the parameters that I set (such as temperature) to my POJO.
What's the best way to extract this data?
I started out trying to consume SOAP Web Services by hand like you describe - there are better ways.
There are libraries out there that will do all the work for you - no need to parse anything by hand.
Check out JAX-WS. Most Modern IDEs (Certainly Netbeans and Eclipse) also provide point and click support for building web service clients given a WSDL.
The biggest potential problem down this route is if there's no WSDL, or the WSDL is wrong, in which case the tooling I've linked might struggle.
The next safest thing would be to use an XML Parser like JAXP's SAX & DOM etc (they're right there in your JRE) to parse the response and then walk the data structures involved.
Finally you could go the string hacking route using splits or regexes but down that path lies a great deal of potential pain - there's more to the XML spec then nested tags.
It's strongly receommended that you not try and decode SOAP by hand :)
Just to expand on what #Brabster said,
Netbeans has extensive Web Service support, especially using the JAX-WS library.
http://www.netbeans.org/kb/60/websvc/jax-ws.html#Exercise_3_1

Categories