From ce09a1a1e6d44b7553595633f750efdfb7323890 Mon Sep 17 00:00:00 2001 From: Aaron Detre Date: Tue, 11 Feb 2025 15:31:51 -0800 Subject: [PATCH 1/5] feat(CRater): Allow requests to be sent to Berkeley endpoint --- .../webservice/crater/CRaterRequest.java | 4 ++++ .../crater/CRaterScoringRequest.java | 5 ++++ .../webservice/crater/CRaterService.java | 9 +++++-- .../crater/CRaterVerificationRequest.java | 5 ++++ .../webservice/crater/CRaterServiceTest.java | 24 +++++++++++++++++++ 5 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/wise/vle/domain/webservice/crater/CRaterRequest.java b/src/main/java/org/wise/vle/domain/webservice/crater/CRaterRequest.java index f5e52010c..aa96316d1 100644 --- a/src/main/java/org/wise/vle/domain/webservice/crater/CRaterRequest.java +++ b/src/main/java/org/wise/vle/domain/webservice/crater/CRaterRequest.java @@ -6,5 +6,9 @@ public interface CRaterRequest { String getCRaterUrl(); + void setCRaterUrl(String cRaterUrl); + String generateBodyData() throws JSONException; + + boolean forBerkeleyEndpoint(); } diff --git a/src/main/java/org/wise/vle/domain/webservice/crater/CRaterScoringRequest.java b/src/main/java/org/wise/vle/domain/webservice/crater/CRaterScoringRequest.java index d2253eabc..6de02ef02 100644 --- a/src/main/java/org/wise/vle/domain/webservice/crater/CRaterScoringRequest.java +++ b/src/main/java/org/wise/vle/domain/webservice/crater/CRaterScoringRequest.java @@ -31,4 +31,9 @@ public String generateBodyData() throws JSONException { body.put("responses", responses); return body.toString(); } + + // Duplicate method implementation would be abstracted in issue 285 + public boolean forBerkeleyEndpoint() { + return itemId.substring(0, 9).equals("berkeley_"); + } } diff --git a/src/main/java/org/wise/vle/domain/webservice/crater/CRaterService.java b/src/main/java/org/wise/vle/domain/webservice/crater/CRaterService.java index 76dc7b80a..428f5561d 100644 --- a/src/main/java/org/wise/vle/domain/webservice/crater/CRaterService.java +++ b/src/main/java/org/wise/vle/domain/webservice/crater/CRaterService.java @@ -59,7 +59,7 @@ public class CRaterService { */ public String getScoringResponse(CRaterScoringRequest request) throws JSONException { request.setCRaterClientId(appProperties.getProperty("cRater_client_id")); - request.setCRaterUrl(appProperties.getProperty("cRater_scoring_url")); + setRequestCRaterUrl(request, "cRater_scoring_url"); return post(request); } @@ -71,10 +71,15 @@ public String getScoringResponse(CRaterScoringRequest request) throws JSONExcept */ public String getVerificationResponse(CRaterVerificationRequest request) throws JSONException { request.setCRaterClientId(appProperties.getProperty("cRater_client_id")); - request.setCRaterUrl(appProperties.getProperty("cRater_verification_url")); + setRequestCRaterUrl(request, "cRater_verification_url"); return post(request); } + private void setRequestCRaterUrl(CRaterRequest request, String baseUrl) { + request.setCRaterUrl(appProperties.getProperty( + request.forBerkeleyEndpoint() ? "berkeley_" + baseUrl : baseUrl)); + } + /** * POSTs a CRater Request to the CRater Servlet and returns the CRater response string * diff --git a/src/main/java/org/wise/vle/domain/webservice/crater/CRaterVerificationRequest.java b/src/main/java/org/wise/vle/domain/webservice/crater/CRaterVerificationRequest.java index 0ff17ebf0..f3dcaf14b 100644 --- a/src/main/java/org/wise/vle/domain/webservice/crater/CRaterVerificationRequest.java +++ b/src/main/java/org/wise/vle/domain/webservice/crater/CRaterVerificationRequest.java @@ -21,4 +21,9 @@ public String generateBodyData() throws JSONException { body.put("item_id", itemId); return body.toString(); } + + // Duplicate method implementation would be abstracted in issue 285 + public boolean forBerkeleyEndpoint() { + return itemId.substring(0, 9).equals("berkeley_"); + } } diff --git a/src/test/java/org/wise/vle/domain/webservice/crater/CRaterServiceTest.java b/src/test/java/org/wise/vle/domain/webservice/crater/CRaterServiceTest.java index 64c4ed464..021ea4140 100644 --- a/src/test/java/org/wise/vle/domain/webservice/crater/CRaterServiceTest.java +++ b/src/test/java/org/wise/vle/domain/webservice/crater/CRaterServiceTest.java @@ -25,6 +25,8 @@ public class CRaterServiceTest { private String password = "abc123"; private String scoringUrl = "https://test.org/score"; private String verifyUrl = "https://test.org/verify"; + private String berkeleyScoringUrl = "https://test.org/score/berkeley"; + private String berkeleyVerifyUrl = "https://test.org/verify/berkeley"; @Before public void before() { @@ -53,4 +55,26 @@ public void getVerificationResponse_ShouldGetCRaterProperties() throws JSONExcep cRaterService.getVerificationResponse(request); verify(appProperties); } + + @Test + public void getBerkeleyScoringResponse_ShouldGetCRaterProperties() throws JSONException { + CRaterScoringRequest request = new CRaterScoringRequest(); + request.setItemId("berkeley_" + itemId); + request.setResponseId("1234567890"); + request.setResponseText("hello"); + expect(appProperties.getProperty("berkeley_cRater_scoring_url")).andReturn(berkeleyScoringUrl); + replay(appProperties); + cRaterService.getScoringResponse(request); + verify(appProperties); + } + + @Test + public void getBerkeleyVerificationResponse_ShouldGetCRaterProperties() throws JSONException { + CRaterVerificationRequest request = new CRaterVerificationRequest(); + request.setItemId("berkeley_" + itemId); + expect(appProperties.getProperty("berkeley_cRater_verification_url")).andReturn(berkeleyVerifyUrl); + replay(appProperties); + cRaterService.getVerificationResponse(request); + verify(appProperties); + } } From fae188beedd51e89f2486936cae52b2202911fcb Mon Sep 17 00:00:00 2001 From: Aaron Detre Date: Tue, 18 Feb 2025 16:15:02 -0800 Subject: [PATCH 2/5] refactor(CRaterRequest): Create AbstractCRaterRequest (#289) --- .../crater/AbstractCRaterRequest.java | 27 +++++++++++++++++ .../crater/CRaterScoringRequest.java | 17 ++--------- .../crater/CRaterVerificationRequest.java | 29 ++++--------------- 3 files changed, 35 insertions(+), 38 deletions(-) create mode 100644 src/main/java/org/wise/vle/domain/webservice/crater/AbstractCRaterRequest.java diff --git a/src/main/java/org/wise/vle/domain/webservice/crater/AbstractCRaterRequest.java b/src/main/java/org/wise/vle/domain/webservice/crater/AbstractCRaterRequest.java new file mode 100644 index 000000000..782d50c4a --- /dev/null +++ b/src/main/java/org/wise/vle/domain/webservice/crater/AbstractCRaterRequest.java @@ -0,0 +1,27 @@ +package org.wise.vle.domain.webservice.crater; + +import org.json.JSONException; +import org.json.JSONObject; + +import lombok.Getter; +import lombok.Setter; + +@Setter +public abstract class AbstractCRaterRequest implements CRaterRequest { + String itemId; + String cRaterClientId; + + @Getter + String cRaterUrl; + + public String generateBodyData() throws JSONException { + JSONObject body = new JSONObject(); + body.put("client_id", cRaterClientId); + body.put("item_id", itemId); + return body.toString(); + } + + public boolean forBerkeleyEndpoint() { + return itemId.length() > 9 && itemId.substring(0, 9).equals("berkeley_"); + } +} diff --git a/src/main/java/org/wise/vle/domain/webservice/crater/CRaterScoringRequest.java b/src/main/java/org/wise/vle/domain/webservice/crater/CRaterScoringRequest.java index 6de02ef02..833ca9402 100644 --- a/src/main/java/org/wise/vle/domain/webservice/crater/CRaterScoringRequest.java +++ b/src/main/java/org/wise/vle/domain/webservice/crater/CRaterScoringRequest.java @@ -5,24 +5,16 @@ import org.json.JSONObject; import org.wise.portal.presentation.util.http.Base64; -import lombok.Getter; import lombok.Setter; @Setter -public class CRaterScoringRequest implements CRaterRequest { - String itemId; +public class CRaterScoringRequest extends AbstractCRaterRequest { String responseId; String responseText; - String cRaterClientId; - - @Getter - String cRaterUrl; public String generateBodyData() throws JSONException { - JSONObject body = new JSONObject(); - body.put("client_id", cRaterClientId); + JSONObject body = new JSONObject(super.generateBodyData()); body.put("service", "ScoringService"); - body.put("item_id", itemId); JSONArray responses = new JSONArray(); JSONObject response = new JSONObject(); response.put("response_id", responseId); @@ -31,9 +23,4 @@ public String generateBodyData() throws JSONException { body.put("responses", responses); return body.toString(); } - - // Duplicate method implementation would be abstracted in issue 285 - public boolean forBerkeleyEndpoint() { - return itemId.substring(0, 9).equals("berkeley_"); - } } diff --git a/src/main/java/org/wise/vle/domain/webservice/crater/CRaterVerificationRequest.java b/src/main/java/org/wise/vle/domain/webservice/crater/CRaterVerificationRequest.java index f3dcaf14b..05a3eec42 100644 --- a/src/main/java/org/wise/vle/domain/webservice/crater/CRaterVerificationRequest.java +++ b/src/main/java/org/wise/vle/domain/webservice/crater/CRaterVerificationRequest.java @@ -3,27 +3,10 @@ import org.json.JSONException; import org.json.JSONObject; -import lombok.Getter; -import lombok.Setter; - -@Setter -public class CRaterVerificationRequest implements CRaterRequest { - String itemId; - String cRaterClientId; - - @Getter - String cRaterUrl; - - public String generateBodyData() throws JSONException { - JSONObject body = new JSONObject(); - body.put("client_id", cRaterClientId); - body.put("service", "VerificationService"); - body.put("item_id", itemId); - return body.toString(); - } - - // Duplicate method implementation would be abstracted in issue 285 - public boolean forBerkeleyEndpoint() { - return itemId.substring(0, 9).equals("berkeley_"); - } +public class CRaterVerificationRequest extends AbstractCRaterRequest { + public String generateBodyData() throws JSONException { + JSONObject body = new JSONObject(super.generateBodyData()); + body.put("service", "VerificationService"); + return body.toString(); + } } From 45a4978b9c8a8eea8fe937fb68a8e849d4d85768 Mon Sep 17 00:00:00 2001 From: Aaron Detre Date: Wed, 26 Feb 2025 22:11:17 -0800 Subject: [PATCH 3/5] Added berkeley versions of CRater variables in application properties --- .../webservice/crater/CRaterRequest.java | 4 ++ .../crater/CRaterScoringRequest.java | 8 +++- .../webservice/crater/CRaterService.java | 41 ++++++++----------- .../crater/CRaterVerificationRequest.java | 8 +++- .../org/wise/vle/web/CRaterController.java | 4 +- .../application-dockerdev-sample.properties | 5 +++ .../resources/application_sample.properties | 5 +++ .../webservice/crater/CRaterServiceTest.java | 21 ++++++---- .../wise/vle/web/CRaterControllerTest.java | 4 +- src/test/resources/application.properties | 5 +++ 10 files changed, 66 insertions(+), 39 deletions(-) diff --git a/src/main/java/org/wise/vle/domain/webservice/crater/CRaterRequest.java b/src/main/java/org/wise/vle/domain/webservice/crater/CRaterRequest.java index aa96316d1..7e16cb48b 100644 --- a/src/main/java/org/wise/vle/domain/webservice/crater/CRaterRequest.java +++ b/src/main/java/org/wise/vle/domain/webservice/crater/CRaterRequest.java @@ -6,8 +6,12 @@ public interface CRaterRequest { String getCRaterUrl(); + String getCRaterUrlVariableBase(); + void setCRaterUrl(String cRaterUrl); + void setCRaterClientId(String cRaterClientId); + String generateBodyData() throws JSONException; boolean forBerkeleyEndpoint(); diff --git a/src/main/java/org/wise/vle/domain/webservice/crater/CRaterScoringRequest.java b/src/main/java/org/wise/vle/domain/webservice/crater/CRaterScoringRequest.java index 6de02ef02..42ab0b49d 100644 --- a/src/main/java/org/wise/vle/domain/webservice/crater/CRaterScoringRequest.java +++ b/src/main/java/org/wise/vle/domain/webservice/crater/CRaterScoringRequest.java @@ -32,8 +32,12 @@ public String generateBodyData() throws JSONException { return body.toString(); } - // Duplicate method implementation would be abstracted in issue 285 + // Duplicate method implementation public boolean forBerkeleyEndpoint() { - return itemId.substring(0, 9).equals("berkeley_"); + return this.itemId.length() > 9 && this.itemId.substring(0, 9).equals("berkeley_"); + } + + public String getCRaterUrlVariableBase() { + return "cRater_scoring_url"; } } diff --git a/src/main/java/org/wise/vle/domain/webservice/crater/CRaterService.java b/src/main/java/org/wise/vle/domain/webservice/crater/CRaterService.java index 428f5561d..bc8f4e9c8 100644 --- a/src/main/java/org/wise/vle/domain/webservice/crater/CRaterService.java +++ b/src/main/java/org/wise/vle/domain/webservice/crater/CRaterService.java @@ -52,34 +52,25 @@ public class CRaterService { private Environment appProperties; /** - * Sends student work to the CRater server and receives the score as the response - * - * @param CRaterScoringRequest scoring request from client - * @return CRaterScoringResponse scoring response from CRater + * Sends either student work (scoring request) or an item id (verification request) to + * the CRater server + * @param request the scoring or verification request from the client + * @return scoring or verify response from CRater + * @throws JSONException */ - public String getScoringResponse(CRaterScoringRequest request) throws JSONException { - request.setCRaterClientId(appProperties.getProperty("cRater_client_id")); - setRequestCRaterUrl(request, "cRater_scoring_url"); - return post(request); - } + public String getCRaterResponse(CRaterRequest request) + throws JSONException { + String prefix = request.forBerkeleyEndpoint() ? "berkeley_" : ""; + + String clientIdVariable = prefix + "cRater_client_id"; + String cRaterUrlVariable = prefix + request.getCRaterUrlVariableBase(); + + request.setCRaterClientId(appProperties.getProperty(clientIdVariable)); + request.setCRaterUrl(appProperties.getProperty(cRaterUrlVariable)); - /** - * Sends item id verification request to the CRater server - * - * @param CRaterVerificationRequest request with item id to verify - * @return CRaterVerificationResponse verify response from CRater - */ - public String getVerificationResponse(CRaterVerificationRequest request) throws JSONException { - request.setCRaterClientId(appProperties.getProperty("cRater_client_id")); - setRequestCRaterUrl(request, "cRater_verification_url"); return post(request); } - private void setRequestCRaterUrl(CRaterRequest request, String baseUrl) { - request.setCRaterUrl(appProperties.getProperty( - request.forBerkeleyEndpoint() ? "berkeley_" + baseUrl : baseUrl)); - } - /** * POSTs a CRater Request to the CRater Servlet and returns the CRater response string * @@ -90,8 +81,10 @@ private String post(CRaterRequest request) throws JSONException { HttpClient client = HttpClientBuilder.create().build(); HttpPost post = new HttpPost(request.getCRaterUrl()); try { + String password = appProperties.getProperty( + request.forBerkeleyEndpoint() ? "berkeley_cRater_password" : "cRater_password"); String authHeader = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary( - ("extsyscrtr02dev:" + appProperties.getProperty("cRater_password")).getBytes()); + ("extsyscrtr02dev:" + password).getBytes()); post.setHeader(HttpHeaders.AUTHORIZATION, authHeader); post.setHeader(HttpHeaders.CONTENT_TYPE, "application/json;charset=utf-8"); post.setEntity(new StringEntity(request.generateBodyData(), ContentType.APPLICATION_JSON)); diff --git a/src/main/java/org/wise/vle/domain/webservice/crater/CRaterVerificationRequest.java b/src/main/java/org/wise/vle/domain/webservice/crater/CRaterVerificationRequest.java index f3dcaf14b..61a273cda 100644 --- a/src/main/java/org/wise/vle/domain/webservice/crater/CRaterVerificationRequest.java +++ b/src/main/java/org/wise/vle/domain/webservice/crater/CRaterVerificationRequest.java @@ -22,8 +22,12 @@ public String generateBodyData() throws JSONException { return body.toString(); } - // Duplicate method implementation would be abstracted in issue 285 + // Duplicate method implementation public boolean forBerkeleyEndpoint() { - return itemId.substring(0, 9).equals("berkeley_"); + return this.itemId.length() > 9 && itemId.substring(0, 9).equals("berkeley_"); + } + + public String getCRaterUrlVariableBase() { + return "cRater_verification_url"; } } diff --git a/src/main/java/org/wise/vle/web/CRaterController.java b/src/main/java/org/wise/vle/web/CRaterController.java index 30ef348e4..58573b402 100644 --- a/src/main/java/org/wise/vle/web/CRaterController.java +++ b/src/main/java/org/wise/vle/web/CRaterController.java @@ -43,11 +43,11 @@ public class CRaterController { @GetMapping("/verify") String verifyItemId(CRaterVerificationRequest request) throws JSONException { - return cRaterService.getVerificationResponse(request); + return cRaterService.getCRaterResponse(request); } @PostMapping("/score") String scoreItem(@RequestBody CRaterScoringRequest request) throws JSONException { - return cRaterService.getScoringResponse(request); + return cRaterService.getCRaterResponse(request); } } diff --git a/src/main/resources/application-dockerdev-sample.properties b/src/main/resources/application-dockerdev-sample.properties index a12a0e02e..8ee46c11a 100644 --- a/src/main/resources/application-dockerdev-sample.properties +++ b/src/main/resources/application-dockerdev-sample.properties @@ -66,6 +66,11 @@ cRater_scoring_url= cRater_client_id= cRater_password= +berkeley_cRater_verification_url= +berkeley_cRater_scoring_url= +berkeley_cRater_clientid= +berkeley_cRater_password= + ######### database properties ######### # Modify below as needed. diff --git a/src/main/resources/application_sample.properties b/src/main/resources/application_sample.properties index ae6733b98..6d0958f15 100644 --- a/src/main/resources/application_sample.properties +++ b/src/main/resources/application_sample.properties @@ -66,6 +66,11 @@ cRater_scoring_url= cRater_client_id= cRater_password= +berkeley_cRater_verification_url= +berkeley_cRater_scoring_url= +berkeley_cRater_clientid= +berkeley_cRater_password= + ######### database properties ######### # Modify below as needed. diff --git a/src/test/java/org/wise/vle/domain/webservice/crater/CRaterServiceTest.java b/src/test/java/org/wise/vle/domain/webservice/crater/CRaterServiceTest.java index 021ea4140..5d12caf6e 100644 --- a/src/test/java/org/wise/vle/domain/webservice/crater/CRaterServiceTest.java +++ b/src/test/java/org/wise/vle/domain/webservice/crater/CRaterServiceTest.java @@ -6,7 +6,6 @@ import org.easymock.Mock; import org.easymock.TestSubject; import org.json.JSONException; -import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.core.env.Environment; @@ -28,53 +27,61 @@ public class CRaterServiceTest { private String berkeleyScoringUrl = "https://test.org/score/berkeley"; private String berkeleyVerifyUrl = "https://test.org/verify/berkeley"; - @Before - public void before() { + public void beforeETS() { expect(appProperties.getProperty("cRater_client_id")).andReturn(clientId); expect(appProperties.getProperty("cRater_password")).andReturn(password); } + public void beforeBerkeley() { + expect(appProperties.getProperty("berkeley_cRater_client_id")).andReturn(clientId); + expect(appProperties.getProperty("berkeley_cRater_password")).andReturn(password); + } + @Test public void getScoringResponse_ShouldGetCRaterProperties() throws JSONException { + beforeETS(); CRaterScoringRequest request = new CRaterScoringRequest(); request.setItemId(itemId); request.setResponseId("1234567890"); request.setResponseText("hello"); expect(appProperties.getProperty("cRater_scoring_url")).andReturn(scoringUrl); replay(appProperties); - cRaterService.getScoringResponse(request); + cRaterService.getCRaterResponse(request); verify(appProperties); } @Test public void getVerificationResponse_ShouldGetCRaterProperties() throws JSONException { + beforeETS(); CRaterVerificationRequest request = new CRaterVerificationRequest(); request.setItemId(itemId); expect(appProperties.getProperty("cRater_verification_url")).andReturn(verifyUrl); replay(appProperties); - cRaterService.getVerificationResponse(request); + cRaterService.getCRaterResponse(request); verify(appProperties); } @Test public void getBerkeleyScoringResponse_ShouldGetCRaterProperties() throws JSONException { + beforeBerkeley(); CRaterScoringRequest request = new CRaterScoringRequest(); request.setItemId("berkeley_" + itemId); request.setResponseId("1234567890"); request.setResponseText("hello"); expect(appProperties.getProperty("berkeley_cRater_scoring_url")).andReturn(berkeleyScoringUrl); replay(appProperties); - cRaterService.getScoringResponse(request); + cRaterService.getCRaterResponse(request); verify(appProperties); } @Test public void getBerkeleyVerificationResponse_ShouldGetCRaterProperties() throws JSONException { + beforeBerkeley(); CRaterVerificationRequest request = new CRaterVerificationRequest(); request.setItemId("berkeley_" + itemId); expect(appProperties.getProperty("berkeley_cRater_verification_url")).andReturn(berkeleyVerifyUrl); replay(appProperties); - cRaterService.getVerificationResponse(request); + cRaterService.getCRaterResponse(request); verify(appProperties); } } diff --git a/src/test/java/org/wise/vle/web/CRaterControllerTest.java b/src/test/java/org/wise/vle/web/CRaterControllerTest.java index e286232bf..6877bf72a 100644 --- a/src/test/java/org/wise/vle/web/CRaterControllerTest.java +++ b/src/test/java/org/wise/vle/web/CRaterControllerTest.java @@ -31,7 +31,7 @@ public void verifyItemId_ShouldReturnString() { CRaterVerificationRequest request = new CRaterVerificationRequest(); request.setItemId(itemId); try { - expect(cRaterService.getVerificationResponse(request)) + expect(cRaterService.getCRaterResponse(request)) .andReturn(createVerificationResponseString(itemId, true, trackingId, clientId)); replay(cRaterService); String response = controller.verifyItemId(request); @@ -59,7 +59,7 @@ public void scoreItemId_ShouldReturnString() { CRaterScoringRequest request = new CRaterScoringRequest(); request.setItemId(itemId); try { - expect(cRaterService.getScoringResponse(request)) + expect(cRaterService.getCRaterResponse(request)) .andReturn(createScoringResponseString(itemId, trackingId, clientId)); replay(cRaterService); String response = controller.scoreItem(request); diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties index a987d8da6..ded8e3dc4 100644 --- a/src/test/resources/application.properties +++ b/src/test/resources/application.properties @@ -64,6 +64,11 @@ cRater_scoring_url= cRater_client_id= cRater_password= +berkeley_cRater_verification_url= +berkeley_cRater_scoring_url= +berkeley_cRater_clientid= +berkeley_cRater_password= + ######### database properties ######### # Modify below as needed. From c56b2282c3e1b079c678facbbfd9361e3e5de642 Mon Sep 17 00:00:00 2001 From: Hiroki Terashima Date: Fri, 7 Mar 2025 16:15:29 -0800 Subject: [PATCH 4/5] refactor(CRaterService): Clean up formatting and improve UTF-8 handling in getCRaterResponse method --- .../domain/webservice/crater/CRaterService.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/wise/vle/domain/webservice/crater/CRaterService.java b/src/main/java/org/wise/vle/domain/webservice/crater/CRaterService.java index bc8f4e9c8..4d976422a 100644 --- a/src/main/java/org/wise/vle/domain/webservice/crater/CRaterService.java +++ b/src/main/java/org/wise/vle/domain/webservice/crater/CRaterService.java @@ -52,19 +52,18 @@ public class CRaterService { private Environment appProperties; /** - * Sends either student work (scoring request) or an item id (verification request) to + * Sends either student work (scoring request) or an item id (verification request) to * the CRater server * @param request the scoring or verification request from the client * @return scoring or verify response from CRater * @throws JSONException */ - public String getCRaterResponse(CRaterRequest request) - throws JSONException { + public String getCRaterResponse(CRaterRequest request) throws JSONException { String prefix = request.forBerkeleyEndpoint() ? "berkeley_" : ""; - + String clientIdVariable = prefix + "cRater_client_id"; String cRaterUrlVariable = prefix + request.getCRaterUrlVariableBase(); - + request.setCRaterClientId(appProperties.getProperty(clientIdVariable)); request.setCRaterUrl(appProperties.getProperty(cRaterUrlVariable)); @@ -83,8 +82,8 @@ private String post(CRaterRequest request) throws JSONException { try { String password = appProperties.getProperty( request.forBerkeleyEndpoint() ? "berkeley_cRater_password" : "cRater_password"); - String authHeader = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary( - ("extsyscrtr02dev:" + password).getBytes()); + String authHeader = "Basic " + javax.xml.bind.DatatypeConverter + .printBase64Binary(("extsyscrtr02dev:" + password).getBytes()); post.setHeader(HttpHeaders.AUTHORIZATION, authHeader); post.setHeader(HttpHeaders.CONTENT_TYPE, "application/json;charset=utf-8"); post.setEntity(new StringEntity(request.generateBodyData(), ContentType.APPLICATION_JSON)); @@ -92,7 +91,7 @@ private String post(CRaterRequest request) throws JSONException { if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { System.err.println("Method failed: " + response.getStatusLine()); } - return IOUtils.toString(response.getEntity().getContent()); + return IOUtils.toString(response.getEntity().getContent(), "UTF-8"); } catch (IOException e) { System.err.println("Fatal transport error: " + e.getMessage()); e.printStackTrace(); From 8a6183047d01154e2a46a43fe316e4747b224719 Mon Sep 17 00:00:00 2001 From: Hiroki Terashima Date: Fri, 7 Mar 2025 16:15:41 -0800 Subject: [PATCH 5/5] Correct typo in berkeley_cRater_client_id key across configuration files --- src/main/resources/application-dockerdev-sample.properties | 2 +- src/main/resources/application_sample.properties | 2 +- src/test/resources/application.properties | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/resources/application-dockerdev-sample.properties b/src/main/resources/application-dockerdev-sample.properties index 8ee46c11a..237f839c1 100644 --- a/src/main/resources/application-dockerdev-sample.properties +++ b/src/main/resources/application-dockerdev-sample.properties @@ -68,7 +68,7 @@ cRater_password= berkeley_cRater_verification_url= berkeley_cRater_scoring_url= -berkeley_cRater_clientid= +berkeley_cRater_client_id= berkeley_cRater_password= ######### database properties ######### diff --git a/src/main/resources/application_sample.properties b/src/main/resources/application_sample.properties index 6d0958f15..c8b5bb17e 100644 --- a/src/main/resources/application_sample.properties +++ b/src/main/resources/application_sample.properties @@ -68,7 +68,7 @@ cRater_password= berkeley_cRater_verification_url= berkeley_cRater_scoring_url= -berkeley_cRater_clientid= +berkeley_cRater_client_id= berkeley_cRater_password= ######### database properties ######### diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties index ded8e3dc4..3200bad51 100644 --- a/src/test/resources/application.properties +++ b/src/test/resources/application.properties @@ -66,7 +66,7 @@ cRater_password= berkeley_cRater_verification_url= berkeley_cRater_scoring_url= -berkeley_cRater_clientid= +berkeley_cRater_client_id= berkeley_cRater_password= ######### database properties #########