org.restlet.Request Java Examples

The following examples show how to use org.restlet.Request. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AdminTestHelper.java    From helix with Apache License 2.0 7 votes vote down vote up
public static ZNRecord post(Client client, String url, String body)
    throws IOException {
  Reference resourceRef = new Reference(url);
  Request request = new Request(Method.POST, resourceRef);

  request.setEntity(body, MediaType.APPLICATION_ALL);

  Response response = client.handle(request);
  Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
  Representation result = response.getEntity();
  StringWriter sw = new StringWriter();

  if (result != null) {
    result.write(sw);
  }
  String responseStr = sw.toString();
  Assert.assertTrue(responseStr.toLowerCase().indexOf("error") == -1);
  Assert.assertTrue(responseStr.toLowerCase().indexOf("exception") == -1);

  ObjectMapper mapper = new ObjectMapper();
  ZNRecord record = mapper.readValue(new StringReader(responseStr), ZNRecord.class);
  return record;
}
 
Example #2
Source File: DefaultResourceFactoryImpl.java    From attic-polygene-java with Apache License 2.0 6 votes vote down vote up
@Override
public T create( Class<T> entityType, Request request, Response response, Context context )
{
    final Map<String, Object> attributes = request.getAttributes();
    String id = (String) attributes.get( "id" );

    ValueBuilder<T> builder = vbf.newValueBuilderWithState(
        resourceType,
        descriptor -> findValue( attributes, descriptor ),
        descriptor -> null,
        descriptor -> null,
        descriptor -> null
    );
    //noinspection unchecked
    ServerResource.Parameters<T> params = builder.prototypeFor( ServerResource.Parameters.class );
    params.id().set( id );
    params.entityType().set( entityType );
    params.context().set( this.context );
    params.request().set( request );
    params.router().set( router );
    params.response().set( response );
    return builder.newInstance();
}
 
Example #3
Source File: AdminTestHelper.java    From helix with Apache License 2.0 6 votes vote down vote up
public static ZNRecord get(Client client, String url) throws IOException {
  Reference resourceRef = new Reference(url);
  Request request = new Request(Method.GET, resourceRef);
  Response response = client.handle(request);
  Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
  Representation result = response.getEntity();
  StringWriter sw = new StringWriter();
  result.write(sw);

  String responseStr = sw.toString();
  Assert.assertTrue(responseStr.toLowerCase().indexOf("error") == -1);
  Assert.assertTrue(responseStr.toLowerCase().indexOf("exception") == -1);
  ObjectMapper mapper = new ObjectMapper();
  ZNRecord record = mapper.readValue(new StringReader(responseStr), ZNRecord.class);
  return record;
}
 
Example #4
Source File: TopicPartitionBlacklistRestletResourceTest.java    From uReplicator with Apache License 2.0 6 votes vote down vote up
@Test
public void testGet() {
  EasyMock.reset(_helixMirrorMakerManager);
  TopicPartition tp = new TopicPartition("test", 3);
  Set<TopicPartition> blacklist = new HashSet<>();
  blacklist.add(tp);
  EasyMock.expect(_helixMirrorMakerManager.getTopicPartitionBlacklist()).andReturn(null).andReturn(blacklist);
  EasyMock.replay(_helixMirrorMakerManager);

  Request request = ControllerRequestURLBuilder.baseUrl(REQUEST_URL)
      .getBlacklistRequestUrl();
  Response response = RestTestBase.HTTP_CLIENT.handle(request);
  Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
  Assert.assertEquals(response.getEntityAsText(), "{}");

  response = RestTestBase.HTTP_CLIENT.handle(request);
  Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
  Assert.assertEquals(response.getEntityAsText(), "{\"blacklist\":[{\"partition\":3,\"topic\":\"test\"}]}");
}
 
Example #5
Source File: GeoWaveOperationServiceWrapperTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Test
public void getMethodReturnsSuccessStatus() throws Exception {

  // Rarely used Teapot Code to check.
  final Boolean successStatusIs200 = true;

  final ServiceEnabledCommand operation = mockedOperation(HttpMethod.GET, successStatusIs200);

  classUnderTest = new GeoWaveOperationServiceWrapper(operation, null);
  classUnderTest.setResponse(new Response(null));
  classUnderTest.setRequest(new Request(Method.GET, "foo.bar"));
  classUnderTest.restGet();
  Assert.assertEquals(
      successStatusIs200,
      classUnderTest.getResponse().getStatus().equals(Status.SUCCESS_OK));
}
 
Example #6
Source File: FormRequestWriter.java    From attic-polygene-java with Apache License 2.0 6 votes vote down vote up
@Override
public boolean writeRequest(Object requestObject, Request request) throws ResourceException
{
   if (requestObject instanceof Form)
   {
      // Form as query parameters
      if (request.getMethod().equals(Method.GET))
         request.getResourceRef().setQuery(((Form)requestObject).getQueryString());
      else
         request.setEntity(((Form)requestObject).getWebRepresentation(CharacterSet.UTF_8));

      return true;
   }

   return false;
}
 
Example #7
Source File: RestApiServer.java    From floodlight_with_topoguard with Apache License 2.0 6 votes vote down vote up
@Override
public Restlet createInboundRoot() {
    Router baseRouter = new Router(context);
    baseRouter.setDefaultMatchingMode(Template.MODE_STARTS_WITH);
    for (RestletRoutable rr : restlets) {
        baseRouter.attach(rr.basePath(), rr.getRestlet(context));
    }

    Filter slashFilter = new Filter() {            
        @Override
        protected int beforeHandle(Request request, Response response) {
            Reference ref = request.getResourceRef();
            String originalPath = ref.getPath();
            if (originalPath.contains("//"))
            {
                String newPath = originalPath.replaceAll("/+", "/");
                ref.setPath(newPath);
            }
            return Filter.CONTINUE;
        }

    };
    slashFilter.setNext(baseRouter);
    
    return slashFilter;
}
 
Example #8
Source File: TestProjectImportResource.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testGitHub() {
	Client client = new Client(Protocol.HTTP);
	Request request = new Request(Method.POST, "http://localhost:8182/projects/import");
	
	ObjectMapper mapper = new ObjectMapper();
	ObjectNode n = mapper.createObjectNode();
	n.put("url", "https://github.com/jrwilliams/gif-hook");
	
	request.setEntity(n.toString(), MediaType.APPLICATION_JSON);
	
	Response response = client.handle(request);
	
	validateResponse(response, 201);
	
	System.out.println(response.getEntityAsText());
}
 
Example #9
Source File: FoxbpmStatusService.java    From FoxBPM with Apache License 2.0 6 votes vote down vote up
public Status getStatus(Throwable throwable, Request request, Response response) {
	Status status = null;
	if (throwable instanceof JsonMappingException && throwable.getCause() != null) {
		status = getSpecificStatus(throwable.getCause(), request, response);
	}
	if (status == null) {
		Throwable causeThrowable = null;
		if (throwable.getCause() != null && throwable.getCause() instanceof FoxBPMException) {
			causeThrowable = throwable.getCause();
		} else {
			causeThrowable = throwable;
		}
		status = getSpecificStatus(causeThrowable, request, response);
	}
	return status != null ? status : Status.SERVER_ERROR_INTERNAL;
}
 
Example #10
Source File: ContextRestlet.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
private String getUsecaseName( Request request )
{
    if( request.getMethod().equals( org.restlet.data.Method.DELETE ) )
    {
        return "delete";
    }
    else
    {
        return request.getResourceRef().getLastSegment();
    }
}
 
Example #11
Source File: GeoWaveOperationFinder.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
public ServerResource create(
    final Class<? extends ServerResource> targetClass,
    final Request request,
    final Response response) {
  try {
    return new GeoWaveOperationServiceWrapper<>(
        operation.getClass().newInstance(),
        defaultConfigFile);
  } catch (InstantiationException | IllegalAccessException e) {
    getLogger().log(Level.SEVERE, "Unable to instantiate Service Resource", e);
    return null;
  }
}
 
Example #12
Source File: FoxbpmStatusService.java    From FoxBPM with Apache License 2.0 5 votes vote down vote up
public Representation getRepresentation(Status status, Request request, Response response) {
	if (status != null && status.isError()) {
		RestError error = new RestError();
		error.setStatusCode(status.getCode());
		error.setErrorMessage(status.getDescription());
		return new JacksonRepresentation<RestError>(error);
	} else {
		return super.getRepresentation(status, request, response);
	}
}
 
Example #13
Source File: AbstractRestApplication.java    From FoxBPM with Apache License 2.0 5 votes vote down vote up
public String authenticate(Request request, Response response) {
	if (!request.getClientInfo().isAuthenticated()) {
		authenticator.challenge(response, false);
		return null;
	}
	return request.getClientInfo().getUser().getIdentifier();
}
 
Example #14
Source File: ContextResource.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
@Override
public final void handle( Request request, Response response )
{
    ObjectSelection objectSelection = current();

    // Check constraints for this resource
    if( !constraints.isValid( getClass(), objectSelection, module ) )
    {
        throw new ResourceException( Status.CLIENT_ERROR_FORBIDDEN );
    }

    // Find remaining segments
    List<String> segments = getSegments();

    if( segments.size() > 0 )
    {
        String segment = segments.remove( 0 );

        if( segments.size() > 0 )
        {
            handleSubResource( segment );
        }
        else
        {
            handleResource( segment );
        }
    }
}
 
Example #15
Source File: AuthTokenVerifier.java    From microservices-comparison with Apache License 2.0 5 votes vote down vote up
@Override
public int verify(Request request, Response response) {
    final String token;

    try {
        ChallengeResponse cr = request.getChallengeResponse();
        if (cr == null) {
            return RESULT_MISSING;
        } else if (ChallengeScheme.HTTP_OAUTH_BEARER.equals(cr.getScheme())) {
            final String bearer = cr.getRawValue();
            if (bearer == null || bearer.isEmpty()) {
                return RESULT_MISSING;
            }
            token = bearer;
        } else {
            return RESULT_UNSUPPORTED;
        }
    } catch (Exception ex) {
        return RESULT_INVALID;
    }

    Try<User> user = accessTokenVerificationCommandFactory.createVerificationCommand(token).executeCommand();
    return user.map(u -> {
        org.restlet.security.User restletUser = createRestletUser(u);
        request.getClientInfo().setUser(restletUser);
        request.getAttributes().put("token", token);
        return RESULT_VALID;
    }).orElse(RESULT_INVALID);
}
 
Example #16
Source File: RestApiServer.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
public void run(FloodlightModuleContext fmlContext, String restHost, int restPort) {
    setStatusService(new StatusService() {
        @Override
        public Representation getRepresentation(Status status,
                                                Request request,
                                                Response response) {
            return new JacksonRepresentation<Status>(status);
        }                
    });
    
    // Add everything in the module context to the rest
    for (Class<? extends IFloodlightService> s : fmlContext.getAllServices()) {
        if (logger.isTraceEnabled()) {
            logger.trace("Adding {} for service {} into context",
                         s.getCanonicalName(), fmlContext.getServiceImpl(s));
        }
        context.getAttributes().put(s.getCanonicalName(), 
                                    fmlContext.getServiceImpl(s));
    }
    
    // Start listening for REST requests
    try {
        final Component component = new Component();
        if (restHost == null) {
        	component.getServers().add(Protocol.HTTP, restPort);
        } else {
        	component.getServers().add(Protocol.HTTP, restHost, restPort);
        }
        component.getClients().add(Protocol.CLAP);
        component.getDefaultHost().attach(this);
        component.start();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example #17
Source File: PolygeneEntityRestlet.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
private void post( final Request request, final Response response )
{
    execute( request, response, resource -> {
        RestForm form = createRestForm( request );
        RestLink link = resource.post( form );
        response.setLocationRef( link.path().get() );
        response.setStatus( Status.REDIRECTION_SEE_OTHER );
    } );
}
 
Example #18
Source File: TestClusterManagementWebapp.java    From helix with Apache License 2.0 5 votes vote down vote up
private ZNRecord get(Client client, String url, ObjectMapper mapper) throws Exception {
  Request request = new Request(Method.GET, new Reference(url));
  Response response = client.handle(request);
  Representation result = response.getEntity();
  StringWriter sw = new StringWriter();
  result.write(sw);
  String responseStr = sw.toString();
  Assert.assertTrue(responseStr.toLowerCase().indexOf("error") == -1);
  Assert.assertTrue(responseStr.toLowerCase().indexOf("exception") == -1);

  ZNRecord record = mapper.readValue(new StringReader(responseStr), ZNRecord.class);
  return record;
}
 
Example #19
Source File: TestRestManager.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testResolveResourceIdDecodeUrlEntities () throws Exception {
  Request testRequest = new Request();
  Reference rootRef = new Reference("http://solr.apache.org/");
  testRequest.setRootRef(rootRef);

  Reference resourceRef = new Reference("http://solr.apache.org/schema/analysis/synonyms/de/%C3%84ndern");
  testRequest.setResourceRef(resourceRef);

  String resourceId = RestManager.ManagedEndpoint.resolveResourceId(testRequest);
  assertEquals(resourceId, "/schema/analysis/synonyms/de/Ă„ndern");
}
 
Example #20
Source File: ManagerRequestURLBuilder.java    From uReplicator with Apache License 2.0 5 votes vote down vote up
public Request getTopicDeleteRequestUrl(String topic, String src, String dst) {
  String requestUrl = StringUtils.join(new String[]{
      _baseUrl, "/topics/", topic, "?src=", src, "&dst=", dst
  });

  Request request = new Request(Method.DELETE, requestUrl);
  return request;
}
 
Example #21
Source File: ExtensionMediaTypeFilter.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
@Override
protected int beforeHandle( Request request, Response response )
{
    List<String> segments = request.getResourceRef().getSegments();
    if( segments.get( segments.size() - 1 ).equals( "" ) )
    {
        return Filter.CONTINUE;
    }

    String extensions = request.getResourceRef().getExtensions();
    if( extensions != null )
    {
        int idx = extensions.lastIndexOf( "." );
        if( idx != -1 )
        {
            extensions = extensions.substring( idx + 1 );
        }

        MetadataService metadataService = getApplication().getMetadataService();
        Metadata metadata = metadataService.getMetadata( extensions );
        if( metadata != null && metadata instanceof MediaType )
        {
            request.getClientInfo()
                .setAcceptedMediaTypes( Collections.singletonList( new Preference<MediaType>( (MediaType) metadata ) ) );
            String path = request.getResourceRef().getPath();
            path = path.substring( 0, path.length() - extensions.length() - 1 );
            request.getResourceRef().setPath( path );
        }
    }

    return Filter.CONTINUE;
}
 
Example #22
Source File: TestHelixAdminScenariosRest.java    From helix with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetResources() throws IOException {
  final String clusterName = "TestTagAwareness_testGetResources";
  final String TAG = "tag";
  final String URL_BASE =
      "http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName + "/resourceGroups";

  _gSetupTool.addCluster(clusterName, true);
  HelixAdmin admin = _gSetupTool.getClusterManagementTool();

  // Add a tagged resource
  IdealState taggedResource = new IdealState("taggedResource");
  taggedResource.setInstanceGroupTag(TAG);
  taggedResource.setStateModelDefRef("OnlineOffline");
  admin.addResource(clusterName, taggedResource.getId(), taggedResource);

  // Add an untagged resource
  IdealState untaggedResource = new IdealState("untaggedResource");
  untaggedResource.setStateModelDefRef("OnlineOffline");
  admin.addResource(clusterName, untaggedResource.getId(), untaggedResource);

  // Now make a REST call for all resources
  Reference resourceRef = new Reference(URL_BASE);
  Request request = new Request(Method.GET, resourceRef);
  Response response = _gClient.handle(request);
  ZNRecord responseRecord =
      ClusterRepresentationUtil.JsonToObject(ZNRecord.class, response.getEntityAsText());

  // Ensure that the tagged resource has information and the untagged one doesn't
  Assert.assertNotNull(responseRecord.getMapField("ResourceTags"));
  Assert
      .assertEquals(TAG, responseRecord.getMapField("ResourceTags").get(taggedResource.getId()));
  Assert.assertFalse(responseRecord.getMapField("ResourceTags").containsKey(
      untaggedResource.getId()));
}
 
Example #23
Source File: ManagerRequestURLBuilder.java    From uReplicator with Apache License 2.0 5 votes vote down vote up
public Request getTopicCreationRequestUrl(String topic, String src, String dst) {
  String requestUrl = StringUtils.join(new String[]{
      _baseUrl, "/topics/", topic, "?src=", src, "&dst=", dst
  });

  Request request = new Request(Method.POST, requestUrl);

  return request;
}
 
Example #24
Source File: ControllerStarterTest.java    From uReplicator with Apache License 2.0 5 votes vote down vote up
@Test
public void testPut() {
  // Create topic
  Request request = ControllerRequestURLBuilder.baseUrl(REQUEST_URL)
      .getTopicCreationRequestUrl("testTopic2", 8);
  Response response = HTTP_CLIENT.handle(request);
  Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
  Assert.assertEquals(response.getEntityAsText(),
      "Successfully add new topic: {topic: testTopic2, partition: 8, pipeline: null}");
  Assert.assertTrue(ZK_CLIENT.exists("/" + HELIX_CLUSTER_NAME + "/CONFIGS/RESOURCE/testTopic2"));

  // Expand topic
  request = ControllerRequestURLBuilder.baseUrl(REQUEST_URL)
      .getTopicExpansionRequestUrl("testTopic2", 16);
  response = HTTP_CLIENT.handle(request);
  Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
  Assert.assertEquals(response.getEntityAsText(),
      "Successfully expand topic: {topic: testTopic2, partition: 16, pipeline: null}");

  // Expand non-existed topic
  request = ControllerRequestURLBuilder.baseUrl(REQUEST_URL)
      .getTopicExpansionRequestUrl("testTopic22", 16);
  response = HTTP_CLIENT.handle(request);
  Assert.assertEquals(response.getStatus(), Status.CLIENT_ERROR_NOT_FOUND);
  Assert.assertEquals(response.getEntityAsText(),
      "Failed to expand topic, topic: testTopic22 is not existed!");

  // Delete topic
  request =
      ControllerRequestURLBuilder.baseUrl(REQUEST_URL).getTopicDeleteRequestUrl("testTopic2");
  response = HTTP_CLIENT.handle(request);
  Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
  Assert.assertEquals(response.getEntityAsText(),
      "Successfully finished delete topic: testTopic2");

}
 
Example #25
Source File: ControllerStarterTest.java    From uReplicator with Apache License 2.0 5 votes vote down vote up
@Test
public void testPost() {
  // Create topic
  Request request = ControllerRequestURLBuilder.baseUrl(REQUEST_URL)
      .getTopicCreationRequestUrl("testTopic1", 16);
  Response response = HTTP_CLIENT.handle(request);
  Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
  Assert.assertEquals(response.getEntityAsText(),
      "Successfully add new topic: {topic: testTopic1, partition: 16, pipeline: null}");
  Assert.assertTrue(ZK_CLIENT.exists("/" + HELIX_CLUSTER_NAME + "/CONFIGS/RESOURCE/testTopic1"));

  // Create existed topic
  request = ControllerRequestURLBuilder.baseUrl(REQUEST_URL)
      .getTopicCreationRequestUrl("testTopic1", 16);
  response = HTTP_CLIENT.handle(request);
  Assert.assertEquals(response.getStatus(), Status.CLIENT_ERROR_NOT_FOUND);
  Assert.assertEquals(response.getEntityAsText(),
      "Failed to add new topic: testTopic1, it is already existed!");

  // Delete topic
  request =
      ControllerRequestURLBuilder.baseUrl(REQUEST_URL).getTopicDeleteRequestUrl("testTopic1");
  response = HTTP_CLIENT.handle(request);
  Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
  Assert.assertEquals(response.getEntityAsText(),
      "Successfully finished delete topic: testTopic1");

}
 
Example #26
Source File: AdminRestletResourceTest.java    From uReplicator with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetControllerWorkload() {
  EasyMock.reset(_helixMirrorMakerManager);
  EasyMock.expect(_helixMirrorMakerManager.getCurrentServingInstance()).andReturn(fakeItphList);
  EasyMock.expect(_helixMirrorMakerManager.getWorkloadInfoRetriever()).andReturn(_workloadInfoRetriever).anyTimes();

  EasyMock.expect(_workloadInfoRetriever.isInitialized()).andReturn(true);
  EasyMock.expect(_workloadInfoRetriever.topicWorkload(fakeTopics.get(0))).andReturn(fakeWorkload1).times(2);
  EasyMock.expect(_workloadInfoRetriever.topicWorkload(fakeTopics.get(1))).andReturn(fakeWorkload2).times(2);

  EasyMock.expect(_helixMirrorMakerManager.calculateLagTime(faketp1)).andReturn(null);
  EasyMock.expect(_helixMirrorMakerManager.calculateLagTime(faketp2)).andReturn(null);
  EasyMock.expect(_helixMirrorMakerManager.calculateLagTime(faketp3)).andReturn(null);
  faketplag.setLagTime(1243L);
  EasyMock.expect(_helixMirrorMakerManager.calculateLagTime(faketp4)).andReturn(faketplag);

  EasyMock.expect(_helixMirrorMakerManager.getMaxDedicatedInstancesRatio()).andReturn(0.2);
  EasyMock.expect(_helixMirrorMakerManager.getMaxWorkloadPerWorkerBytes()).andReturn(700.0);


  EasyMock.replay(_helixMirrorMakerManager, _workloadInfoRetriever);


  Request request = ControllerRequestURLBuilder.baseUrl(REQUEST_URL)
      .getWorkloadInfoUrl();
  Response response = RestTestBase.HTTP_CLIENT.handle(request);
  Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);

  ControllerWorkloadInfo controllerWorkloadInfo = JSONObject.parseObject(response.getEntityAsText(), ControllerWorkloadInfo.class);
  Assert.assertEquals((int) controllerWorkloadInfo.getTopicWorkload().getBytesPerSecond(), 1264);

  Assert.assertEquals(controllerWorkloadInfo.getWorkerInstances().size(), 2);
  Assert.assertEquals(controllerWorkloadInfo.getNumOfLaggingWorkers(), 1);
  Assert.assertEquals(controllerWorkloadInfo.getNumOfExpectedWorkers(), 4);
}
 
Example #27
Source File: TopicPartitionBlacklistRestletResourceTest.java    From uReplicator with Apache License 2.0 5 votes vote down vote up
@Test
public void testPost() {
  EasyMock.reset(_helixMirrorMakerManager);

  // input validation
  Request request = ControllerRequestURLBuilder.baseUrl(REQUEST_URL)
      .postBlacklistRequestUrl("testTopic", "2", null);
  Response response = RestTestBase.HTTP_CLIENT.handle(request);
  Assert.assertEquals(response.getStatus(), Status.CLIENT_ERROR_BAD_REQUEST);
  Assert.assertEquals(response.getEntityAsText(), "Invalid parameter opt");


  request = ControllerRequestURLBuilder.baseUrl(REQUEST_URL)
      .postBlacklistRequestUrl("testTopic", "t", null);
  response = RestTestBase.HTTP_CLIENT.handle(request);
  Assert.assertEquals(response.getStatus(), Status.CLIENT_ERROR_BAD_REQUEST);
  Assert.assertEquals(response.getEntityAsText(), "Parameter partition should be Integer");


  _helixMirrorMakerManager.updateTopicPartitionStateInMirrorMaker("testTopic", 2, Constants.HELIX_ONLINE_STATE);
  EasyMock.expectLastCall();

  request = ControllerRequestURLBuilder.baseUrl(REQUEST_URL)
      .postBlacklistRequestUrl("testTopic", "2", "whitelist");
  response = RestTestBase.HTTP_CLIENT.handle(request);
  Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
  Assert.assertEquals(response.getEntityAsText(), "OK");

  _helixMirrorMakerManager.updateTopicPartitionStateInMirrorMaker("testTopic", 3,Constants.HELIX_OFFLINE_STATE);
  EasyMock.expectLastCall();

  request = ControllerRequestURLBuilder.baseUrl(REQUEST_URL)
      .postBlacklistRequestUrl("testTopic", "3", "blacklist");
  response = RestTestBase.HTTP_CLIENT.handle(request);
  Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK);
  Assert.assertEquals(response.getEntityAsText(), "OK");
}
 
Example #28
Source File: ControllerRequestURLBuilder.java    From uReplicator with Apache License 2.0 5 votes vote down vote up
public Request getBlacklistRequestUrl() {
  String requestUrl = StringUtils.join(new String[]{
      _baseUrl, "/blacklist"
  });
  Request request = new Request(Method.GET, requestUrl);
  return request;
}
 
Example #29
Source File: ControllerRequestURLBuilder.java    From uReplicator with Apache License 2.0 5 votes vote down vote up
public Request getNoProgressRequestUrl() {
  String requestUrl = StringUtils.join(new String[]{
      _baseUrl, "/noprogress"
  });
  Request request = new Request(Method.GET, requestUrl);
  return request;
}
 
Example #30
Source File: ClientCache.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
public void updateQueryConditions( Request request )
    {
        String identity = pathToIdentity.get( getIdentityPath( request.getResourceRef() ) );
        if( identity != null )
        {
            CacheInfo cacheInfo = identityToTimestamp.get( identity );
            if( cacheInfo != null )
            {
//            LoggerFactory.getLogger( ClientCache.class ).info( "Send:  "+cacheInfo.getEntity()+" ("+request.getMethod().getName()+":"+request.getResourceRef()+") -> "+cacheInfo.getLastModified() );
                request.getConditions().setModifiedSince( from( cacheInfo.getLastModified() ) );
            }
        }
    }