org.jboss.resteasy.client.ClientRequest Java Examples

The following examples show how to use org.jboss.resteasy.client.ClientRequest. 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: RestReceive.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
   // first get the create URL for the shipping queue
   ClientRequest request = new ClientRequest("http://localhost:8080/queues/orders");
   ClientResponse res = request.head();
   Link pullConsumers = res.getHeaderAsLink("msg-pull-consumers");
   res = pullConsumers.request().formParameter("autoAck", "false").post();
   Link ackNext = res.getHeaderAsLink("msg-acknowledge-next");
   res.releaseConnection();
   while (true) {
      System.out.println("Waiting...");
      res = ackNext.request().header("Accept-Wait", "10").header("Accept", "application/xml").post();
      if (res.getStatus() == 503) {
         System.out.println("Timeout...");
         ackNext = res.getHeaderAsLink("msg-acknowledge-next");
      } else if (res.getStatus() == 200) {
         Order order = (Order) res.getEntity(Order.class);
         System.out.println(order);
         Link ack = res.getHeaderAsLink("msg-acknowledgement");
         res = ack.request().formParameter("acknowledge", "true").post();
         ackNext = res.getHeaderAsLink("msg-acknowledge-next");
      } else {
         throw new RuntimeException("Failure! " + res.getStatus());
      }
      res.releaseConnection();
   }
}
 
Example #2
Source File: RestSend.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
   // first get the create URL for the shipping queue
   ClientRequest request = new ClientRequest("http://localhost:8080/queues/orders");
   ClientResponse res = request.head();
   Link create = res.getHeaderAsLink("msg-create");

   System.out.println("Send order...");
   Order order = new Order();
   order.setName("Bill");
   order.setItem("iPhone4");
   order.setAmount("$199.99");

   res = create.request().body("application/xml", order).post();
   if (res.getStatus() != 201)
      throw new RuntimeException("Failed to post");
}
 
Example #3
Source File: PushReg.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
   // get the push consumers factory resource
   ClientRequest request = new ClientRequest("http://localhost:8080/queues/orders");
   ClientResponse res = request.head();
   Link pushConsumers = res.getHeaderAsLink("msg-push-consumers");

   // next create the XML document that represents the registration
   // Really, just create a link with the shipping URL and the type you want posted
   PushRegistration reg = new PushRegistration();
   XmlLink target = new XmlLink();
   target.setHref("http://localhost:8080/queues/shipping");
   target.setType("application/xml");
   target.setRelationship("destination");
   reg.setTarget(target);

   res = pushConsumers.request().body("application/xml", reg).post();
   System.out.println("Create push registration.  Resource URL: " + res.getLocationLink().getHref());
}
 
Example #4
Source File: RecaptchaUtil.java    From oxTrust with MIT License 6 votes vote down vote up
public boolean verifyGoogleRecaptcha(String gRecaptchaResponse, String secretKey) {
	boolean result = false;
	try {
		ClientRequest request = new ClientRequest("https://www.google.com/recaptcha/api/siteverify");
		request.formParameter("secret", secretKey);
		request.formParameter("response", gRecaptchaResponse);
		request.accept("application/json");

		ClientResponse<String> response = request.post(String.class);

		ObjectMapper mapper = new ObjectMapper();
		Map<String, String> map = mapper.readValue(new ByteArrayInputStream(response.getEntity().getBytes()),
				new TypeReference<Map<String, String>>() {
				});

		return Boolean.parseBoolean(map.get("success"));
	} catch (Exception e) {
		log.warn("Exception happened while verifying recaptcha, check your internet connection", e);
		return result;
	}
}
 
Example #5
Source File: EmbeddedRestActiveMQJMSTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void startEmbedded() throws Exception {
   server = new EmbeddedRestActiveMQ(null);
   assertNotNull(server.getEmbeddedActiveMQ());
   server.getManager().setConfigResourcePath("activemq-rest.xml");

   SecurityConfiguration securityConfiguration = createDefaultSecurityConfiguration();
   ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), securityConfiguration);
   server.getEmbeddedActiveMQ().setSecurityManager(securityManager);

   server.start();
   factory = ActiveMQJMSClient.createConnectionFactory("vm://0", "cf");

   ClientRequest request = new ClientRequest(TestPortProvider.generateURL("/queues/exampleQueue"));

   ClientResponse<?> response = request.head();
   response.releaseConnection();
   assertEquals(200, response.getStatus());
   Link sender = response.getLinkHeader().getLinkByTitle("create");
   log.debug("create: " + sender);
   Link consumers = response.getLinkHeader().getLinkByTitle("pull-consumers");
   log.debug("pull: " + consumers);
   response = Util.setAutoAck(consumers, true);
   consumeNext = response.getLinkHeader().getLinkByTitle("consume-next");
   log.debug("consume-next: " + consumeNext);
}
 
Example #6
Source File: PostOrderWithId.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
   if (args.length < 1 || args[0] == null)
      throw new RuntimeException("You must pass in a parameter");

   // first get the create URL for the shipping queue
   ClientRequest request = new ClientRequest("http://localhost:8080/queues/orders");
   ClientResponse res = request.head();
   Link create = res.getHeaderAsLink("msg-create-with-id");

   Order order = new Order();
   order.setName(args[0]);
   order.setItem("iPhone4");
   order.setAmount("$199.99");

   res = create.request().pathParameter("id", args[0]).body("application/xml", order).post();

   if (res.getStatus() != 201)
      throw new RuntimeException("Failed to post");

   System.out.println("Sent order " + args[0]);
}
 
Example #7
Source File: RestEndPointMockerTest.java    From zerocode with Apache License 2.0 6 votes vote down vote up
@Test
public void willMockASimpleGetEndPoint() throws Exception {

    final MockStep mockStep = mockSteps.getMocks().get(0);
    String jsonBodyRequest = mockStep.getResponse().get("body").toString();

    WireMock.configureFor(9073);
    givenThat(get(urlEqualTo(mockStep.getUrl()))
            .willReturn(aResponse()
                    .withStatus(mockStep.getResponse().get("status").asInt())
                    .withHeader("Content-Type", APPLICATION_JSON)
                    .withBody(jsonBodyRequest)));

    ApacheHttpClientExecutor httpClientExecutor = new ApacheHttpClientExecutor();
    ClientRequest clientExecutor = httpClientExecutor.createRequest("http://localhost:9073" + mockStep.getUrl());
    clientExecutor.setHttpMethod("GET");
    ClientResponse serverResponse = clientExecutor.execute();

    final String respBodyAsString = (String) serverResponse.getEntity(String.class);
    JSONAssert.assertEquals(jsonBodyRequest, respBodyAsString, true);

    System.out.println("### zerocode: \n" + respBodyAsString);

}
 
Example #8
Source File: ReceiveOrder.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
   // first get the create URL for the shipping queue
   ClientRequest request = new ClientRequest("http://localhost:8080/queues/orders");
   ClientResponse res = request.head();
   Link pullConsumers = res.getHeaderAsLink("msg-pull-consumers");
   res.releaseConnection();
   res = pullConsumers.request().post();
   Link consumeNext = res.getHeaderAsLink("msg-consume-next");
   res.releaseConnection();
   while (true) {
      System.out.println("Waiting...");
      res = consumeNext.request().header("Accept-Wait", "10").post();
      if (res.getStatus() == 503) {
         System.out.println("Timeout...");
         consumeNext = res.getHeaderAsLink("msg-consume-next");
      } else if (res.getStatus() == 200) {
         Order order = (Order) res.getEntity(Order.class);
         System.out.println(order);
         consumeNext = res.getHeaderAsLink("msg-consume-next");
      } else {
         throw new RuntimeException("Failure! " + res.getStatus());
      }
      res.releaseConnection();
   }
}
 
Example #9
Source File: PushQueueConsumerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testClass() throws Exception {
   Link destinationForConsumption = null;
   ClientResponse consumerResponse = null;
   Link pushSubscription = null;
   String messageContent = "1";

   try {
      // The name of the queue used for the test should match the name of the test
      String queue = "testClass";
      String queueToPushTo = "pushedFrom-" + queue;
      log.debug("\n" + queue);

      deployQueue(queue);
      deployQueue(queueToPushTo);

      ClientResponse queueResponse = Util.head(new ClientRequest(generateURL(Util.getUrlPath(queue))));
      Link destinationForSend = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), queueResponse, "create");
      Link pushSubscriptions = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), queueResponse, "push-consumers");

      ClientResponse queueToPushToResponse = Util.head(new ClientRequest(generateURL(Util.getUrlPath(queueToPushTo))));
      ClientResponse autoAckResponse = setAutoAck(queueToPushToResponse, true);
      destinationForConsumption = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), autoAckResponse, "consume-next");

      pushSubscription = createPushRegistration(queueToPushTo, pushSubscriptions, PushRegistrationType.CLASS);

      sendMessage(destinationForSend, messageContent);

      consumerResponse = consume(destinationForConsumption, messageContent);
   } finally {
      cleanupConsumer(consumerResponse);
      cleanupSubscription(pushSubscription);
   }
}
 
Example #10
Source File: PushQueueConsumerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testTemplate() throws Exception {
   Link destinationForConsumption = null;
   ClientResponse consumerResponse = null;
   Link pushSubscription = null;
   String messageContent = "1";

   try {
      // The name of the queue used for the test should match the name of the test
      String queue = "testTemplate";
      String queueToPushTo = "pushedFrom-" + queue;
      log.debug("\n" + queue);

      deployQueue(queue);
      deployQueue(queueToPushTo);

      ClientResponse queueResponse = Util.head(new ClientRequest(generateURL(Util.getUrlPath(queue))));
      Link destinationForSend = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), queueResponse, "create");
      Link pushSubscriptions = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), queueResponse, "push-consumers");

      ClientResponse queueToPushToResponse = Util.head(new ClientRequest(generateURL(Util.getUrlPath(queueToPushTo))));
      Link consumers = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), queueToPushToResponse, "pull-consumers");
      Link createWithId = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), queueToPushToResponse, "create-with-id");
      ClientResponse autoAckResponse = Util.setAutoAck(consumers, true);
      destinationForConsumption = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), autoAckResponse, "consume-next");

      pushSubscription = createPushRegistration(createWithId.getHref(), pushSubscriptions, PushRegistrationType.TEMPLATE);

      sendMessage(destinationForSend, messageContent);

      consumerResponse = consume(destinationForConsumption, messageContent);
   } finally {
      cleanupConsumer(consumerResponse);
      cleanupSubscription(pushSubscription);
   }
}
 
Example #11
Source File: BaseClient.java    From oxAuth with MIT License 5 votes vote down vote up
public static void putAllFormParameters(ClientRequest p_clientRequest, BaseRequest p_request) {
    if (p_clientRequest != null && p_request != null) {
        final Map<String, String> parameters = p_request.getParameters();
        if (parameters != null && !parameters.isEmpty()) {
            for (Map.Entry<String, String> e : parameters.entrySet()) {
                p_clientRequest.formParameter(e.getKey(), e.getValue());
            }
        }
    }
}
 
Example #12
Source File: FindDestinationTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testFindQueue() throws Exception {
   String testName = "testFindQueue";
   server.getActiveMQServer().addAddressInfo(new AddressInfo(SimpleString.toSimpleString(testName), RoutingType.MULTICAST));
   server.getActiveMQServer().createQueue(new QueueConfiguration(testName).setDurable(false));

   ClientRequest request = new ClientRequest(TestPortProvider.generateURL("/queues/" + testName));

   ClientResponse<?> response = request.head();
   response.releaseConnection();
   Assert.assertEquals(200, response.getStatus());
   Link sender = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "create");
   log.debug("create: " + sender);
   Link consumers = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "pull-consumers");
   log.debug("pull: " + consumers);
   response = Util.setAutoAck(consumers, true);
   Link consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consume-next");
   log.debug("poller: " + consumeNext);

   ClientResponse<?> res = sender.request().body("text/plain", Integer.toString(1)).post();
   res.releaseConnection();
   Assert.assertEquals(201, res.getStatus());

   res = consumeNext.request().post(String.class);
   Assert.assertEquals(200, res.getStatus());
   Assert.assertEquals("1", res.getEntity(String.class));
   res.releaseConnection();
   Link session = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consumer");
   log.debug("session: " + session);
   Assert.assertEquals(204, session.request().delete().getStatus());
}
 
Example #13
Source File: RoundtripTimeTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testSuccessFirst() throws Exception {
   QueueDeployment deployment = new QueueDeployment();
   deployment.setDuplicatesAllowed(true);
   deployment.setDurableSend(false);
   deployment.setName("testQueue");
   manager.getQueueManager().deploy(deployment);

   ClientRequest request = new ClientRequest(generateURL("/queues/testQueue"));

   ClientResponse<?> response = request.head();
   response.releaseConnection();
   Assert.assertEquals(200, response.getStatus());
   Link sender = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "create");
   log.debug("create: " + sender);
   Link consumers = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "pull-consumers");
   log.debug("pull: " + consumers);
   response = Util.setAutoAck(consumers, true);
   Link consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consume-next");
   log.debug("consume-next: " + consumeNext);

   long start = System.currentTimeMillis();
   int num = 100;
   for (int i = 0; i < num; i++) {
      response = sender.request().body("text/plain", Integer.toString(i + 1)).post();
      response.releaseConnection();
   }
   long end = System.currentTimeMillis() - start;
   log.debug(num + " iterations took " + end + "ms");

   for (int i = 0; i < num; i++) {
      response = consumeNext.request().post(String.class);
      consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consume-next");
      Assert.assertEquals(200, response.getStatus());
      Assert.assertEquals(Integer.toString(i + 1), response.getEntity(String.class));
      response.releaseConnection();
   }
}
 
Example #14
Source File: PushQueueConsumerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testUri() throws Exception {
   Link pushSubscription = null;
   String messageContent = "1";

   try {
      // The name of the queue used for the test should match the name of the test
      String queue = "testUri";
      String queueToPushTo = "pushedFrom-" + queue;
      log.debug("\n" + queue);

      deployQueue(queue);
      deployQueue(queueToPushTo);
      server.getJaxrsServer().getDeployment().getRegistry().addPerRequestResource(MyResource.class);

      ClientResponse queueResponse = Util.head(new ClientRequest(generateURL(Util.getUrlPath(queue))));
      Link destinationForSend = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), queueResponse, "create");
      Link pushSubscriptions = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), queueResponse, "push-consumers");

      pushSubscription = createPushRegistration(generateURL("/my"), pushSubscriptions, PushRegistrationType.URI);

      sendMessage(destinationForSend, messageContent);

      Thread.sleep(100);

      Assert.assertEquals(messageContent, MyResource.got_it);
   } finally {
      cleanupSubscription(pushSubscription);
   }
}
 
Example #15
Source File: WireMockJsonContentTesting.java    From zerocode with Apache License 2.0 5 votes vote down vote up
@Test
public void bioViaJson() throws Exception{
    String jsonBodyRequest = "{\n" +
            "    \"id\": \"303021\",\n" +
            "    \"names\": [\n" +
            "        {\n" +
            "            \"firstName\": \"You First\",\n" +
            "            \"lastName\": \"Me Last\"\n" +
            "        }\n" +
            "    ]\n" +
            "}";

    givenThat(WireMock.get(urlEqualTo("/identitymanagement-services/identitymanagement-services/person/internalHandle/person_id_009/biographics/default"))
            .willReturn(aResponse()
                    .withStatus(200)
                    .withHeader("Content-Type", APPLICATION_JSON)
                    .withBody(jsonBodyRequest)));

    ApacheHttpClientExecutor httpClientExecutor = new ApacheHttpClientExecutor();
    ClientRequest clientExecutor = httpClientExecutor.createRequest("http://localhost:9073/identitymanagement-services/identitymanagement-services/person/internalHandle/person_id_009/biographics/default");
    clientExecutor.setHttpMethod("GET");
    ClientResponse serverResponse = clientExecutor.execute();

    final String respBodyAsString = (String)serverResponse.getEntity(String.class);
    JSONAssert.assertEquals(jsonBodyRequest, respBodyAsString, true);

    System.out.println("### bio response from mapping: \n" + respBodyAsString);
}
 
Example #16
Source File: PushQueueConsumerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testBridge() throws Exception {
   Link destinationForConsumption = null;
   ClientResponse consumerResponse = null;
   Link pushSubscription = null;
   String messageContent = "1";

   try {
      // The name of the queue used for the test should match the name of the test
      String queue = "testBridge";
      String queueToPushTo = "pushedFrom-" + queue;
      log.debug("\n" + queue);
      deployQueue(queue);
      deployQueue(queueToPushTo);

      ClientResponse queueResponse = Util.head(new ClientRequest(generateURL(Util.getUrlPath(queue))));
      Link destination = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), queueResponse, "create");
      Link pushSubscriptions = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), queueResponse, "push-consumers");

      ClientResponse queueToPushToResponse = Util.head(new ClientRequest(generateURL(Util.getUrlPath(queueToPushTo))));
      ClientResponse autoAckResponse = setAutoAck(queueToPushToResponse, true);
      destinationForConsumption = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), autoAckResponse, "consume-next");

      pushSubscription = createPushRegistration(queueToPushTo, pushSubscriptions, PushRegistrationType.BRIDGE);

      sendMessage(destination, messageContent);

      consumerResponse = consume(destinationForConsumption, messageContent);
   } finally {
      cleanupConsumer(consumerResponse);
      cleanupSubscription(pushSubscription);
   }
}
 
Example #17
Source File: CreateDestinationTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateTopicWithBadContentType() throws Exception {
   String queueConfig = "<topic name=\"testTopic\"></topic>";
   ClientRequest create = new ClientRequest(TestPortProvider.generateURL("/topics"));
   ClientResponse cRes = create.body("application/x-www-form-urlencoded", queueConfig).post();
   cRes.releaseConnection();
   Assert.assertEquals(415, cRes.getStatus());
}
 
Example #18
Source File: AuthorizeClient.java    From oxAuth with MIT License 5 votes vote down vote up
@Deprecated
public AuthorizationResponse exec(ClientExecutor clientExecutor) {
    AuthorizationResponse response = null;

    try {
        clientRequest = new ClientRequest(getUrl(), clientExecutor);
        response = exec_();
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
    }
    // Do not close the connection for this case.

    return response;
}
 
Example #19
Source File: RepostingTopicTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testRestartOnNonDurableNamedSubscriber() throws Exception {
   ClientRequest request = new ClientRequest(generateURL("/topics/testTopic"));

   ClientResponse<?> response = request.head();
   response.releaseConnection();
   Assert.assertEquals(200, response.getStatus());
   Link sender = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "create");
   log.debug("create: " + sender);
   Link consumers = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "pull-subscriptions");
   log.debug("pull: " + consumers);
   response = consumers.request().formParameter("name", "bill").post();
   response.releaseConnection();

   response = sender.request().body("text/plain", Integer.toString(1)).post();
   response.releaseConnection();
   Assert.assertEquals(201, response.getStatus());
   response = sender.request().body("text/plain", Integer.toString(2)).post();
   response.releaseConnection();
   Assert.assertEquals(201, response.getStatus());

   manager.getTopicManager().getDestination().findTopic("testTopic").getSubscriptions().stop();

   // recreate subscription a second time as named.  Should pick up old one.

   response = consumers.request().formParameter("name", "bill").post();
   response.releaseConnection();
   Link consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consume-next");
   log.debug("resource consume-next: " + consumeNext);
   response = consumeNext.request().header("Accept-Wait", "2").post(String.class);
   response.releaseConnection();
   Assert.assertEquals(503, response.getStatus());

   Link session = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consumer");
   response = session.request().delete();
   response.releaseConnection();
   Assert.assertEquals(204, response.getStatus());
}
 
Example #20
Source File: BaseClient.java    From oxAuth with MIT License 5 votes vote down vote up
protected void initClientRequest() {
    if (this.executor == null) {
        this.clientRequest = new ClientRequest(getUrl());
    } else {
        this.clientRequest = new ClientRequest(getUrl(), this.executor);
    }
    for (Cookie cookie : cookies) {
        clientRequest.cookie(cookie);
    }
    for (Map.Entry<String, String> headerEntry : headers.entrySet()) {
        clientRequest.header(headerEntry.getKey(), headerEntry.getValue());
    }
}
 
Example #21
Source File: HttpUtils.java    From pnc with Apache License 2.0 5 votes vote down vote up
/**
 * Process HTTP requests and tests if server responds with expected HTTP code. Request is implicitly set to accept
 * MIME type application/json.
 *
 * @param ecode Expected HTTP error code
 * @param url Request URL
 * @throws Exception Thrown if some error occurs in communication with server
 */
public static void testResponseHttpCode(int ecode, String url) throws Exception {
    ClientRequest request = new ClientRequest(url);
    request.accept(MediaType.APPLICATION_JSON);

    ClientResponse<String> response = request.get(String.class);
    if (response.getStatus() != ecode)
        throw new Exception("Server returned unexpected HTTP code! Returned code:" + response.getStatus());
}
 
Example #22
Source File: RepostingTopicTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testRestartOnNonDurableNamedSubscriber() throws Exception {
   ClientRequest request = new ClientRequest(generateURL("/topics/testTopic"));

   ClientResponse<?> response = request.head();
   response.releaseConnection();
   Assert.assertEquals(200, response.getStatus());
   Link sender = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "create");
   log.debug("create: " + sender);
   Link consumers = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "pull-subscriptions");
   log.debug("pull: " + consumers);
   response = consumers.request().formParameter("name", "bill").post();
   response.releaseConnection();

   response = sender.request().body("text/plain", Integer.toString(1)).post();
   response.releaseConnection();
   Assert.assertEquals(201, response.getStatus());
   response = sender.request().body("text/plain", Integer.toString(2)).post();
   response.releaseConnection();
   Assert.assertEquals(201, response.getStatus());

   manager.getTopicManager().getDestination().findTopic("testTopic").getSubscriptions().stop();

   // recreate subscription a second time as named.  Should pick up old one.

   response = consumers.request().formParameter("name", "bill").post();
   response.releaseConnection();
   Link consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consume-next");
   log.debug("resource consume-next: " + consumeNext);
   response = consumeNext.request().header("Accept-Wait", "2").post(String.class);
   response.releaseConnection();
   Assert.assertEquals(503, response.getStatus());

   Link session = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consumer");
   response = session.request().delete();
   response.releaseConnection();
   Assert.assertEquals(204, response.getStatus());
}
 
Example #23
Source File: HMACFilterAuthenticationProviderTest.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testProvideAuthenticationPostFail() throws Exception {
	ClientRequest request = new ClientRequest("http://localhost:8080/hmac", httpExecutor);
	request.queryParameter("a", "b"); // with also params in URI
	request.queryParameter("c", "d");
	request.header(HMACUtils.HEADERS_SIGNED.get(0), "z");
	request.header("r", "f");
	request.body(MediaType.TEXT_PLAIN, "abcdhjk");
	// without providing authentication
	ClientResponse<?> resp = request.post();
	Assert.assertTrue(resp.getStatus() >= 400);
	Assert.assertFalse(DummyServlet.arrived);
}
 
Example #24
Source File: AutoAckTopicTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
   try {
      ClientRequest req = new ClientRequest(url);
      req.header("Accept-Wait", acceptWaitTime);
      ClientResponse<?> response = req.post();
      response.releaseConnection();
      isFinished = true;
   } catch (Exception e) {
      failed = true;
   }
}
 
Example #25
Source File: AutoAckTopicTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
   try {
      isFinished = false;
      ClientRequest request = new ClientRequest(url);
      ClientResponse<?> response = request.post();
      response.releaseConnection();
      log.debug("NPS response: " + response.getStatus());
      Assert.assertEquals(201, response.getStatus());
      isFinished = true;
   } catch (Exception e) {
      log.debug("Exception " + e);
      failed = true;
   }
}
 
Example #26
Source File: RepostingQueueTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testPostOnOldConsumeNext() throws Exception {
   ClientRequest request = new ClientRequest(generateURL("/queues/testQueue"));

   ClientResponse<?> response = request.head();
   response.releaseConnection();
   Assert.assertEquals(200, response.getStatus());
   Link sender = MessageTestBase.getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "create");
   log.debug("create: " + sender);
   Link consumers = MessageTestBase.getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "pull-consumers");
   log.debug("pull: " + consumers);
   response = Util.setAutoAck(consumers, true);
   Link consumeNext = MessageTestBase.getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consume-next");
   log.debug("resource consume-next: " + consumeNext);

   response = sender.request().body("text/plain", Integer.toString(1)).post();
   response.releaseConnection();
   Assert.assertEquals(201, response.getStatus());

   response = consumeNext.request().header(Constants.WAIT_HEADER, "1").post(String.class);
   Assert.assertEquals(200, response.getStatus());
   Assert.assertEquals("1", response.getEntity(String.class));
   response.releaseConnection();
   Link session = MessageTestBase.getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consumer");
   log.debug("session: " + session);
   consumeNext = MessageTestBase.getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consume-next");
   Link firstConsumeNext = consumeNext;
   log.debug("session 1st consumeNext: " + consumeNext);

   response = sender.request().body("text/plain", Integer.toString(2)).post();
   response.releaseConnection();
   Assert.assertEquals(201, response.getStatus());

   response = consumeNext.request().header(Constants.WAIT_HEADER, "10").post(String.class);
   Assert.assertEquals(200, response.getStatus());
   Assert.assertEquals("2", response.getEntity(String.class));
   response.releaseConnection();
   session = MessageTestBase.getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consumer");
   log.debug("session: " + session);
   consumeNext = MessageTestBase.getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consume-next");
   log.debug("session 2nd consumeNext: " + consumeNext);

   response = sender.request().body("text/plain", Integer.toString(3)).post();
   response.releaseConnection();
   Assert.assertEquals(201, response.getStatus());
   response = consumeNext.request().header(Constants.WAIT_HEADER, "10").post(String.class);
   Assert.assertEquals(200, response.getStatus());
   Assert.assertEquals("3", response.getEntity(String.class));
   response.releaseConnection();

   response = firstConsumeNext.request().header(Constants.WAIT_HEADER, "10").post(String.class);
   Assert.assertEquals(412, response.getStatus());
   log.debug(response.getEntity(String.class));
   response.releaseConnection();

   response = session.request().delete();
   response.releaseConnection();
   Assert.assertEquals(204, response.getStatus());
}
 
Example #27
Source File: RepostingQueueTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testPostOnSameAcknowledgeNextAndAck() throws Exception {
   ClientRequest request = new ClientRequest(generateURL("/queues/testQueue"));

   ClientResponse<?> response = request.head();
   response.releaseConnection();
   Assert.assertEquals(200, response.getStatus());
   Link sender = MessageTestBase.getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "create");
   log.debug("create: " + sender);
   Link consumers = MessageTestBase.getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "pull-consumers");
   log.debug("pull: " + consumers);
   response = Util.setAutoAck(consumers, false);
   Link consumeNext = MessageTestBase.getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "acknowledge-next");
   log.debug("resource acknowledge-next: " + consumeNext);

   response = sender.request().body("text/plain", Integer.toString(1)).post();
   response.releaseConnection();
   Assert.assertEquals(201, response.getStatus());

   response = consumeNext.request().header(Constants.WAIT_HEADER, "3").post(String.class);
   Assert.assertEquals(200, response.getStatus());
   Assert.assertEquals("1", response.getEntity(String.class));
   response.releaseConnection();
   Link session = MessageTestBase.getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consumer");
   log.debug("session: " + session);
   Link ack = MessageTestBase.getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "acknowledgement");
   log.debug("ack: " + ack);
   response = ack.request().formParameter("acknowledge", "true").post();
   response.releaseConnection();
   Assert.assertEquals(204, response.getStatus());
   response = ack.request().formParameter("acknowledge", "true").post();
   response.releaseConnection();
   Assert.assertEquals(204, response.getStatus());
   response = ack.request().formParameter("acknowledge", "true").post();
   response.releaseConnection();
   Assert.assertEquals(204, response.getStatus());
   consumeNext = MessageTestBase.getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "acknowledge-next");
   log.debug("session 1st acknowledge-next: " + consumeNext);

   response = sender.request().body("text/plain", Integer.toString(2)).post();
   response.releaseConnection();
   Assert.assertEquals(201, response.getStatus());

   response = consumeNext.request().header(Constants.WAIT_HEADER, "10").post(String.class);
   Assert.assertEquals(200, response.getStatus());
   Assert.assertEquals("2", response.getEntity(String.class));
   response.releaseConnection();
   response = consumeNext.request().header(Constants.WAIT_HEADER, "10").post(String.class);
   Assert.assertEquals(200, response.getStatus());
   Assert.assertEquals("2", response.getEntity(String.class));
   response.releaseConnection();
   response = consumeNext.request().header(Constants.WAIT_HEADER, "10").post(String.class);
   Assert.assertEquals(200, response.getStatus());
   Assert.assertEquals("2", response.getEntity(String.class));
   response.releaseConnection();
   response = consumeNext.request().header(Constants.WAIT_HEADER, "10").post(String.class);
   Assert.assertEquals(200, response.getStatus());
   Assert.assertEquals("2", response.getEntity(String.class));
   response.releaseConnection();
   ack = MessageTestBase.getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "acknowledgement");
   log.debug("ack: " + ack);
   response = ack.request().formParameter("acknowledge", "true").post();
   response.releaseConnection();
   Assert.assertEquals(204, response.getStatus());

   response = session.request().delete();
   response.releaseConnection();
   Assert.assertEquals(204, response.getStatus());
}
 
Example #28
Source File: RedirectionUriService.java    From oxAuth with MIT License 4 votes vote down vote up
public String validateRedirectionUri(@NotNull Client client, String redirectionUri) {
    try {
        String sectorIdentifierUri = client.getSectorIdentifierUri();
        String[] redirectUris = client.getRedirectUris();

        if (StringUtils.isNotBlank(sectorIdentifierUri)) {
            ClientRequest clientRequest = new ClientRequest(sectorIdentifierUri);
            clientRequest.setHttpMethod(HttpMethod.GET);

            ClientResponse<String> clientResponse = clientRequest.get(String.class);
            int status = clientResponse.getStatus();

            if (status == 200) {
                String entity = clientResponse.getEntity(String.class);
                JSONArray sectorIdentifierJsonArray = new JSONArray(entity);
                redirectUris = new String[sectorIdentifierJsonArray.length()];
                for (int i = 0; i < sectorIdentifierJsonArray.length(); i++) {
                    redirectUris[i] = sectorIdentifierJsonArray.getString(i);
                }
            } else {
                return null;
            }
        }

        if (StringUtils.isNotBlank(redirectionUri) && redirectUris != null) {
            log.debug("Validating redirection URI: clientIdentifier = {}, redirectionUri = {}, found = {}",
                    client.getClientId(), redirectionUri, redirectUris.length);

            if (isUriEqual(redirectionUri, redirectUris)) {
                return redirectionUri;
            }
        } else {
            // Accept Request Without redirect_uri when One Registered
            if (redirectUris != null && redirectUris.length == 1) {
                return redirectUris[0];
            }
        }
    } catch (Exception e) {
        return null;
    }
    return null;
}
 
Example #29
Source File: PersistentPushTopicConsumerTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testSuccessFirst() throws Exception {
   try {
      String testName = "testSuccessFirst";
      startup();
      deployTopic(testName);

      ClientRequest request = new ClientRequest(generateURL("/topics/" + testName));

      ClientResponse<?> response = request.head();
      response.releaseConnection();
      Assert.assertEquals(200, response.getStatus());
      Link sender = MessageTestBase.getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "create");
      log.debug("create: " + sender);
      Link pushSubscriptions = MessageTestBase.getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "push-subscriptions");
      log.debug("push subscriptions: " + pushSubscriptions);

      String sub1 = generateURL("/subscribers/1");
      String sub2 = generateURL("/subscribers/2");

      PushTopicRegistration reg = new PushTopicRegistration();
      reg.setDurable(true);
      XmlLink target = new XmlLink();
      target.setHref(sub1);
      reg.setTarget(target);
      response = pushSubscriptions.request().body("application/xml", reg).post();
      response.releaseConnection();
      Assert.assertEquals(201, response.getStatus());

      reg = new PushTopicRegistration();
      reg.setDurable(true);
      target = new XmlLink();
      target.setHref(sub2);
      reg.setTarget(target);
      response = pushSubscriptions.request().body("application/xml", reg).post();
      response.releaseConnection();
      Assert.assertEquals(201, response.getStatus());

      shutdown();
      startup();
      deployTopic(testName);

      ClientResponse<?> res = sender.request().body("text/plain", Integer.toString(1)).post();
      res.releaseConnection();
      Assert.assertEquals(201, res.getStatus());

      Receiver.latch.await(1, TimeUnit.SECONDS);

      Assert.assertEquals("1", Receiver.subscriber1);
      Assert.assertEquals("1", Receiver.subscriber2);

      manager.getTopicManager().getPushStore().removeAll();
   } finally {
      shutdown();
   }
}
 
Example #30
Source File: RepostingQueueTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testRepostAckAfterUnacknowledge() throws Exception {
   ClientRequest request = new ClientRequest(generateURL("/queues/testQueue"));

   ClientResponse<?> response = request.head();
   response.releaseConnection();
   Assert.assertEquals(200, response.getStatus());
   Link sender = MessageTestBase.getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "create");
   log.debug("create: " + sender);
   Link consumers = MessageTestBase.getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "pull-consumers");
   log.debug("pull: " + consumers);
   response = Util.setAutoAck(consumers, false);
   Link consumeNext = MessageTestBase.getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "acknowledge-next");
   log.debug("resource acknowledge-next: " + consumeNext);

   response = sender.request().body("text/plain", Integer.toString(1)).post();
   response.releaseConnection();
   Assert.assertEquals(201, response.getStatus());

   response = consumeNext.request().header(Constants.WAIT_HEADER, "1").post(String.class);
   Assert.assertEquals(200, response.getStatus());
   Assert.assertEquals("1", response.getEntity(String.class));
   response.releaseConnection();
   Link session = MessageTestBase.getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consumer");
   log.debug("session: " + session);
   Link ack = MessageTestBase.getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "acknowledgement");
   log.debug("ack: " + ack);
   response = ack.request().formParameter("acknowledge", "false").post();
   response.releaseConnection();
   Assert.assertEquals(204, response.getStatus());
   response = ack.request().formParameter("acknowledge", "true").post();
   Assert.assertEquals(412, response.getStatus());
   log.debug(response.getEntity(String.class));
   response.releaseConnection();
   consumeNext = MessageTestBase.getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "acknowledge-next");
   log.debug("session 1st acknowledge-next: " + consumeNext);

   response = consumeNext.request().header(Constants.WAIT_HEADER, "10").post(String.class);
   Assert.assertEquals(200, response.getStatus());
   Assert.assertEquals("1", response.getEntity(String.class));
   response.releaseConnection();
   response = consumeNext.request().header(Constants.WAIT_HEADER, "10").post(String.class);
   Assert.assertEquals(200, response.getStatus());
   Assert.assertEquals("1", response.getEntity(String.class));
   response.releaseConnection();
   response = consumeNext.request().header(Constants.WAIT_HEADER, "10").post(String.class);
   Assert.assertEquals(200, response.getStatus());
   Assert.assertEquals("1", response.getEntity(String.class));
   response.releaseConnection();
   response = consumeNext.request().header(Constants.WAIT_HEADER, "10").post(String.class);
   Assert.assertEquals(200, response.getStatus());
   Assert.assertEquals("1", response.getEntity(String.class));
   response.releaseConnection();
   ack = MessageTestBase.getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "acknowledgement");
   log.debug("ack: " + ack);
   response = ack.request().formParameter("acknowledge", "true").post();
   response.releaseConnection();
   Assert.assertEquals(204, response.getStatus());

   response = session.request().delete();
   response.releaseConnection();
   Assert.assertEquals(204, response.getStatus());
}