-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
258 additions
and
38 deletions.
There are no files selected for viewing
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
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
48 changes: 48 additions & 0 deletions
48
src/main/java/mServer/crawler/sender/newsearch/ZDFConfigurationDTO.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,48 @@ | ||
package mServer.crawler.sender.newsearch; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* A Data-Transfer-Object to transfer the ZDF configuration information. | ||
*/ | ||
public class ZDFConfigurationDTO implements Serializable | ||
{ | ||
private static final long serialVersionUID = -445386435734116784L; | ||
private String apiToken; | ||
|
||
/** | ||
* @param aApiToken The ZDF api authentication token. | ||
*/ | ||
public ZDFConfigurationDTO(final String aApiToken) | ||
{ | ||
setApiToken(aApiToken); | ||
} | ||
|
||
public String getApiToken() | ||
{ | ||
return apiToken; | ||
} | ||
|
||
public void setApiToken(final String aApiToken) | ||
{ | ||
apiToken = aApiToken; | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) | ||
{ | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
final ZDFConfigurationDTO that = (ZDFConfigurationDTO) o; | ||
|
||
return getApiToken() != null ? getApiToken().equals(that.getApiToken()) : that.getApiToken() == null; | ||
} | ||
|
||
@Override | ||
public int hashCode() | ||
{ | ||
return getApiToken() != null ? getApiToken().hashCode() : 0; | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/mServer/crawler/sender/newsearch/ZDFConfigurationDTODeserializer.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,33 @@ | ||
package mServer.crawler.sender.newsearch; | ||
|
||
import com.google.gson.*; | ||
import mSearch.tool.Log; | ||
|
||
import java.lang.reflect.Type; | ||
|
||
/** | ||
* A JSON deserializer to gather the needed information for a {@link ZDFConfigurationDTO}. | ||
*/ | ||
public class ZDFConfigurationDTODeserializer implements JsonDeserializer<ZDFConfigurationDTO> | ||
{ | ||
|
||
public static final String JSON_ELEMENT_API_TOKEN = "apiToken"; | ||
|
||
@Override | ||
public ZDFConfigurationDTO deserialize(final JsonElement aJsonElement, final Type aTypeOfT, final JsonDeserializationContext aJsonDeserializationContext) throws JsonParseException | ||
{ | ||
ZDFConfigurationDTO dto = null; | ||
try { | ||
JsonObject targetObject = aJsonElement.getAsJsonObject(); | ||
JsonElement apiTokenElement = targetObject.get(JSON_ELEMENT_API_TOKEN); | ||
|
||
String apiToken = apiTokenElement.getAsString(); | ||
|
||
dto = new ZDFConfigurationDTO(apiToken); | ||
} catch (Exception ex) { | ||
Log.errorLog(496583255, ex); | ||
} | ||
|
||
return dto; | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/mServer/crawler/sender/newsearch/ZDFConfigurationLoader.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,60 @@ | ||
package mServer.crawler.sender.newsearch; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import com.sun.jersey.api.client.Client; | ||
import com.sun.jersey.api.client.ClientResponse; | ||
import com.sun.jersey.api.client.WebResource; | ||
import mSearch.tool.Log; | ||
|
||
/** | ||
* A simple singelton to read the ZDF configuration just once per runtime. | ||
*/ | ||
public class ZDFConfigurationLoader | ||
{ | ||
public static final String ZDF_CONFIGURATION_URL = "https://www.zdf.de/ZDFplayer/configs/zdf/zdf2016/configuration.json"; | ||
private static final String USER_AGENT = "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:50.0) Gecko/20100101 Firefox/50.0"; | ||
private static final String HEADER_USER_AGENT = "user-agent"; | ||
private static ZDFConfigurationLoader instance; | ||
|
||
private ZDFConfigurationDTO config; | ||
|
||
private ZDFConfigurationLoader() | ||
{ | ||
config = null; | ||
} | ||
|
||
public static ZDFConfigurationLoader getInstance() | ||
{ | ||
if (instance == null) | ||
{ | ||
instance = new ZDFConfigurationLoader(); | ||
} | ||
return instance; | ||
} | ||
|
||
public ZDFConfigurationDTO loadConfig() | ||
{ | ||
if (config == null) | ||
{ | ||
WebResource webResource = Client.create().resource(ZDF_CONFIGURATION_URL); | ||
ClientResponse response = webResource | ||
.header(HEADER_USER_AGENT, USER_AGENT) | ||
.get(ClientResponse.class); | ||
|
||
if (response.getStatus() == 200) | ||
{ | ||
Gson gson = new GsonBuilder() | ||
.registerTypeAdapter(ZDFConfigurationDTO.class, new ZDFConfigurationDTODeserializer()) | ||
.create(); | ||
config = gson.fromJson(response.getEntity(String.class), ZDFConfigurationDTO.class); | ||
} else | ||
{ | ||
Log.errorLog(496583428, "Lade der Config Seite " + webResource.getURI() + " fehlgeschlagen: " + response.getStatus()); | ||
config = new ZDFConfigurationDTO(""); | ||
} | ||
|
||
} | ||
return config; | ||
} | ||
} |
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