Resteasy 3.x Series three: Jsonp

Source: Internet
Author: User
Tags jboss

Cross-domain request resolution (JSONP, CORS) mentions resolving cross-domain can be used Jsonp,resteasy Self-jsonp interceptor

First, refer to the method inside the Http://stackoverflow.com/questions/5350924/how-enable-jsonp-in-resteasy:

1. In your Web. XML add:

<context-param>    <param-name>resteasy.providers</param-name>    <param-value> Org.jboss.resteasy.plugins.providers.jackson.jacksonjsonpinterceptor</param-value></context-param>

2. Make sure a web-inf/jboss-deployment-structure.xml with:

<jboss-deployment-structure>    <deployment>        <dependencies>            <module name= " Org.jboss.resteasy.resteasy-jackson-provider "services=" import "annotations=" true "/>        </dependencies >    </deployment></jboss-deployment-structure>

3, make sure you has a resteasy-jackson-provider dependency in your pom.xml, something like:

<dependency>    <groupId>org.jboss.resteasy</groupId>    <artifactId> Resteasy-jackson-provider</artifactid>    <scope>provided</scope></dependency>

Second, but Resteasy's documentation mentions the use of:

    <dependency>       <groupId>org.jboss.resteasy</groupId>       <artifactId> resteasy-json-p-provider</artifactid>       <version>3.0.9.Final</version>    </dependency >

Thirdly, I tried it myself.

1, JSON and JSONP are in the Resteasy-jackson2-provider inside, Pom.xml:

<dependency><groupId>org.jboss.resteasy</groupId><artifactId> Resteasy-jackson2-provider</artifactid><version>3.0.9.final</version></dependency>

2. Web. xml:

<context-param><param-name>resteasy.providers</param-name><param-value> Org.jboss.resteasy.plugins.providers.jackson.jackson2jsonpinterceptor</param-value></context-param >

But there is still a problem and the last use

GET HTTP://LOCALHOST:8080/RESTEASY_02_JSONP/JSON/PRODUCT/GET?CALLBACK=AAA

return: aaa ({"Name": "IPad 3", "Age": 999}

Note a ")" is missing from the back, and he returns the JSON object

But

POST Http://localhost:8080/RestEasy_02_Jsonp/json/product/post?callback=back

return: Back (Product created: [email protected]) OK, he returned a string.

Do not know what the problem, have to know the trouble to tell

Iv. Source code Download

Accessories: Resteasy_02_jsonp.zip

Resteasy 3.x Series three: Jsonp

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.