You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by "senthil.arumugam" <se...@gmail.com> on 2010/11/23 10:39:52 UTC

Issue with Json Namespace in POST/PUT

Hi,

I am facing an issue with POST/PUT input in Json format, we use multiple
schemas and using which we are validating our Input. 

When I try POST/PUT,
cvc-complex-type.2.4.a: Invalid content was found starting with element
'image'. One of '{"http://sample-json.com/xml/ns/image":image}' is expected.

Input looks like,
{
 "ns1.foo": {
           "ns1.id": 1,
           "ns1.name": "no:1-Foo"
           "ns1.images": {
                  "ns2.image": [
                        {
                             "ns2.imageUri": "thumbnail.jpg",
                             "ns2.height": 342,
                             "ns2.type": "thumbnail",
                             "ns2.width": 380
                        }
                  ]
            },
      }
}

JSONProvider bean looks like,
  <bean id="jsonpProvider"
class="com.ebates.cxf.jaxrs.provider.JSONPProvider" autowire="constructor">
    <property name="namespaceMap" ref="jsonNamespaceMap" />
  </bean>
  
  <util:map id="jsonNamespaceMap" map-class="java.util.Hashtable">
    <entry key="http://sample-json.com/xml/ns/foo" value="ns1"/>
    <entry key="http://sample-json.com/xml/ns/image" value="ns2"/>
  </util:map>

Thanks in advance.

-Senthil Arumugam
-- 
View this message in context: http://cxf.547215.n5.nabble.com/Issue-with-Json-Namespace-in-POST-PUT-tp3276515p3276515.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Issue with Json Namespace in POST/PUT

Posted by "senthil.arumugam" <se...@gmail.com>.
Hi Sergey,

I meant multiple schemas in the same way as in you specified here. I have
image.xsd and foo.xsd and I use package-info for package level annotation to
specify the schema to be referred for the package.

When we have specified the schema at package level, do we need to specify at
@XmlRootElement too ?? I tried specifying namespace at @XmlRootElement too
and it too did not help with the POST/PUT of Json.

Thanks
Senthil Arumugam
-- 
View this message in context: http://cxf.547215.n5.nabble.com/Issue-with-Json-Namespace-in-POST-PUT-tp3276515p3279896.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Issue with Json Namespace in POST/PUT

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi Senthil

Sorry - I haven't had a chance to  investigate just yet - I suspect it might
be a Jettison issue and thus out of CXF's control, I'll try to find some
time asap

Sergey

On Fri, Dec 3, 2010 at 10:03 AM, Senthilkumar Arumugam <
senthilkumara20@gmail.com> wrote:

> Hi Sergey,
>
> Please find the attached sample maven project, it is been developed to
> reproduce the issue I am facing.
>
> I have  included the input json and xml, POST/PUT on which you can
> reproduce
> the bug I am facing. On giving the array specification (i.e., square
> brackets), the input instance of object I am getting is carrying null
> values
> for the array of elements.
>
> I have added the test cases too, but we are getting some Connection refused
> exception. Whereas deploying which on server you can have the application
> working.
>
> Thanks,
> Senthil Arumugam
>
> ---------- Forwarded message ----------
> From: senthil.arumugam [via CXF] <
> ml-node+3287570-816798456-66771@n5.nabble.com<ml...@n5.nabble.com>
> >
> Date: Wed, Dec 1, 2010 at 5:49 PM
> Subject: Re: Issue with Json Namespace in POST/PUT
> To: "senthil.arumugam" <se...@gmail.com>
>
>
> json-sample.zip<http://cxf.547215.n5.nabble.com/file/n3287570/json-sample.zip>
>
> Missed out to attach with the previous message. Sorry.
>

Re: Issue with Json Namespace in POST/PUT

Posted by "senthil.arumugam" <se...@gmail.com>.
http://cxf.547215.n5.nabble.com/file/n3287570/json-sample.zip json-sample.zip 

Missed out to attach with the previous message. Sorry.
-- 
View this message in context: http://cxf.547215.n5.nabble.com/Issue-with-Json-Namespace-in-POST-PUT-tp3276515p3287570.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Issue with Json Namespace in POST/PUT

Posted by "senthil.arumugam" <se...@gmail.com>.
Hi Sergey,

