[GRP-437] Add JSONP support to Grouper-WS Created: 21/May/10  Updated: 20/Mar/12  Resolved: 20/Mar/12

Status: Resolved
Project: Grouper
Component/s: WS
Affects Version/s: None
Fix Version/s: 2.1.0

Type: Improvement Priority: Minor
Reporter: David Langenberg Assignee: Chris Hyzer (upenn.edu)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

web



 Description   

It would be nice if grouper-ws supported JSONP for AJAX apps which do not live on the server hosting the grouper-ws-api.



 Comments   
Comment by mchyzer [ 19/Oct/10 ]

Just curious, David, what changes need to happen on the server side to support this?

Thanks,
Chris

Comment by langedb [ 19/Oct/10 ]

Basically, the server needs to be able to accept a new parameter on all calls
which return JSON. For this case, let's call the parameter 'callback'. The
input to this parameter is a single-word string. The server will then take
the JSON response, and before sending it back to the client will wrap the
response in the callback value.

Pseudo Example non-JSONp:

GET http://server/getStuff

Returned:

{foo: bar, baz: qux}

Pseudo Example JSONp

GET http://server/getStuff?callback=someQueryResults

Returned:

someQueryResults(

{foo: bar, baz: qux}

)

On the client side, a function someQueryResults will exist which will take the
JSON as a parameter & do things with it.

Dave

Comment by langedb [ 20/Mar/12 ]

Just curious if there is any movement on this.

Comment by mchyzer [ 20/Mar/12 ]

This is fixed.

Note, if you want to disable this functionality, set this in the grouper-ws.properties

ws.allowJsonWrapper = false

If this is the request (could be any operation):

POST /grouper-ws/servicesRest/v2_1_000/subjects?grouperJsonResponseWrapper=something HTTP/1.1
Connection: close
Authorization: Basic XXXXXXXX
User-Agent: Jakarta Commons-HttpClient/3.0
Host: localhost:8090
Content-Length: 149
Content-Type: text/x-json; charset=UTF-8

{"WsRestGetGroupsRequest":{"subjectAttributeNames":["description"],"subjectLookups":[

{"subjectId":"test.subject.0"}

,

{"subjectId":"test.subject.1"}

]}}

Then this is the response:

HTTP/1.1 201 Created
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=xxxxxxxxxxx; Path=/grouper-ws
X-Grouper-resultCode: SUCCESS
X-Grouper-success: T
X-Grouper-resultCode2: NONE
Content-Type: text/x-json;charset=UTF-8
Content-Length: 1135
Date: Tue, 20 Mar 2012 15:00:01 GMT
Connection: close

something({"WsGetGroupsResults":{"responseMetadata":

{"millis":"223","serverVersion":"2.1.0"}

,"resultMetadata":

{"resultCode":"SUCCESS","resultMessage":"Success for: clientVersion: 2.1.0, subjectLookups: Array size: 2: [0]: WsSubjectLookup[subjectId=test.subject.0]\n[1]: WsSubjectLookup[subjectId=test.subject.1]\n\nmemberFilter: All, includeGroupDetail: false, actAsSubject: null\n, params: null\n fieldName1: null\n, scope: null, wsStemLookup: null\n, stemScope: null, enabled: null, pageSize: null, pageNumber: null, sortString: null, ascending: null\n, pointInTimeFrom: null, pointInTimeTo: null","success":"T"}

,"results":[{"resultMetadata":

{"resultCode":"SUCCESS","success":"T"}

,"wsSubject":{"attributeValues":["description.test.subject.0"],"id":"test.subject.0","name":"my name is test.subject.0","resultCode":"SUCCESS","sourceId":"jdbc","success":"T"}},{"resultMetadata":

{"resultCode":"SUCCESS","success":"T"}

,"wsSubject":{"attributeValues":["description.test.subject.1"],"id":"test.subject.1","name":"my name is test.subject.1","resultCode":"SUCCESS","sourceId":"jdbc","success":"T"}}],"subjectAttributeNames":["description"]}})

Generated at Thu Apr 18 23:22:41 UTC 2024 using Jira 9.4.18#940018-sha1:32a59db0b032756f9bbd6a22c656d21edb3fb41f.