From db1d24053112b97c4f3d5efb004e478dc9714451 Mon Sep 17 00:00:00 2001 From: Gary Gilbert Date: Fri, 3 Apr 2015 14:44:55 -0400 Subject: [PATCH 1/3] Updated LtiLaunch to support additional recommended and optional launch parameters;added support custom and ext parameters --- .gitignore | 4 + .../org/imsglobal/lti/launch/LtiLaunch.java | 204 +++++++++++++++++- 2 files changed, 203 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 8192014..c905879 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ /target/ .idea/ *.iml +/bin/ +.classpath +.project +.settings/ diff --git a/src/main/java/org/imsglobal/lti/launch/LtiLaunch.java b/src/main/java/org/imsglobal/lti/launch/LtiLaunch.java index 4e322f1..d73a2a2 100644 --- a/src/main/java/org/imsglobal/lti/launch/LtiLaunch.java +++ b/src/main/java/org/imsglobal/lti/launch/LtiLaunch.java @@ -1,41 +1,141 @@ package org.imsglobal.lti.launch; import javax.servlet.http.HttpServletRequest; + import java.util.Map; +import java.util.Set; +import java.util.TreeMap; /** * Created by paul on 5/28/14. */ public class LtiLaunch { - private LtiUser user; - + // Required private String version; private String messageType; private String resourceLinkId; + // Recommended + private LtiUser user; private String contextId; private String launchPresentationReturnUrl; + private String launchPresentationDocumentTarget; + private String launchPresentationWidth; + private String launchPresentationHeight; private String toolConsumerInstanceGuid; + + // Optional + private String contextType; + private String launchPresentationLocale; + private String launchPresentationCssUrl; + private String roleScopeMentor; + private String userImage; + private Map custom; + private Map ext; public LtiLaunch(HttpServletRequest request) { - this.user = new LtiUser(request); + this.version = request.getParameter("lti_version"); this.messageType = request.getParameter("lti_message_type"); this.resourceLinkId = request.getParameter("resource_link_id"); + + this.user = new LtiUser(request); this.contextId = request.getParameter("context_id"); this.launchPresentationReturnUrl = request.getParameter("launch_presentation_return_url"); + this.launchPresentationDocumentTarget = request.getParameter("launch_presentation_document_target"); + this.launchPresentationWidth = request.getParameter("launch_presentation_width"); + this.launchPresentationHeight = request.getParameter("launch_presentation_height"); this.toolConsumerInstanceGuid = request.getParameter("tool_consumer_instance_guid"); + + this.contextType = request.getParameter("context_type"); + this.launchPresentationLocale = request.getParameter("launch_presentation_locale"); + this.launchPresentationCssUrl = request.getParameter("launch_presentation_css_url"); + this.roleScopeMentor = request.getParameter("role_scope_mentor"); + this.userImage = request.getParameter("user_image"); + + Map allRequestParameters = request.getParameterMap(); + if (allRequestParameters != null && !allRequestParameters.isEmpty()) { + Set keys = allRequestParameters.keySet(); + for (String key : keys) { + if (key != null) { + if (key.startsWith("custom_")) { + if (this.custom == null) { + this.custom = new TreeMap(); + } + + String [] values = allRequestParameters.get(key); + if (values != null) { + if (values.length > 1) { + this.custom.put(key, stringArrayToCommaDelimitedString(values)); + } + else { + this.custom.put(key, values[0]); + } + } + } + else if (key.startsWith("ext_")) { + if (this.ext == null) { + this.ext = new TreeMap(); + } + + String [] values = allRequestParameters.get(key); + if (values != null) { + if (values.length > 1) { + this.ext.put(key, stringArrayToCommaDelimitedString(values)); + } + else { + this.ext.put(key, values[0]); + } + } + } + } + } + } + } public LtiLaunch(Map parameters) { - this.user = new LtiUser(parameters); + this.version = parameters.get("lti_version"); this.messageType = parameters.get("lti_message_type"); this.resourceLinkId = parameters.get("resource_link_id"); + + this.user = new LtiUser(parameters); this.contextId = parameters.get("context_id"); this.launchPresentationReturnUrl = parameters.get("launch_presentation_return_url"); + this.launchPresentationDocumentTarget = parameters.get("launch_presentation_document_target"); + this.launchPresentationWidth = parameters.get("launch_presentation_width"); + this.launchPresentationHeight = parameters.get("launch_presentation_height"); this.toolConsumerInstanceGuid = parameters.get("tool_consumer_instance_guid"); + + this.contextType = parameters.get("context_type"); + this.launchPresentationLocale = parameters.get("launch_presentation_locale"); + this.launchPresentationCssUrl = parameters.get("launch_presentation_css_url"); + this.roleScopeMentor = parameters.get("role_scope_mentor"); + this.userImage = parameters.get("user_image"); + + Set keys = parameters.keySet(); + for (String key : keys) { + if (key != null) { + if (key.startsWith("custom_")) { + if (this.custom == null) { + this.custom = new TreeMap(); + } + + String value = parameters.get(key); + this.custom.put(key, value); + } + else if (key.startsWith("ext_")) { + if (this.ext == null) { + this.ext = new TreeMap(); + } + + String value = parameters.get(key); + this.custom.put(key, value); + } + } + } } public LtiUser getUser() { @@ -86,11 +186,105 @@ public void setLaunchPresentationReturnUrl(String launchPresentationReturnUrl) { this.launchPresentationReturnUrl = launchPresentationReturnUrl; } - public String getToolConsumerInstanceGuid() { + public String getLaunchPresentationDocumentTarget() { + return launchPresentationDocumentTarget; + } + + public void setLaunchPresentationDocumentTarget( + String launchPresentationDocumentTarget) { + this.launchPresentationDocumentTarget = launchPresentationDocumentTarget; + } + + public String getLaunchPresentationWidth() { + return launchPresentationWidth; + } + + public void setLaunchPresentationWidth(String launchPresentationWidth) { + this.launchPresentationWidth = launchPresentationWidth; + } + + public String getLaunchPresentationHeight() { + return launchPresentationHeight; + } + + public void setLaunchPresentationHeight(String launchPresentationHeight) { + this.launchPresentationHeight = launchPresentationHeight; + } + + public String getToolConsumerInstanceGuid() { return toolConsumerInstanceGuid; } public void setToolConsumerInstanceGuid(String toolConsumerInstanceGuid) { this.toolConsumerInstanceGuid = toolConsumerInstanceGuid; } + + public String getContextType() { + return contextType; + } + + public void setContextType(String contextType) { + this.contextType = contextType; + } + + public String getLaunchPresentationLocale() { + return launchPresentationLocale; + } + + public void setLaunchPresentationLocale(String launchPresentationLocale) { + this.launchPresentationLocale = launchPresentationLocale; + } + + public String getLaunchPresentationCssUrl() { + return launchPresentationCssUrl; + } + + public void setLaunchPresentationCssUrl(String launchPresentationCssUrl) { + this.launchPresentationCssUrl = launchPresentationCssUrl; + } + + public String getRoleScopeMentor() { + return roleScopeMentor; + } + + public void setRoleScopeMentor(String roleScopeMentor) { + this.roleScopeMentor = roleScopeMentor; + } + + public String getUserImage() { + return userImage; + } + + public void setUserImage(String userImage) { + this.userImage = userImage; + } + + public Map getCustom() { + return custom; + } + + public void setCustom(Map custom) { + this.custom = custom; + } + + public Map getExt() { + return ext; + } + + public void setExt(Map ext) { + this.ext = ext; + } + + private String stringArrayToCommaDelimitedString(String [] values) { + + StringBuilder stringBuilder = new StringBuilder(); + for (int i = 0; i < values.length; i++) { + stringBuilder.append(values[i]); + if (i < values.length - 1) { + stringBuilder.append(","); + } + } + + return stringBuilder.toString(); + } } From 1abe3e1451f8514cbd5ef67e56eaf868202f5449 Mon Sep 17 00:00:00 2001 From: Gary Gilbert Date: Fri, 22 May 2015 09:25:35 -0400 Subject: [PATCH 2/3] added more supported parameters to launch object --- .../org/imsglobal/lti/launch/LtiLaunch.java | 27 +++++++++++++++++++ .../java/org/imsglobal/pox/IMSPOXRequest.java | 2 ++ 2 files changed, 29 insertions(+) diff --git a/src/main/java/org/imsglobal/lti/launch/LtiLaunch.java b/src/main/java/org/imsglobal/lti/launch/LtiLaunch.java index d73a2a2..02905fc 100644 --- a/src/main/java/org/imsglobal/lti/launch/LtiLaunch.java +++ b/src/main/java/org/imsglobal/lti/launch/LtiLaunch.java @@ -33,6 +33,11 @@ public class LtiLaunch { private String userImage; private Map custom; private Map ext; + + // Deprecated parameters + private String lis_result_sourcedid; + private String lis_outcome_service_url; + public LtiLaunch(HttpServletRequest request) { @@ -54,6 +59,9 @@ public LtiLaunch(HttpServletRequest request) { this.roleScopeMentor = request.getParameter("role_scope_mentor"); this.userImage = request.getParameter("user_image"); + this.lis_result_sourcedid = request.getParameter("lis_result_sourcedid"); + this.lis_outcome_service_url = request.getParameter("lis_outcome_service_url"); + Map allRequestParameters = request.getParameterMap(); if (allRequestParameters != null && !allRequestParameters.isEmpty()) { Set keys = allRequestParameters.keySet(); @@ -115,6 +123,9 @@ public LtiLaunch(Map parameters) { this.roleScopeMentor = parameters.get("role_scope_mentor"); this.userImage = parameters.get("user_image"); + this.lis_result_sourcedid = parameters.get("lis_result_sourcedid"); + this.lis_outcome_service_url = parameters.get("lis_outcome_service_url"); + Set keys = parameters.keySet(); for (String key : keys) { if (key != null) { @@ -275,6 +286,22 @@ public void setExt(Map ext) { this.ext = ext; } + public String getLis_result_sourcedid() { + return lis_result_sourcedid; + } + + public void setLis_result_sourcedid(String lis_result_sourcedid) { + this.lis_result_sourcedid = lis_result_sourcedid; + } + + public String getLis_outcome_service_url() { + return lis_outcome_service_url; + } + + public void setLis_outcome_service_url(String lis_outcome_service_url) { + this.lis_outcome_service_url = lis_outcome_service_url; + } + private String stringArrayToCommaDelimitedString(String [] values) { StringBuilder stringBuilder = new StringBuilder(); diff --git a/src/main/java/org/imsglobal/pox/IMSPOXRequest.java b/src/main/java/org/imsglobal/pox/IMSPOXRequest.java index 6f91340..019cd7a 100644 --- a/src/main/java/org/imsglobal/pox/IMSPOXRequest.java +++ b/src/main/java/org/imsglobal/pox/IMSPOXRequest.java @@ -548,6 +548,8 @@ public static void sendReplaceResult(String url, String key, String secret, Stri HttpPost request = buildReplaceResult(url, key, secret, sourcedid, score, resultData, isUrl); DefaultHttpClient client = new DefaultHttpClient(); HttpResponse response = client.execute(request); +System.out.println("**** outcomes status code: "+response.getStatusLine().getStatusCode()); +System.out.println("**** outcomes reason: "+response.getStatusLine().getReasonPhrase()); if (response.getStatusLine().getStatusCode() >= 400) { throw new HttpResponseException(response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase()); From 2c484bb2c1b646584daf78294190012d885a925f Mon Sep 17 00:00:00 2001 From: Gary Gilbert Date: Tue, 9 Feb 2016 11:46:29 -0500 Subject: [PATCH 3/3] removed system out statements that were mistakenly committed --- src/main/java/org/imsglobal/pox/IMSPOXRequest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/org/imsglobal/pox/IMSPOXRequest.java b/src/main/java/org/imsglobal/pox/IMSPOXRequest.java index 019cd7a..6f91340 100644 --- a/src/main/java/org/imsglobal/pox/IMSPOXRequest.java +++ b/src/main/java/org/imsglobal/pox/IMSPOXRequest.java @@ -548,8 +548,6 @@ public static void sendReplaceResult(String url, String key, String secret, Stri HttpPost request = buildReplaceResult(url, key, secret, sourcedid, score, resultData, isUrl); DefaultHttpClient client = new DefaultHttpClient(); HttpResponse response = client.execute(request); -System.out.println("**** outcomes status code: "+response.getStatusLine().getStatusCode()); -System.out.println("**** outcomes reason: "+response.getStatusLine().getReasonPhrase()); if (response.getStatusLine().getStatusCode() >= 400) { throw new HttpResponseException(response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase());