Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.netflix.niws.client.http.HttpClientRequest;
- import com.netflix.niws.client.http.HttpClientRequest.Verb;
- import com.netflix.niws.client.http.HttpClientResponse;
- import com.netflix.niws.client.http.RestClient;
- import org.apache.http.entity.StringEntity;
- import org.apache.http.entity.ContentType;
- public class AddRSSCommand extends HystrixCommand<String> {
- private final String url;
- public AddRSSCommand() {
- super (Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(RSSConstants.HYSTRIX_RSS_MUTATIONS_GROUP))
- .andCommandKey(HystrixCommandKey.Factory.asKey(RSSConstants.HYSTRIX_RSS_ADD_COMMAND_KEY))
- .andThreadPoolKey(HystrixThreadPoolKey.Factory.asKey(RSSConstants.HYSTRIX_RSS_THREAD_POOL)));
- }
- @Override
- protected String run() {
- String jsonString = "{username: 'Hermione', password: 'Granger'}"
- StringEntity se = new StringEntity(jsonString, ContentType.APPLICATION_JSON);
- try {
- RestClient client = (RestClient) ClientFactory.getNamedClient(RSSConstants.MIDDLETIER_REST_CLIENT);
- HttpClientRequest request = HttpClientRequest
- .newBuilder()
- .setVerb(Verb.POST)
- .setUri(new URI("/"
- + RSSConstants.MIDDLETIER_WEB_RESOURCE_ROOT_PATH
- + RSSConstants.RSS_ENTRY_POINT
- + "?url=" + url))
- .setEntity(se);
- .build();
- HttpClientResponse response = client.executeWithLoadBalancer(request);
- return IOUtils.toString(response.getRawEntity(), Charsets.UTF_8);
- } catch (Exception exc) {
- throw new RuntimeException("Exception occurred when adding a RSS feed", exc);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement