diff options
Diffstat (limited to 'eaaf_modules/eaaf_module_auth_sl20/src/main/java/at/gv/egiz/eaaf/modules/auth/sl20/utils/SL20HttpBindingUtils.java')
-rw-r--r-- | eaaf_modules/eaaf_module_auth_sl20/src/main/java/at/gv/egiz/eaaf/modules/auth/sl20/utils/SL20HttpBindingUtils.java | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/eaaf_modules/eaaf_module_auth_sl20/src/main/java/at/gv/egiz/eaaf/modules/auth/sl20/utils/SL20HttpBindingUtils.java b/eaaf_modules/eaaf_module_auth_sl20/src/main/java/at/gv/egiz/eaaf/modules/auth/sl20/utils/SL20HttpBindingUtils.java index c45245b1..f9ca7cf8 100644 --- a/eaaf_modules/eaaf_module_auth_sl20/src/main/java/at/gv/egiz/eaaf/modules/auth/sl20/utils/SL20HttpBindingUtils.java +++ b/eaaf_modules/eaaf_module_auth_sl20/src/main/java/at/gv/egiz/eaaf/modules/auth/sl20/utils/SL20HttpBindingUtils.java @@ -7,26 +7,26 @@ import java.text.MessageFormat; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.http.Header; -import org.apache.http.HttpEntity; -import org.apache.http.ParseException; -import org.apache.http.StatusLine; -import org.apache.http.client.ResponseHandler; -import org.apache.http.client.utils.URIBuilder; -import org.apache.http.entity.ContentType; -import org.apache.http.util.EntityUtils; + +import org.apache.hc.core5.http.ContentType; +import org.apache.hc.core5.http.Header; +import org.apache.hc.core5.http.HttpEntity; +import org.apache.hc.core5.http.io.HttpClientResponseHandler; +import org.apache.hc.core5.http.io.entity.EntityUtils; +import org.apache.hc.core5.http.message.StatusLine; +import org.apache.hc.core5.net.URIBuilder; import org.jose4j.base64url.Base64Url; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; +import com.fasterxml.jackson.core.JacksonException; import com.fasterxml.jackson.databind.JsonNode; import at.gv.egiz.eaaf.modules.auth.sl20.exceptions.SlCommandoParserException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import lombok.Data; import lombok.Getter; @@ -48,20 +48,20 @@ public class SL20HttpBindingUtils { * * @return {@link Sl20ResponseHolder} */ - public static ResponseHandler<Sl20ResponseHolder> sl20ResponseHandler() { + public static HttpClientResponseHandler<Sl20ResponseHolder> sl20ResponseHandler() { return response -> { try { - final int httpStatusCode = response.getStatusLine().getStatusCode(); + final int httpStatusCode = response.getCode(); if (httpStatusCode == HttpStatus.OK.value()) { if (response.getEntity().getContentType() == null) { throw new SlCommandoParserException("SL20 response contains NO ContentType"); } - final ContentType contentType = ContentType.getOrDefault(response.getEntity()); + final ContentType contentType = ContentType.parse(response.getEntity().getContentType()); if (!ContentType.APPLICATION_JSON.getMimeType().equals(contentType.getMimeType())) { log.error("SL20 response with statuscode: {} has wrong http ContentType: {}", - response.getStatusLine(), contentType); + response.getCode(), contentType); throw new SlCommandoParserException( "SL20 response with a wrong http ContentType: " + contentType); @@ -69,7 +69,7 @@ public class SL20HttpBindingUtils { //parse OK response from body return new Sl20ResponseHolder(parseSL20ResultFromResponse(response.getEntity()), - response.getStatusLine()); + new StatusLine(response)); } else if (httpStatusCode == HttpStatus.SEE_OTHER.value() || httpStatusCode == HttpStatus.TEMPORARY_REDIRECT.value()) { @@ -81,24 +81,24 @@ public class SL20HttpBindingUtils { final String sl20RespString = new URIBuilder(locationHeader[0].getValue()).getQueryParams().get(0).getValue(); return new Sl20ResponseHolder(JsonMapper.getMapper().readTree(Base64Url.decode(sl20RespString)), - response.getStatusLine()); + new StatusLine(response)); } else if ( httpStatusCode == HttpStatus.INTERNAL_SERVER_ERROR.value() || httpStatusCode == HttpStatus.UNAUTHORIZED.value() || httpStatusCode == HttpStatus.BAD_REQUEST.value()) { log.info("SL20 response with http-code: {}. Search for error message", httpStatusCode); - + String bodyMsg = "_EMPTY_"; try { //extract JSON body from defined http error-codes bodyMsg = EntityUtils.toString(response.getEntity()); log.info("SL20 response with http-code: {} and errorMsg: {}", httpStatusCode, bodyMsg); Sl20ResponseHolder holder = new Sl20ResponseHolder( - JsonMapper.getMapper().readTree(bodyMsg), response.getStatusLine()); + JsonMapper.getMapper().readTree(bodyMsg), new StatusLine(response)); return holder; - } catch (final IOException | ParseException e) { + } catch (final JacksonException e) { log.warn("SL20 response contains no valid JSON. Body msg: {}", bodyMsg, e); throw new SlCommandoParserException(MessageFormat.format( "SL20 response with http-code: {} and generic response-processing error: {}", @@ -115,12 +115,12 @@ public class SL20HttpBindingUtils { } } catch (SlCommandoParserException e) { - Sl20ResponseHolder holder = new Sl20ResponseHolder(null, response.getStatusLine()); + Sl20ResponseHolder holder = new Sl20ResponseHolder(null, new StatusLine(response)); holder.setError(e); return holder; } catch (final Exception e) { - Sl20ResponseHolder holder = new Sl20ResponseHolder(null, response.getStatusLine()); + Sl20ResponseHolder holder = new Sl20ResponseHolder(null, new StatusLine(response)); holder.setError( new SlCommandoParserException("SL20 response parsing FAILED! Reason: " + e.getMessage(), e)); return holder; |