Commit bdf3a775 authored by Andre Freyssinet's avatar Andre Freyssinet

Use form parameters for authentication.

parent b5d5183a
......@@ -23,6 +23,7 @@
package rest;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
......@@ -30,6 +31,7 @@ import java.util.Set;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Form;
import javax.ws.rs.client.Invocation.Builder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Link;
......@@ -38,6 +40,7 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import org.glassfish.jersey.client.ClientConfig;
import org.objectweb.util.monolog.api.BasicLevel;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
......@@ -65,15 +68,28 @@ public class RestConsumer {
System.out.println("Lookup \"" + dest + "\" -> " + response.getStatus());
if (debug) print(response.getLinks());
URI uriCreateCons = client.target(response.getLink("create-consumer-client-ack"))
URI uriCreateCons = client.target(response.getLink("create-consumer"))
// .queryParam("name", "cons1")
.queryParam("idle-timeout", "120")
.getUri();
try {
// // TODO (AF): to remove (use FormParam alternate URI)
// uriCreateCons = new URI(uriCreateCons.toString() + "-fp");
uriCreateCons = new URI("http://localhost:8989/joram/jndi/queue/create-consumer-fp?session-mode=2");
} catch (URISyntaxException exc) {
exc.printStackTrace();
uriCreateCons = null;
}
Form form = new Form();
form.param("user", "anonymous")
.param("password", "anonymous");
response = client.target(uriCreateCons)
.request()
.accept(MediaType.TEXT_PLAIN).post(null);
// .accept(MediaType.TEXT_PLAIN).post(Entity.entity(null, MediaType.APPLICATION_FORM_URLENCODED));
// .accept(MediaType.TEXT_PLAIN).post(null);
.accept(MediaType.TEXT_PLAIN).post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED));
System.out.println("Create consumer -> " + response.getStatus());
if (debug) print(response.getLinks());
......
......@@ -23,6 +23,7 @@
package rest;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Properties;
import java.util.Set;
......@@ -30,6 +31,7 @@ import java.util.Set;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Form;
import javax.ws.rs.client.Invocation.Builder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Link;
......@@ -68,13 +70,30 @@ public class RestProducer {
URI uriCreateProd = client.target(response.getLink("create-producer"))
// .queryParam("name", "prod1")
.getUri();
try {
uriCreateProd = new URI(uriCreateProd.toString() + "-fp");
} catch (URISyntaxException exc) {
exc.printStackTrace();
}
System.out.println("URI -> " + uriCreateProd);
// Create the producer
response = client.target(uriCreateProd)
.request()
.accept(MediaType.TEXT_PLAIN).post(null);
// .accept(MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON).post(Entity.entity(null, MediaType.APPLICATION_FORM_URLENCODED));
target = client.target(uriCreateProd);
target = target.queryParam("name", "prod1");
target = target.queryParam("client-id", "prod1");
// target = target.queryParam("user", "anonymous");
// target = target.queryParam("password", "anonymous");
Form form = new Form();
form.param("user", "efluid")
.param("password", "diulfe");
response = target.request()
// .accept(MediaType.TEXT_PLAIN).post("");
.accept(MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON).post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED));
// response = target.
// request(MediaType.APPLICATION_FORM_URLENCODED)
// .accept(MediaType.TEXT_PLAIN)
// .buildPost(Entity.form(form)).submit(String.class);
System.out.println("Response -> " + response);
uriCloseProd = response.getLink("close-context").getUri();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment