Commit e193235b by amir

add getHeaders in IRequest

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