Ok, answer to my own mail:
I managed to do what I wanted by overriding readType() in Hessian2Input
on the server and readType() in CHessianInput (actually I changed that
implementation because we use a vendor branch for C#).
In doing so I had to remove the concrete instance from the hessian
servlet, exposing it using a public parameter for Hessian2Input. In my
own sub-classed servlet I gave it a new MappedHessianInput class with
the overidden readType(). Both on the client and server this method
works with a HessianTypeMapper interface that have only one method:
string getMappedType(string fromType). If a type-mapper isn't provided,
it will fallback on default from the protocol.
On the C# side I hade to change the API pretty much to be able to get
the mapping interface all the way down to CHessianInput. Neither the
Java servlet or the C# client is very friendly to extensions.
My mapping (client-side is most interesting) now works something like this:
internal class JavaHessianTypeMapper : IHessianTypeMapper
{
public string getMappedType(string type)
{
type = type.Replace("com.xyz.model.Person",
"Xyz.Model.CPerson");
type = type.Replace("com.xyz.model.", "Xyz.Model.");
type = type.Replace("com.xyz.core.Observer",
"Xyz.Core.IObserver");
type = type.Replace("com.xyz.core", "Xyz.Core.");
return type;
}
}
The server is the same, but reversed.
This then works for all Collections, Lists, etc without any other
intervention.
Another obvious way to fix this would be to implement true generics
support on both sides but I couldn't figure out how to do it.
Cheers,
/Niclas
Niclas Olofsson skrev:
> Hi,
>
> I'm looking through the code trying to figure out if it is at all
> possible to do custom type-name mapping. Can't find any way to do it
> right now.
>
> What I'm trying to accomplish is to be able to map from (in this case)
> .NET style namespaces and type standards (I/C type-names and camel-cased
> namespaces) to Java style (no casing on namespaces and no I/C prefix on
> types). I would settle for namespace mappings as a starter since that is
> most important, but if implemented it would be pretty natural to do full
> custom type-mapping. Example:
>
> com.zyx.AnObserver -> Xyz.IAnObserver
>
> ..and of course the other way around.
>
> The goal is for the user to be able to work with types in a platform
> dependent fashion.
>
> I hacked the C# hessian implementation to ignore casing when it resolves
> the types (since the type-loader in C# provide this functionallity) but
> that is not possible in Java. Also it's not exactly what I'm looking
> for, just a brutal workaround. Hence I would like to do an
> implementation of this mapping if it doesn't exist.
>
> Cheers,
> /Niclas
> PS! I'd be happy to provide this mapping if it doesn't exist. For Java
> and C#. However, I can't get a hold on the C# implementers (and can't
> register to their forums too) so if they see this please send me a mail
> and help out that issue.
>
>
> _______________________________________________
> hessian-interest mailing list
> [email protected]
> http://maillist.caucho.com/mailman/listinfo/hessian-interest
_______________________________________________
hessian-interest mailing list
[email protected]
http://maillist.caucho.com/mailman/listinfo/hessian-interest