c0563fad71de28490a9a76876982249329a34df6
java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/StartTimeUpdateHandler.java
| ... | ... | @@ -67,7 +67,6 @@ public class StartTimeUpdateHandler extends UpdateHandler implements StartTimeCh |
| 67 | 67 | HashMap<String, String> additionalParameters = new HashMap<String, String>(); |
| 68 | 68 | additionalParameters.put(FIELD_RACE_START_TIME, String.valueOf(newStartTime.asMillis())); |
| 69 | 69 | URL startTimeUpdateURL = buildUpdateURL(additionalParameters); |
| 70 | - |
|
| 71 | 70 | logger.info("Using " + eraseSecurityRelatedValuesFromURL(startTimeUpdateURL.toString()) + " for the start time update!"); |
| 72 | 71 | HttpURLConnection connection = (HttpURLConnection) startTimeUpdateURL.openConnection(); |
| 73 | 72 | try { |
java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/UpdateHandler.java
| ... | ... | @@ -135,6 +135,12 @@ public class UpdateHandler { |
| 135 | 135 | parseAndLogResponse(reader); |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | + private void authenticate(HttpURLConnection connection) { |
|
| 139 | + if (Util.hasLength(tracTracApiToken)) { |
|
| 140 | + connection.addRequestProperty("Authorization", "Bearer " + tracTracApiToken); |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + |
|
| 138 | 144 | protected void parseAndLogResponse(BufferedReader reader) |
| 139 | 145 | throws IOException, ParseException, JsonDeserializationException { |
| 140 | 146 | Object responseBody = JSONValue.parseWithException(reader); |
| ... | ... | @@ -156,6 +162,7 @@ public class UpdateHandler { |
| 156 | 162 | |
| 157 | 163 | protected HttpURLConnection setConnectionProperties(HttpURLConnection connection) throws IOException { |
| 158 | 164 | return followRedirects(connection, c->{ |
| 165 | + authenticate(c); |
|
| 159 | 166 | c.setRequestMethod(HttpGetRequestMethod); |
| 160 | 167 | c.setDoOutput(false); |
| 161 | 168 | c.setUseCaches(false); |
| ... | ... | @@ -164,14 +171,13 @@ public class UpdateHandler { |
| 164 | 171 | |
| 165 | 172 | protected HttpURLConnection setConnectionPropertiesAndSendWithPayload(HttpURLConnection connection, String payload) throws IOException { |
| 166 | 173 | return followRedirects(connection, c-> { |
| 174 | + authenticate(c); |
|
| 167 | 175 | c.setRequestMethod(HttpPostRequestMethod); |
| 168 | 176 | c.setDoOutput(true); |
| 169 | 177 | c.setUseCaches(false); |
| 170 | 178 | c.setRequestProperty(ContentType, ContentTypeApplicationJson); |
| 171 | 179 | c.addRequestProperty(ContentLength, String.valueOf(payload.getBytes().length)); |
| 172 | - if (Util.hasLength(tracTracApiToken)) { |
|
| 173 | - c.addRequestProperty("Authorization", "Bearer " + tracTracApiToken); |
|
| 174 | - } |
|
| 180 | + authenticate(c); |
|
| 175 | 181 | DataOutputStream writer = new DataOutputStream(c.getOutputStream()); |
| 176 | 182 | writer.writeBytes(payload); |
| 177 | 183 | writer.flush(); |