Skip to content

Commit

Permalink
SAK-44878 - Mark the LTI Advantage JSON documents as UTF-8 (sakaiproj…
Browse files Browse the repository at this point in the history
…ect#8976)

Co-authored-by: Charles Severance <[email protected]>
  • Loading branch information
jonespm and csev authored Jan 21, 2021
1 parent efa2312 commit 6e38d83
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,7 @@ protected void handleKeySet(String tool_id, HttpServletRequest request, HttpServ
return;
}

response.setContentType(APPLICATION_JSON);
try {
out = response.getWriter();
} catch (Exception e) {
Expand All @@ -701,7 +702,6 @@ protected void handleKeySet(String tool_id, HttpServletRequest request, HttpServ
return;
}

response.setContentType(APPLICATION_JSON);
try {
out.println(keySetJSON);
} catch (Exception e) {
Expand Down Expand Up @@ -854,9 +854,9 @@ protected void handleTokenPost(String tool_id, HttpServletRequest request, HttpS
AccessToken at = new AccessToken();
at.access_token = jws;

response.setContentType(APPLICATION_JSON);
String atsp = JacksonUtil.prettyPrintLog(at);

response.setContentType(APPLICATION_JSON);
try {
PrintWriter out = response.getWriter();
out.println(atsp);
Expand Down Expand Up @@ -1226,6 +1226,7 @@ protected void handleNamesAndRoles(String signed_placement, HttpServletRequest r

String maintainRole = site.getMaintainRole();

response.setContentType(APPLICATION_JSON);
PrintWriter out = response.getWriter();
out.println("{");
out.println(" \"id\" : \"http://TODO.wtf.com/we_eliminated_json_ld_but_forgot_to_remove_this\",");
Expand Down Expand Up @@ -1658,7 +1659,7 @@ private void handleLineItemsPost(String signed_placement, HttpServletRequest req
item.id = getOurServerUrl() + LTI13_PATH + "lineitems/" + signed_placement + "/" + retval.getId();

log.debug("Lineitem item={}",item);
response.setContentType(SakaiLineItem.MIME_TYPE);
response.setContentType(SakaiLineItem.CONTENT_TYPE);

PrintWriter out = response.getWriter();
String json_out = JacksonUtil.prettyPrint(item);
Expand Down Expand Up @@ -1738,7 +1739,7 @@ private void handleLineItemsUpdate(String signed_placement, String lineItem, Htt
item.id = getOurServerUrl() + LTI13_PATH + "lineitems/" + signed_placement + "/" + retval.getId();
log.debug("Lineitem item={}",item);
response.setContentType(LineItem.MIME_TYPE);
response.setContentType(LineItem.CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.print(JacksonUtil.prettyPrint(item));
Expand Down Expand Up @@ -1792,7 +1793,7 @@ private void handleLineItemsGet(String signed_placement, boolean all, SakaiLineI

// If we are only returning a single line item
if ( ! all ) {
response.setContentType(SakaiLineItem.MIME_TYPE);
response.setContentType(SakaiLineItem.CONTENT_TYPE);
SakaiLineItem item = LineItemUtil.getDefaultLineItem(site, content);
PrintWriter out = response.getWriter();
out.print(JacksonUtil.prettyPrint(item));
Expand All @@ -1802,8 +1803,7 @@ private void handleLineItemsGet(String signed_placement, boolean all, SakaiLineI
// Find the line items created for this tool
List<SakaiLineItem> toolItems = LineItemUtil.getLineItemsForTool(signed_placement, site, sat.tool_id, filter);

response.setContentType(SakaiLineItem.MIME_TYPE_CONTAINER);

response.setContentType(SakaiLineItem.CONTENT_TYPE_CONTAINER);
PrintWriter out = response.getWriter();
out.print("[");
boolean first = true;
Expand Down Expand Up @@ -1894,9 +1894,10 @@ private void handleLineItemsDetail(String signed_placement, String lineItem, boo
if ( ! results ) {
SakaiLineItem item = LineItemUtil.getLineItem(signed_placement, a);

response.setContentType(SakaiLineItem.MIME_TYPE);
String json_out = JacksonUtil.prettyPrint(item);
log.debug("Returning {}", json_out);

response.setContentType(SakaiLineItem.CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.print(json_out);
return;
Expand All @@ -1921,7 +1922,7 @@ private void resultsForAssignment(String signed_placement, Site site, Assignment
"comment": "This is exceptional work."
}]
*/
response.setContentType(Result.MIME_TYPE_CONTAINER);
response.setContentType(Result.CONTENT_TYPE_CONTAINER);

// Look up the assignment so we can find the max points
GradebookService g = (GradebookService) ComponentManager
Expand Down Expand Up @@ -1958,6 +1959,8 @@ private void resultsForAssignment(String signed_placement, Site site, Assignment

List<User> users = UserDirectoryService.getUsers(userIds);
boolean first = true;

response.setContentType(APPLICATION_JSON);
PrintWriter out = response.getWriter();

if ( user_id == null ) out.println("[");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public class LineItem {
public static final String MIME_TYPE = "application/vnd.ims.lis.v2.lineitem+json";
public static final String MIME_TYPE_CONTAINER = "application/vnd.ims.lis.v2.lineitemcontainer+json";

public static final String CONTENT_TYPE = MIME_TYPE + "; charset=utf-8";
public static final String CONTENT_TYPE_CONTAINER = MIME_TYPE_CONTAINER + "; charset=utf-8";

@JsonProperty("scoreMaximum")
public Double scoreMaximum;
@JsonProperty("label")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public class Result { // This is all output-only
public static final String MIME_TYPE = "application/vnd.ims.lis.v2.result+json";
public static final String MIME_TYPE_CONTAINER = "application/vnd.ims.lis.v2.resultcontainer+json";

public static final String CONTENT_TYPE = MIME_TYPE + "; charset=utf-8";
public static final String CONTENT_TYPE_CONTAINER = MIME_TYPE_CONTAINER + "; charset=utf-8";

@JsonProperty("id")
public String id;
@JsonProperty("scoreOf")
Expand Down

0 comments on commit 6e38d83

Please sign in to comment.