Commit e193235b by amir

add getHeaders in IRequest

parent 172c1b1e
group 'com.ipgallery.common'
version '2.0.0'
version '2.0.0-services'
apply plugin: 'java'
apply plugin: 'maven-publish'
......
......@@ -22,4 +22,6 @@
// });
- add static page for monitor metrics that calls http://localhost:32000/_mon/_stat?viewType=list
periodically via jquery and display the metrics in a table
\ No newline at end of file
- periodically via jquery and display the metrics in a table
- Add zipkin to trace and monitor requests across microservices
\ No newline at end of file
......@@ -2,6 +2,7 @@ package microservice.io.iface;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
public interface IRequest
......@@ -26,6 +27,13 @@ public interface IRequest
*/
List<String> getHeader(String headerName);
/**
* return map of the request headers name with list of values
* since there can multiple headers with the same name
* @return
*/
Map<String, List<String>> getHeaders();
public boolean startAsync(Runnable asyncFunc);
}
......@@ -3,6 +3,7 @@ package microservice.io.impl;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
//import com.sun.xml.internal.ws.api.message.stream.InputStreamMessage;
......@@ -61,6 +62,11 @@ public class IRequestMBIImpl implements IRequest
}
@Override
public Map<String, List<String>> getHeaders() {
return null;
}
@Override
public boolean startAsync(Runnable asyncFunc) {
return false;
}
......
package microservice.io.impl;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import io.undertow.server.HttpServerExchange;
import io.undertow.util.HeaderValues;
import microservice.io.iface.IRequest;
public class IRequestRestImpl implements IRequest
......@@ -45,6 +50,15 @@ public class IRequestRestImpl implements IRequest
}
@Override
public Map<String, List<String>> getHeaders(){
Map<String, List<String>> headersDeque = new HashMap<>(exchange.getRequestHeaders().size());
for (HeaderValues headerValues : exchange.getRequestHeaders()){
headersDeque.put(headerValues.getHeaderName().toString(), Arrays.asList(headerValues.toArray()));
}
return headersDeque;
}
@Override
public List<String> getHeader(String headerName) {
return exchange.getRequestHeaders().get(headerName);
}
......
......@@ -13,6 +13,7 @@ import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.util.List;
import java.util.Map;
/**
* Created by amir on 22/05/17.
......@@ -52,6 +53,11 @@ public class RestImpl {
}
@Override
public Map<String, List<String>> getHeaders() {
return null;
}
@Override
public boolean startAsync(Runnable asyncFunc) {
asyncFunc.run();
return true;
......
......@@ -183,6 +183,7 @@ public class TestMicroserviceApp {
ObjectNode objectNode = JsonNodeFactory.instance.objectNode();
if (restContext.pathParameters != null)
restContext.pathParameters.forEach((key,value) -> objectNode.put(key,value));
restContext.request.getHeaders().forEach((key,values) -> objectNode.put(key,values.toString()));
brr.objectNode = objectNode;
restContext.container.writeObjectToResponse(restContext.response,brr);
}
......
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 sign in to comment