I gave up trying to figure out how to remove namespaces from the
response, and decided to write my own MessageFormatter that ignores
namespaces, since I don't care about them if I'm using the data in
JavaScript.
Here's what I did:
- copied MappedNamespaceConvention to MyMappedNamespaceConvention and
changed getJSONNamespace to always return ""; I had to make a copy
because getJSONNamespace is private -- why?!
- copied MappedXMLStreamWriter to MyMappedXMLStreamWriter and changed to
use a MyMappedNamespaceConvention object instead of a
MappedNamespaceConvention object. I had to make another copy, because
MappedXMLStreamWriter defines a MappedNamespaceConvention instead of
using the interface Convention that MappedNamespaceConvention
implements. Convention doesn't define isElement or createAttributeKey,
not sure why.
- overrode JSONMessageFormatter.getJSONWriter to use
MyMappedNamespaceConvention and MyMappedXMLStreamWriter
- in axis2.xml, set messageFormatter for application/json to use
MyJSONMessageFormatter
This returns output like this:
{"getAllOnlineUsersResponse":{"return":["admin","knadmin01"]}}, which I
can use in JavaScript like this:
try {
// get data from services/content/serviceMethod?params via AJAX
// checks to see if data is an array or not; single elements are not
put into an array
setData(data[serviceMethod+"Response"].return);
} catch(err) {
document.getElementById("data").innerHTML = "no data available";
}
Kimberly Nicholls
Kimberly Nicholls wrote:
Did you ever find an answer for this? I would also like to use a
mapped service with POJO services, but I've searched and searched and
can't find any information on how to get it working.
I've tried adding <schema schemaNamespace=""
elementFormDefaultQualified="false"/> to my service (found on the How
to remove namespaces from SOAP response in Axis2 thread), and
targetNamespace="" to my <service> tag. That gets me a response like this:
<ns:getAllOnlineUsersResponse xmlns:ns="http://webservice.company.com"
xmlns:ax21="http://webservice.company.com/xsd">
<return>kntest01</return>
<return>kntest02</return>
</ns:getAllOnlineUsersResponse>
So there's <return> instead of <ns:return>, but there's still a
namespace on the reponse, and I still get "Mapped formatted JSON with
namespaces are not supported in Axis2. Make sure that your request
doesn't include namespaces or use the Badgerfish convention" in my
error log.
If I can't get this working, my next idea is to write some sort of
handler that can parse the badgerfish output into something actually
usable by a JavaScript developer, but it seems like I shouldn't have
to do that...
Kimberly Nicholls
Karina Pereyra wrote:
I don't have errors using badgerfish but i want to parse it into
javascript and mapped is easier than badgerfish to parse.
also i'm a neebie in java and axis2, could you suggest me some guides
to create services using axiom or how to specify namespaces to
default?
thanks a lot.
On 10/3/07, Thilina Gunarathne <[EMAIL PROTECTED]> wrote:
AFAIK POJO support by defualt generates namespaces. But you can try
specifying nameapce to package mapping pointing to the defualt
namespace... Not sure whether it'll work..
If not you will have to either create your service using Axiom or
using a code generation...
These are the results of impedence mismatch's between JSON and XML..
Also wat's the error you are getting with badgerfish.
Thanks,
Thilina
On 10/3/07, Karina Pereyra <[EMAIL PROTECTED]> wrote:
i'd like to use mapped service not badgerfish but when i try to use
mapped i have this error
Mapped formatted JSON with namespaces are not supported in Axis2.
Make sure that your request doesn't include namespaces or use the
Badgerfish convention.
do you know how i can remove namespaces?
On 10/3/07, keith chapman <[EMAIL PROTECTED]> wrote:
Sorry Karina I'm not very familiar with Badgerfish. Did you have a look at
http://wso2.org/library/768 ?
Thanks,
Keith.
On 10/3/07, Karina Pereyra <[EMAIL PROTECTED]> wrote:
I'm nearby of success.
I have now my pojo services with this method, but i have the last problem.
When i use Badgerfish response comes to client (response is difficult
to parse in javascript),
But when i use Mapped i have the next error:
Mapped formatted JSON with namespaces are not supported in Axis2.
Make sure that your request doesn't include namespaces or use the
Badgerfish convention.
How i could use mapped formatter in axis2 with pojo?
public User UserInfo(String username ) throws AxisFault{
MessageContext msgContext =
org.apache.axis2.context.MessageContext.getCurrentMessageContext().getCurrentMessageContext().getOperationContext().getMessageContext(
WSDLConstants.MESSAGE_LABEL_OUT_VALUE
);
msgContext.setProperty(Constants.Configuration.MESSAGE_TYPE,"application/json");
return (User)entries.get(username);
}
---------------------------------------------------------------------
To unsubscribe, e-mail:
[EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
Keith Chapman
WSO2 Inc.
Oxygen for Web Services Developers.
http://wso2.org/
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
Thilina Gunarathne - http://thilinag.blogspot.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]