Skip to content
This repository was archived by the owner on Feb 23, 2022. It is now read-only.

Commit 6e1cd7c

Browse files
committed
switched from jersey to apache wink for the rest client code to reduce external repository dependencies
1 parent f0dea13 commit 6e1cd7c

3 files changed

Lines changed: 48 additions & 50 deletions

File tree

http/pom.xml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,10 @@
7070
<scope>compile</scope>
7171
</dependency>
7272

73-
<!--
74-
This dependency comes from the java.net repository.
75-
http://download.java.net/maven/2
76-
-->
7773
<dependency>
78-
<groupId>com.sun.jersey</groupId>
79-
<artifactId>jersey-client</artifactId>
80-
<version>1.5</version>
74+
<groupId>org.apache.wink</groupId>
75+
<artifactId>wink-client</artifactId>
76+
<version>1.1.3-incubating</version>
8177
<type>jar</type>
8278
<scope>compile</scope>
8379
</dependency>

http/src/main/java/org/syphr/mythtv/http/backend/BackendFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ private static <T> T getInstance(Class<T> type, ConnectionManager connMan) throw
5151

5252
try
5353
{
54-
String mainAppPath = type.getSimpleName();
55-
version = Version.parse(connMan.getXml(mainAppPath, "version"));
54+
String mainAppName = type.getSimpleName();
55+
version = Version.parse(connMan.getXml(mainAppName, "version"));
5656
Class<T> clazz = (Class) Class.forName("org.syphr.mythtv.http.backend.impl."
5757
+ type.getSimpleName()
5858
+ version.getValue()
5959
.replace('.', '_'));
6060

61-
return clazz.getConstructor(ConnectionManager.class).newInstance(connMan.extend(URI.create(mainAppPath)));
61+
return clazz.getConstructor(ConnectionManager.class).newInstance(connMan.extend(URI.create("/" + mainAppName)));
6262
}
6363
catch (IllegalArgumentException e)
6464
{

http/src/main/java/org/syphr/mythtv/http/backend/ConnectionManager.java

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
import java.net.URI;
1919

2020
import javax.ws.rs.core.MediaType;
21+
import javax.ws.rs.core.UriBuilder;
2122

23+
import org.apache.wink.client.ClientRuntimeException;
24+
import org.apache.wink.client.ClientWebException;
25+
import org.apache.wink.client.Resource;
26+
import org.apache.wink.client.RestClient;
2227
import org.slf4j.Logger;
2328
import org.slf4j.LoggerFactory;
2429

25-
import com.sun.jersey.api.client.Client;
26-
import com.sun.jersey.api.client.ClientHandlerException;
27-
import com.sun.jersey.api.client.UniformInterfaceException;
28-
import com.sun.jersey.api.client.WebResource;
29-
3030
/**
3131
* This class manages HTTP requests to the backend with a convenient API to retrieve data
3232
* in multiple formats.
@@ -39,7 +39,7 @@ public class ConnectionManager
3939

4040
private final URI base;
4141

42-
private final Client client;
42+
private final RestClient client;
4343

4444
public ConnectionManager(String host, int port)
4545
{
@@ -48,10 +48,10 @@ public ConnectionManager(String host, int port)
4848

4949
public ConnectionManager(URI base)
5050
{
51-
this(base, Client.create());
51+
this(base, new RestClient());
5252
}
5353

54-
private ConnectionManager(URI base, Client client)
54+
private ConnectionManager(URI base, RestClient client)
5555
{
5656
this.base = base;
5757
this.client = client;
@@ -86,69 +86,71 @@ public ConnectionManager extend(URI newBase)
8686
// TODO need to take arguments
8787
public String getXml(String... paths) throws ContentException
8888
{
89-
WebResource wr = getWebResource(paths);
90-
logger.trace("Requesting XML from URI: {}", wr.getURI());
89+
Resource resource = getResource(paths);
90+
logger.trace("Requesting XML from URI: {}", resource.getUriBuilder().build());
9191

92-
return getData(MediaType.APPLICATION_XML_TYPE, wr);
92+
return getData(MediaType.APPLICATION_XML_TYPE, resource);
9393
}
9494

9595
// TODO need to take arguments
9696
public String getJson(String... paths) throws ContentException
9797
{
98-
WebResource wr = getWebResource(paths);
99-
logger.trace("Requesting JSON from URI: {}", wr.getURI());
98+
Resource resource = getResource(paths);
99+
logger.trace("Requesting JSON from URI: {}", resource.getUriBuilder().build());
100100

101-
return getData(MediaType.APPLICATION_JSON_TYPE, wr);
101+
return getData(MediaType.APPLICATION_JSON_TYPE, resource);
102102
}
103103

104104
public void put(String data, String... paths) throws ContentException
105105
{
106-
WebResource wr = getWebResource(paths);
107-
108-
// TODO encode data into uri or as payload
109-
110-
logger.trace("Posting to URI: {} :: {}", wr.getURI(), data);
111-
112-
try
113-
{
114-
wr.post();
115-
}
116-
catch (UniformInterfaceException e)
117-
{
118-
throw new ContentException(e.getMessage(), e);
119-
}
120-
catch (ClientHandlerException e)
121-
{
122-
throw new ContentException(e.getMessage(), e);
123-
}
106+
// Resource wr = getWebResource(paths);
107+
//
108+
// // TODO encode data into uri or as payload
109+
//
110+
// logger.trace("Posting to URI: {} :: {}", wr.getUriBuilder().build(), data);
111+
//
112+
// try
113+
// {
114+
// wr.post();
115+
// }
116+
// catch (ClientWebException e)
117+
// {
118+
// throw new ContentException(e.getMessage(), e);
119+
// }
120+
// catch (ClientRuntimeException e)
121+
// {
122+
// throw new ContentException(e.getMessage(), e);
123+
// }
124124
}
125125

126-
private WebResource getWebResource(String... paths)
126+
private Resource getResource(String... paths)
127127
{
128-
WebResource wr = client.resource(base);
128+
Resource resource = client.resource(base);
129+
UriBuilder uriBuilder = resource.getUriBuilder();
130+
129131
for (String path : paths)
130132
{
131-
wr = wr.path(path);
133+
uriBuilder.path(path);
132134
}
133135

134-
return wr;
136+
return resource;
135137
}
136138

137-
private String getData(MediaType mediaType, WebResource wr) throws ContentException
139+
private String getData(MediaType mediaType, Resource resource) throws ContentException
138140
{
139141
try
140142
{
141-
String data = wr.accept(mediaType).get(String.class);
143+
String data = resource.accept(mediaType).get(String.class);
142144

143145
logger.trace("Received response: {}", data);
144146

145147
return data;
146148
}
147-
catch (UniformInterfaceException e)
149+
catch (ClientWebException e)
148150
{
149151
throw new ContentException(e.getMessage(), e);
150152
}
151-
catch (ClientHandlerException e)
153+
catch (ClientRuntimeException e)
152154
{
153155
throw new ContentException(e.getMessage(), e);
154156
}

0 commit comments

Comments
 (0)