-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move torrent client to the separate service
- Loading branch information
galushko
committed
Oct 18, 2023
1 parent
bf1e421
commit fb5749a
Showing
3 changed files
with
59 additions
and
40 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
core/src/main/java/com/halushko/kinocat/core/web/ApiResponce.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.halushko.kinocat.core.web; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.http.Header; | ||
import org.apache.http.HttpResponse; | ||
import org.apache.http.util.EntityUtils; | ||
|
||
import java.io.IOException; | ||
|
||
@Slf4j | ||
public class ApiResponce { | ||
private final HttpResponse httpResponse; | ||
public ApiResponce(HttpResponse httpResponse) { | ||
if (httpResponse == null) { | ||
log.debug("[ApiResponce] Responce is null"); | ||
} | ||
this.httpResponse = httpResponse; | ||
} | ||
|
||
public String getHeader(String headerKey) { | ||
if (httpResponse == null) { | ||
log.debug("[getHeader] Responce is null. Can't get header [{}]", headerKey); | ||
return ""; | ||
} | ||
Header header = httpResponse.getFirstHeader(headerKey); | ||
String value = header.getValue(); | ||
log.debug("[getHeader] Responce header {}=[{}]", headerKey, value); | ||
return value; | ||
} | ||
|
||
public String getBody() { | ||
if (httpResponse == null) { | ||
log.debug("[getBody] Responce is null. Can't get body"); | ||
return ""; | ||
} | ||
try { | ||
String body = EntityUtils.toString(httpResponse.getEntity()); | ||
log.debug("[getBody] Responce body=[{}]", body); | ||
return body; | ||
} catch (IOException e) { | ||
log.error("[getBody] Can't get body from responce", e); | ||
} | ||
return ""; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters