JAX-RS standard solution for serialize arrays of one element - jax-rs

Like it is described in jersey documentation, jersey use as default MAPPED notation, so I have a serialization problem with lists of one element.
http://jersey.java.net/nonav/documentation/latest/json.html#d4e949
Until now, I resolved the problem in the client side, but now, I don't have access to client code.
I need serialize arrays in NATURAL notation, but i can't make me code dependent of jersey. I need a solution according to JAX-RS standards, a cross platform solution.

In JAX-RS, don't specify JSON provider, so i must implement my own provider if i want a portable solution.

Related

Imposing limits on Wsdl created by Apache CXF

I'm currently working on a project to develop some web services, and we've chosen Apache CXF as the technology of choice. We're working with a contract-last methodology (We're coding our service and allowing CXF to generate the wsdl for us.) While we have been able to use Java-WS annotations to set certain fields as required, we have been unable to figure out how to impose character limits on strings elements in the wsdl. While it isn't a huge deal (we're fairly close with the vendor we're working with, so a casual agreement to not let the requests coming to us exceed said length is enough for now), we are curious is there is a way to do this.
Is there a way to with CFX to impose something like a 20 character limit on an input string?
This isn't something that JAXB provides. However, there is a project that has forked the jaxb-ri that adds support for this:
https://github.com/whummer/jaxb-facets
If you don't need to have the facet reflected in the WSDL, you could just do the validation as part of the setter method of the JAXB beans.
setName(String s) {
if (s.length() > 20) thrown new Exception(....);
name = s;
}
There are also some events that the JAXB bean could respond to after unmarshalling where you could validate things. See the afterUnmarshall descriptions in the javadoc: http://docs.oracle.com/javase/6/docs/api/javax/xml/bind/Unmarshaller.html
When you do a bottom up approach to webservice(i.e. impl first, WSDL later), you are at the webservice engine's mercy wrt to thew restrictions on the datatypes.
But if you go thru the top-down approach(WSDL first, impl later), you can eliminate those kind of problems, but would require you to know how to develop WSDLs and apply facets (restrictions).
Fortunately, CXF supports both, and you can give a try to wsdl2java.
Also remember, adding a facet doesn't mean that it will be enforced by the webservice engine. Most of the engines just ignore it, though I am not sure about CXF.

protobuf-net and wcf web apis

I haven't used wcf web api yet. Glenn Block's demo at MIX11 looked real nice so I will certainly dig into that.
In the meantime, I'm wondering how it could be used together with protocol buffers (mainly for performance reasons). The idea would be to put in place an application/x-protobuf MIME type (or equivalent).
I guess we could :
get rid of soap based attributes
define a custom media type processor that serializes / deserializes messages with protobuf-net
Do you think that would work ?
Speaking as someone who is rather familiar with protobuf-net, I honestly haven't tried that approach, but glancing at that blog entry it looks encouraging. If it works, I'd be happy to add support to the core library (at least, the 3.0 version).
I realise this isn't really an answer, but I can't see a reason why it shouldn't, given thaw it works for BSON.

GWT Data Serialization

I'm looking for the algorithm that Google's Web Toolkit uses to serialize data posted to the server during an AJAX request. I'm looking to duplicate it in another language so that I can tie in another of my projects with a GWT project.
Any help is much appreciated!
The GWT-RPC serialization is heavily tied to Java. It even sends Java class names over the wire.
I suggest you use something like JSON to communicate with the server. This way, you can use any programming language with the GWT server.
Update: There are no definitive references to the GWT-RPC format, and a mailing list post explains that decision:
The GWT RPC format is intentionally opaque JSON. This makes it
somewhere between difficult and impossible to add a non-GWT agent to
the RPC discussion. There isn't really a nice work-around for
creating a non-Java server-side implementation but, because your
RemoteServiceServlet implementation just has to implement your
synchronous RPC interface, it's quite possible for non-GWT clients to
talk to the same server-side business logic, just without using the
RPC protocol.
and the little detail which surfaced was
The wire format is plain text. It's actually JSON. It's just
unreadable JSON because the assumption is that both the producing and
consuming code is auto-generated and can make all kinds of assumptions
about the structure of the text.
I've written a design document explaining the GWT-RPC wire format. Hopefully you'll find it useful.

Xstream/HTTP service

We run multiple websites which use the same rich functional backend running as a library. The backend is comprised of multiple components with a lot of objects shared between them. Now, we need to separate a stateless rule execution component into a different container for security reasons. It would be great if I could have access to all the backend objects seamlessly in the rules component (rather than defining a new interface and objects/adapters).
I would like to use a RPC mechanism that will seamlessly support passing our java pojos (some of them are hibernate beans) over the wire. Webservices like JAXB, Axis etc. are needing quite a bit of boiler plate and configuration for each object. Whereas those using Java serialization seem straightforward but I am concerned about backward/forward compatibility issues.
We are using Xstream for serializing our objects into persistence store and happy so far. But none of the popular rpc/webservice framework seem use xstream for serialization. Is it ok to use xstream and send my objects over HTTP using my custom implementation? OR will java serialization just work OR are there better alternatives?
Advance thanks for your advise.
The good thing with standard Java serialization is that it produces binary stream which is quite a bit more space- and bandwidth-efficient than any of these XML serialization mechanisms. But as you wrote, XML can be more back/forward compatibility friendly, and it's easier to parse and modify by hand and/or by scripts, if need arises. It's a trade-off; if you need long-time storage, then it's advisable to avoid plain serialization.
I'm a happy XStream user. Zero problems so far.

How can we transparently serialize Dataset ExtendedProperties in WCF?

We are migrating from Remoting to WCF a very big application that makes intensive use of DataSets. We use the ExtendedProperties of the DataSets' tables to store a graph of objects containing special information we need at client side.
In our Remoting implementation we did add to the channel stack a client and a server channels to check if the message contained a dataset and use a xml serializer to be able to send ExtendedProperties through the wire (you may know that the dataset serializer does a ToString() of the elements found into the ExtendedProperties).
We did it that way so it was transparent to the business rules and UI developers.
What should we override or implement in WCF to be able to manage the DataSet before it is serialized to xml/soap by the wcf channel? Is it possible?
Note: I already know we have to avoid using datasets in wcf, but we have more than 200 forms using datasets and changing them all is not a option right now.
Many thanks!
I wonder if you can't swap the serializer by adding a behaviour attribute at each end... given an XmlReader/XmlWriter, the approach of:
dataset.WriteXml(xmlWriter, XmlWriteMode.WriteSchema);
and
dataset.ReadXml(xmlReader, XmlReadMode.ReadSchema);
seems to work (i.e. extended properties are respected), so you should be able to write a behaviour that detects DataSet and swaps to a custom serializer - like this (attribute | behaviour | serializer) - but probably simpler. I can take a look later if that isn't enough to get started...
You might consider switching to NetDataContractSerializer. It is capable to serialize all serializable .NET types, including even the ones supporting ISerializable, and it fully handles cycles in such graphs.
But this will work only if you're going to consume your WCF service by a .NET client.
First of all thanks for your answers. I've finally did find how to change the serializer with a mix of Marc's answer and an entry of Nicholas Allen's Indigo Blog.
Thank you.