use of jakarta.ws.rs.core.MultivaluedMap in project resteasy by resteasy.
the class MapMultipartFormDataWriter method asyncWriteTo.
@Override
public CompletionStage<Void> asyncWriteTo(Map<String, Object> map, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, AsyncOutputStream entityStream) {
PartType partType = FindAnnotation.findAnnotation(annotations, PartType.class);
MediaType partMediaType = MediaType.valueOf(partType.value());
MultipartFormDataOutput output = new MultipartFormDataOutput();
for (Map.Entry<String, Object> entry : map.entrySet()) {
output.addFormData(entry.getKey(), entry.getValue(), partMediaType);
}
return asyncWrite(output, mediaType, httpHeaders, entityStream, annotations);
}
use of jakarta.ws.rs.core.MultivaluedMap in project resteasy by resteasy.
the class PriorityTest method testMessageBodyReaderPriorityOverride.
@Test
public void testMessageBodyReaderPriorityOverride() {
Client client = ClientBuilder.newClient();
try {
fakeHttpServer.start();
WebTarget webTarget = client.target("http://" + fakeHttpServer.getHostAndPort());
webTarget.register((ClientResponseFilter) (containerRequestContext, containerResponseContext) -> {
containerResponseContext.getHeaders().putSingle(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN);
containerResponseContext.setEntityStream(new ByteArrayInputStream("hello".getBytes()));
});
StringBuilder result = new StringBuilder();
webTarget.register(new MessageBodyReader<String>() {
@Override
public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
result.append("K");
return false;
}
@Override
public String readFrom(Class<String> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
return null;
}
}, 1);
webTarget.register(new MessageBodyReader<String>() {
@Override
public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
result.append("O");
return false;
}
@Override
public String readFrom(Class<String> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
return null;
}
}, 0);
webTarget.request().get().readEntity(String.class);
Assert.assertEquals("OK", result.toString());
} finally {
client.close();
}
}
use of jakarta.ws.rs.core.MultivaluedMap in project org.openntf.xsp.jakartaee by OpenNTF.
the class TestNoSQL method testNoSql.
@SuppressWarnings("unchecked")
@Test
public void testNoSql() throws JsonException {
Client client = getAnonymousClient();
// $NON-NLS-1$
WebTarget target = client.target(getRestUrl(null) + "/nosql?lastName=CreatedUnitTest");
{
Response response = target.request().get();
String json = response.readEntity(String.class);
Map<String, Object> jsonObject = (Map<String, Object>) JsonParser.fromJson(JsonJavaFactory.instance, json);
// $NON-NLS-1$
List<Object> byQueryLastName = (List<Object>) jsonObject.get("byQueryLastName");
assertNotNull(byQueryLastName, () -> String.valueOf(jsonObject));
assertTrue(byQueryLastName.isEmpty(), () -> String.valueOf(jsonObject));
}
// Now use the MVC endpoint to create one, which admittedly is outside this test
{
MultivaluedMap<String, String> payload = new MultivaluedHashMap<>();
// $NON-NLS-1$ //$NON-NLS-2$
payload.putSingle("firstName", "foo");
// $NON-NLS-1$ //$NON-NLS-2$
payload.putSingle("lastName", "CreatedUnitTest");
// $NON-NLS-1$
WebTarget postTarget = client.target(getRestUrl(null) + "/nosql/create");
Response response = postTarget.request().post(Entity.form(payload));
assertEquals(303, response.getStatus());
}
// There should be at least one now
{
Response response = target.request().get();
String json = response.readEntity(String.class);
Map<String, Object> jsonObject = (Map<String, Object>) JsonParser.fromJson(JsonJavaFactory.instance, json);
// $NON-NLS-1$
List<Map<String, Object>> byQueryLastName = (List<Map<String, Object>>) jsonObject.get("byQueryLastName");
assertFalse(byQueryLastName.isEmpty());
Map<String, Object> entry = byQueryLastName.get(0);
// $NON-NLS-1$ //$NON-NLS-2$
assertEquals("CreatedUnitTest", entry.get("lastName"));
// $NON-NLS-1$
assertFalse(((String) entry.get("unid")).isEmpty());
}
}
use of jakarta.ws.rs.core.MultivaluedMap in project incubator-hugegraph by apache.
the class NeighborRankTraverser method neighborRank.
public List<Map<Id, Double>> neighborRank(Id source, List<Step> steps) {
E.checkNotNull(source, "source vertex id");
this.checkVertexExist(source, "source vertex");
E.checkArgument(!steps.isEmpty(), "The steps can't be empty");
MultivaluedMap<Id, Node> sources = newMultivalueMap();
sources.add(source, new Node(source, null));
boolean sameLayerTransfer = true;
long access = 0;
// Results: ranks of each layer
List<Ranks> ranks = newList();
ranks.add(Ranks.of(source, 1.0));
for (Step step : steps) {
Ranks lastLayerRanks = ranks.get(ranks.size() - 1);
Map<Id, Double> sameLayerIncrRanks = newMap();
List<Adjacencies> adjacencies = newList();
MultivaluedMap<Id, Node> newVertices = newMultivalueMap();
// Traversal vertices of previous level
for (Map.Entry<Id, List<Node>> entry : sources.entrySet()) {
Id vertex = entry.getKey();
Iterator<Edge> edges = this.edgesOfVertex(vertex, step.edgeStep);
Adjacencies adjacenciesV = new Adjacencies(vertex);
Set<Id> sameLayerNodesV = newIdSet();
Map<Integer, Set<Id>> prevLayerNodesV = newMap();
while (edges.hasNext()) {
HugeEdge edge = (HugeEdge) edges.next();
Id target = edge.id().otherVertexId();
// Determine whether it belongs to the same layer
if (this.belongToSameLayer(sources.keySet(), target, sameLayerNodesV)) {
continue;
}
/*
* Determine whether it belongs to the previous layers,
* if it belongs to, update the weight, but don't pass
* any more
*/
if (this.belongToPrevLayers(ranks, target, prevLayerNodesV)) {
continue;
}
for (Node n : entry.getValue()) {
// If have loop, skip target
if (n.contains(target)) {
continue;
}
Node newNode = new Node(target, n);
adjacenciesV.add(newNode);
// Add adjacent nodes to sources of next step
newVertices.add(target, newNode);
checkCapacity(this.capacity, ++access, "neighbor rank");
}
}
long degree = sameLayerNodesV.size() + prevLayerNodesV.size() + adjacenciesV.nodes().size();
if (degree == 0L) {
continue;
}
adjacenciesV.degree(degree);
adjacencies.add(adjacenciesV);
double incr = lastLayerRanks.getOrDefault(vertex, 0.0) * this.alpha / degree;
// Merge the increment of the same layer node
this.mergeSameLayerIncrRanks(sameLayerNodesV, incr, sameLayerIncrRanks);
// Adding contributions to the previous layers
this.contributePrevLayers(ranks, incr, prevLayerNodesV);
}
Ranks newLayerRanks;
if (sameLayerTransfer) {
// First contribute to last layer, then pass to the new layer
this.contributeLastLayer(sameLayerIncrRanks, lastLayerRanks);
newLayerRanks = this.contributeNewLayer(adjacencies, lastLayerRanks, step.capacity);
} else {
// First pass to the new layer, then contribute to last layer
newLayerRanks = this.contributeNewLayer(adjacencies, lastLayerRanks, step.capacity);
this.contributeLastLayer(sameLayerIncrRanks, lastLayerRanks);
}
ranks.add(newLayerRanks);
// Re-init sources
sources = newVertices;
}
return this.topRanks(ranks, steps);
}
use of jakarta.ws.rs.core.MultivaluedMap in project incubator-hugegraph by apache.
the class LoginApiTest method testVerify.
@Test
public void testVerify() {
Response r;
String result;
r = this.login("test", "test");
result = assertResponseStatus(200, r);
assertJsonContains(result, "token");
String token = this.tokenFromResponse(result);
String path = Paths.get(PATH, "verify").toString();
MultivaluedMap<String, Object> headers = new MultivaluedHashMap<>();
headers.add(HttpHeaders.AUTHORIZATION, "Bearer " + token);
r = client().get(path, headers);
result = assertResponseStatus(200, r);
assertJsonContains(result, "user_id");
assertJsonContains(result, "user_name");
Map<String, Object> user = JsonUtil.fromJson(result, new TypeReference<Map<String, Object>>() {
});
Assert.assertEquals(this.userId4Test, user.get("user_id"));
Assert.assertEquals("test", user.get("user_name"));
String invalidToken = "eyJhbGciOiJIUzI1NiJ9.eyJ1caVyX25hb" + "WUiOiJ0ZXN0IiwidXNlcl9pZCI6Ii02Mzp0ZXN0I" + "iwiZXhwIjoxNjI0MzUzMjUyfQ.kYot-3mSGlfSbE" + "MzxrTs84q8YanhTTxtsKPPG25CNxA";
headers = new MultivaluedHashMap<>();
headers.add(HttpHeaders.AUTHORIZATION, "Bearer " + invalidToken);
r = client().get(path, headers);
assertResponseStatus(401, r);
invalidToken = "123.ansfaf";
headers = new MultivaluedHashMap<>();
headers.add(HttpHeaders.AUTHORIZATION, "Bearer " + invalidToken);
r = client().get(path, headers);
assertResponseStatus(401, r);
}
Aggregations