extracted parsers and rest templates appropriately

pull/324/merge
Justin Richer 2013-04-19 14:22:21 -04:00
parent cf39b49657
commit 0b0e52b7a3
2 changed files with 7 additions and 10 deletions

View File

@ -58,10 +58,11 @@ public class DynamicServerConfigurationService implements ServerConfigurationSer
private class OpenIDConnectServiceConfigurationFetcher extends CacheLoader<String, ServerConfiguration> { private class OpenIDConnectServiceConfigurationFetcher extends CacheLoader<String, ServerConfiguration> {
private HttpClient httpClient = new DefaultHttpClient(); private HttpClient httpClient = new DefaultHttpClient();
private HttpComponentsClientHttpRequestFactory httpFactory = new HttpComponentsClientHttpRequestFactory(httpClient); private HttpComponentsClientHttpRequestFactory httpFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
private RestTemplate restTemplate = new RestTemplate(httpFactory); private JsonParser parser = new JsonParser();
@Override @Override
public ServerConfiguration load(String issuer) throws Exception { public ServerConfiguration load(String issuer) throws Exception {
RestTemplate restTemplate = new RestTemplate(httpFactory);
// data holder // data holder
ServerConfiguration conf = new ServerConfiguration(); ServerConfiguration conf = new ServerConfiguration();
@ -72,7 +73,7 @@ public class DynamicServerConfigurationService implements ServerConfigurationSer
// fetch the value // fetch the value
String jsonString = restTemplate.getForObject(url, String.class); String jsonString = restTemplate.getForObject(url, String.class);
JsonElement parsed = new JsonParser().parse(jsonString); JsonElement parsed = parser.parse(jsonString);
if (parsed.isJsonObject()) { if (parsed.isJsonObject()) {
JsonObject o = parsed.getAsJsonObject(); JsonObject o = parsed.getAsJsonObject();

View File

@ -3,8 +3,6 @@
*/ */
package org.mitre.openid.connect.client.service.impl; package org.mitre.openid.connect.client.service.impl;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -16,7 +14,6 @@ import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.client.DefaultHttpClient;
import org.mitre.openid.connect.client.model.IssuerServiceResponse; import org.mitre.openid.connect.client.model.IssuerServiceResponse;
import org.mitre.openid.connect.client.service.IssuerService; import org.mitre.openid.connect.client.service.IssuerService;
import org.mitre.openid.connect.config.ServerConfiguration;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
@ -171,9 +168,8 @@ public class WebfingerIssuerService implements IssuerService {
private class WebfingerIssuerFetcher extends CacheLoader<NormalizedURI, String> { private class WebfingerIssuerFetcher extends CacheLoader<NormalizedURI, String> {
private HttpClient httpClient = new DefaultHttpClient(); private HttpClient httpClient = new DefaultHttpClient();
private HttpComponentsClientHttpRequestFactory httpFactory = new HttpComponentsClientHttpRequestFactory(httpClient); private HttpComponentsClientHttpRequestFactory httpFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
/* (non-Javadoc) private JsonParser parser = new JsonParser();
* @see com.google.common.cache.CacheLoader#load(java.lang.Object)
*/
@Override @Override
public String load(NormalizedURI key) throws Exception { public String load(NormalizedURI key) throws Exception {
@ -196,7 +192,7 @@ public class WebfingerIssuerService implements IssuerService {
// TODO: catch and handle HTTP errors // TODO: catch and handle HTTP errors
JsonElement json = new JsonParser().parse(webfingerResponse); JsonElement json = parser.parse(webfingerResponse);
// TODO: catch and handle JSON errors // TODO: catch and handle JSON errors