1818import java .net .URI ;
1919
2020import 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 ;
2227import org .slf4j .Logger ;
2328import 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