Please find the attached sample maven project, it is been developed to
reproduce the issue I am facing.

I have  included the input json and xml, POST/PUT on which you can reproduce
the bug I am facing. On giving the array specification (i.e., square
brackets), the input instance of object I am getting is carrying null values
for the array of elements.

I have added the test cases too, but we are getting some Connection refused
exception. Whereas deploying which on server you can have the application
working.

Thanks,
Senthil Arumugam
-- 
View this message in context: http://cxf.547215.n5.nabble.com/Issue-with-Json-Namespace-in-POST-PUT-tp3276515p3287567.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Issue with Json Namespace in POST/PUT

Posted by "senthil.arumugam" <se...@gmail.com>.
Hi Sergey,

Any idea how can we overcome the issues I am facing while giving Json input
for POST/PUT ?

Thanks
Senthil Arumugam
-- 
View this message in context: http://cxf.547215.n5.nabble.com/Issue-with-Json-Namespace-in-POST-PUT-tp3276515p3283135.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Issue with Json Namespace in POST/PUT

Posted by "senthil.arumugam" <se...@gmail.com>.
Hi Sergey,

When I turned off the validation, it was working fine but I could not get
the Image values been given in the input Json. Image collection was null.

Let me update this thread, when I get to know something more interested. One
other thing is, when I do not use the array brackets but on giving multiple
Image, the last value been given is saved.

For example, in the below input only the Image of type logo is saved.
{ 
 "ns1.foo": { 
          "ns1.id": 1, 
          "ns1.name": "no:1-Foo" 
          "ns1.images": { 
                 "ns2.image": 
                       { 
                            "ns2.imageUri": "thumbnail.jpg", 
                            "ns2.height": 342, 
                            "ns2.type": "thumbnail", 
                            "ns2.width": 380 
                       },
                 "ns2.image": 
                       { 
                            "ns2.imageUri": "thumbnail.jpg", 
                            "ns2.height": 342, 
                            "ns2.type": "logo", 
                            "ns2.width": 380 
                       } 
           }, 
     } 
} 

Thanks
Senthil Arumugam
-- 
View this message in context: http://cxf.547215.n5.nabble.com/Issue-with-Json-Namespace-in-POST-PUT-tp3276515p3280014.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Issue with Json Namespace in POST/PUT

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

thanks for the update. I think you said it earlier on, but can you please
confirm : if you use the array brackets, around image, it does not work even
with the validation being turned off ? In other words, is it the problem
with Jettison reading  sequences with explicit array separators that we're
dealing here ?

cheers, Sergey

On Thu, Nov 25, 2010 at 12:00 PM, senthil.arumugam <
senthilkumara20@gmail.com> wrote:

>
> Hi Sergey,
>
> When I try POST/PUT with input with only one Image inside Images without
> specifying as an array, the POST/PUT works fine for me.
>
> {
>  "ns1.foo": {
>          "ns1.id": 1,
>          "ns1.name": "no:1-Foo"
>          "ns1.images": {
>                 "ns2.image":
>                       {
>                            "ns2.imageUri": "thumbnail.jpg",
>                            "ns2.height": 342,
>                            "ns2.type": "thumbnail",
>                            "ns2.width": 380
>                       }
>            },
>     }
> }
>
> It fails, even when I give a single Image element in array the POST/PUT
> fails. I guess, the error is because of the array of elements. I tried the
> property 'serializeAsArray' but it did not help.
>
> Can you please direct me, how I can give the input Json with an array of
> elements.
>
> Thanks
> Senthil Arumugam
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/Issue-with-Json-Namespace-in-POST-PUT-tp3276515p3279944.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>

Re: Issue with Json Namespace in POST/PUT

Posted by "senthil.arumugam" <se...@gmail.com>.
Hi Sergey,

When I try POST/PUT with input with only one Image inside Images without
specifying as an array, the POST/PUT works fine for me.

{
 "ns1.foo": {
          "ns1.id": 1,
          "ns1.name": "no:1-Foo"
          "ns1.images": {
                 "ns2.image": 
                       {
                            "ns2.imageUri": "thumbnail.jpg",
                            "ns2.height": 342,
                            "ns2.type": "thumbnail",
                            "ns2.width": 380
                       }
           },
     }
}

It fails, even when I give a single Image element in array the POST/PUT
fails. I guess, the error is because of the array of elements. I tried the
property 'serializeAsArray' but it did not help.

Can you please direct me, how I can give the input Json with an array of
elements.

Thanks
Senthil Arumugam
-- 
View this message in context: http://cxf.547215.n5.nabble.com/Issue-with-Json-Namespace-in-POST-PUT-tp3276515p3279944.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Issue with Json Namespace in POST/PUT

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi Senthil

thanks for posting the snippets. Just a quick check :
- I'm assuming that both Images and Image beans have @XmlRootElement with
the namespace attribute ?
- When you say 'multiple schemas', do you mean that you have say A.xsd
importing B.xsd with xsd:import ?

cheers, Sergey


On Thu, Nov 25, 2010 at 9:12 AM, senthil.arumugam <senthilkumara20@gmail.com
> wrote:

>
> Hi Sergey,
>
> I have added the code snippet of Images and Image bean. The problem I am
> facing is, when I have the input from single namespace, it works fine. When
> I have the multiple namespaces, it fails at validation.
>
> Here goes the Images
>
>
> > @XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
> > @XmlRootElement(name = "images")
> > public class Images {
> >     private Collection<Image> images;
> >
> >     public Images() {
> >     }
> >
> >     public Images(final Collection<Image> images) {
> >         this.images = images;
> >     }
> >
> >     @XmlElement(name = "image")
> >     public Collection<Image> getImages() {
> >         return images;
> >     }
> >
> >     public void setEntity(final Long entityId, final Long entityTypeId) {
> >         for (final Image image : this.images) {
> >             image.setEntityId(entityId);
> >             image.setEntityTypeId(entityTypeId);
> >         }
> >     }
> >
> >     public void setImages(final Collection<Image> images) {
> >         this.images = images;
> >     }
> > }
> >
>
> Image bean:
>
>
> > @XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
> > @XmlRootElement(name = "image")
> > public class Image {
> >     private Long entityId;
> >     private Long entityTypeId;
> >     private Integer height;
> >     private Long id;
> >     pirvate String absoluteUri;
> >     private Date lastModified;
> >     private ImageTypeEnum type;
> >     private Integer width;
> >
> >     public Image() {
> >     }
> >
> >     @XmlElement(name = "imageUri")
> >     public String getAbsoluteUri() {
> >         return absoluteUri;
> >     }
> >
> >     @XmlTransient public Long getEntityId() {
> >         return entityId;
> >     }
> >
> >     @XmlTransient public Long getEntityTypeId() {
> >         return entityTypeId;
> >     }
> >
> >     public Integer getHeight() {
> >         return height;
> >     }
> >
> >     public Long getId() {
> >         return id;
> >     }
> >
> >     @XmlTransient public Date getLastModified() {
> >         return lastModified;
> >     }
> >
> >     public ImageTypeEnum getType() {
> >         return type;
> >     }
> >
> >     public Integer getWidth() {
> >         return width;
> >     }
> >
> >     public void setEntityId(final Long entityId) {
> >         this.entityId = entityId;
> >     }
> >
> >     public void setEntityTypeId(final Long entityTypeId) {
> >         this.entityTypeId = entityTypeId;
> >     }
> >
> >     public void setHeight(final Integer height) {
> >         this.height = height;
> >     }
> >
> >     public void setId(final Long id) {
> >         this.id = id;
> >     }
> >
> >     public void setLastModified(final Date lastModified) {
> >         this.lastModified = lastModified;
> >     }
> >
> >     public void setType(final ImageTypeEnum type) {
> >         this.type = type;
> >     }
> >
> >     public void setWidth(final Integer width) {
> >         this.width = width;
> >     }
> > }
> >
>
> Thanks
> Senthil Arumugam
>
>

Re: Issue with Json Namespace in POST/PUT

Posted by "senthil.arumugam" <se...@gmail.com>.
Hi Sergey,

I have added the code snippet of Images and Image bean. The problem I am
facing is, when I have the input from single namespace, it works fine. When
I have the multiple namespaces, it fails at validation.

Here goes the Images


> @XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
> @XmlRootElement(name = "images")
> public class Images {
>     private Collection<Image> images;
> 
>     public Images() {
>     }
> 
>     public Images(final Collection<Image> images) {
>         this.images = images;
>     }
> 
>     @XmlElement(name = "image")
>     public Collection<Image> getImages() {
>         return images;
>     }
> 
>     public void setEntity(final Long entityId, final Long entityTypeId) {
>         for (final Image image : this.images) {
>             image.setEntityId(entityId);
>             image.setEntityTypeId(entityTypeId);
>         }
>     }
> 
>     public void setImages(final Collection<Image> images) {
>         this.images = images;
>     }
> }
> 

Image bean:


> @XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
> @XmlRootElement(name = "image")
> public class Image {
>     private Long entityId;
>     private Long entityTypeId;
>     private Integer height;
>     private Long id;
>     pirvate String absoluteUri;
>     private Date lastModified;
>     private ImageTypeEnum type;
>     private Integer width;
> 
>     public Image() {
>     }
> 
>     @XmlElement(name = "imageUri")
>     public String getAbsoluteUri() {
>         return absoluteUri;
>     }
> 
>     @XmlTransient public Long getEntityId() {
>         return entityId;
>     }
> 
>     @XmlTransient public Long getEntityTypeId() {
>         return entityTypeId;
>     }
> 
>     public Integer getHeight() {
>         return height;
>     }
> 
>     public Long getId() {
>         return id;
>     }
> 
>     @XmlTransient public Date getLastModified() {
>         return lastModified;
>     }
> 
>     public ImageTypeEnum getType() {
>         return type;
>     }
> 
>     public Integer getWidth() {
>         return width;
>     }
> 
>     public void setEntityId(final Long entityId) {
>         this.entityId = entityId;
>     }
> 
>     public void setEntityTypeId(final Long entityTypeId) {
>         this.entityTypeId = entityTypeId;
>     }
> 
>     public void setHeight(final Integer height) {
>         this.height = height;
>     }
> 
>     public void setId(final Long id) {
>         this.id = id;
>     }
> 
>     public void setLastModified(final Date lastModified) {
>         this.lastModified = lastModified;
>     }
> 
>     public void setType(final ImageTypeEnum type) {
>         this.type = type;
>     }
> 
>     public void setWidth(final Integer width) {
>         this.width = width;
>     }
> }
> 

Thanks
Senthil Arumugam
-- 
View this message in context: http://cxf.547215.n5.nabble.com/Issue-with-Json-Namespace-in-POST-PUT-tp3276515p3279716.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Issue with Json Namespace in POST/PUT

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

It is difficult for me to help as I'm not seeing what exactly is happening.
Can you post some sample code, ex, Images bean and Image bean ?

cheers. Sergey

P.S For some reason if I reply directly to your email without stripping your
text then my response is blocked. May be it's something to do with Nabble

Re: Issue with Json Namespace in POST/PUT

Posted by "senthil.arumugam" <se...@gmail.com>.
Hi Sergey,

Thanks for your response. I tried with validation been set off, for Json
input in POST/PUT calls I receive the Images as null. I checked for the
namespaceMap and found to have all the namespaces available.

The same configuration works perfectly fine for xml input in POST/PUT calls.

The only difference is defining the namespace map and referring it in the
provider bean, without which I was getting some exception saying cannot find
declaration for "foo".

Thanks in advance.

Senthil Arumugam
-- 
View this message in context: http://cxf.547215.n5.nabble.com/Issue-with-Json-Namespace-in-POST-PUT-tp3276515p3278046.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Issue with Json Namespace in POST/PUT

Posted by Sergey Beryozkin <sb...@gmail.com>.
My response is being blocked for some reasons...

Hi

I can not really tell why the validation is not working. I have a test
confirming  JSON sequence containing prefixes (processed with Jettison) is
validated, but only a single namespace is involved in the test.

Can you try to post a single image only and see if it's been validated.

Does it work when you turn the validation off ? It actually seems like the
json namespaces map is ignored that is why you're seeing an early validation
error but without the validation you'll likely see a JAXB error.

The custom provider you're using may not be setting the namespace map
properly or it is not injected ?

cheers, Sergey