HttpHeaderServiceEndpointDecorator extends ServiceEndpointDecorator<T> { @Override public void configure() { super.configure(); final HTTPClientPolicy httpClientPolicy = getHTTPClientPolicy(); final BindingProvider bindingProvider = (BindingProvider) getPort(); httpClientPolicy.setConnection(null); if (hasKeepAliveForConnection()) { httpClientPolicy.setConnection(ConnectionType.KEEP_ALIVE); } bindingProvider.getRequestContext().remove(NhincConstants.CUSTOM_HTTP_HEADERS); HashMap<String, String> httpHeaders = getCustomHeaders(); if (MapUtils.isNotEmpty(httpHeaders)) { bindingProvider.getRequestContext().put(NhincConstants.CUSTOM_HTTP_HEADERS, httpHeaders); } } HttpHeaderServiceEndpointDecorator(ServiceEndpoint<T> decoratedEndpoint, final AssertionType assertion); @Override void configure();  }
@Test public void testConfigure_WithAssertionValues() throws PropertyAccessException { final CONNECTTestClient<TestServicePortType> testClient = new CONNECTTestClient<>( new TestServicePortDescriptor()); final ServiceEndpoint<TestServicePortType> serviceEndpoint = testClient.getServiceEndpoint(); final PropertyAccessor mockPropAccessor = mock(PropertyAccessor.class); final AssertionType assertion = new AssertionType(); assertion.setKeepAlive("true"); final CONNECTCustomHttpHeadersType assertionHeaders = new CONNECTCustomHttpHeadersType(); assertionHeaders.setHeaderName("headerName"); assertionHeaders.setHeaderValue("headerValue"); assertion.getCONNECTCustomHttpHeaders().add(assertionHeaders); final HttpHeaderServiceEndpointDecorator headerDecorator = new HttpHeaderServiceEndpointDecorator( serviceEndpoint, assertion) { @Override protected PropertyAccessor getPropertyAccessor() { return mockPropAccessor; } }; when(mockPropAccessor.getPropertyNames(NhincConstants.GATEWAY_PROPERTY_FILE)).thenReturn(new HashSet<String>()); headerDecorator.configure(); validateConfiguration(headerDecorator); }
@Test public void testConfigure_WithoutValues() throws PropertyAccessException { final CONNECTTestClient<TestServicePortType> testClient = new CONNECTTestClient<>( new TestServicePortDescriptor()); final ServiceEndpoint<TestServicePortType> serviceEndpoint = testClient.getServiceEndpoint(); final AssertionType assertion = new AssertionType(); final HttpHeaderServiceEndpointDecorator headerDecorator = new HttpHeaderServiceEndpointDecorator( serviceEndpoint, assertion); headerDecorator.configure(); final BindingProvider bp = (BindingProvider) headerDecorator.getPort(); final Map<String, List<String>> bpMap = (Map<String, List<String>>) bp.getRequestContext() .get(NhincConstants.CUSTOM_HTTP_HEADERS); assertNull(bpMap); }
@Test public void testConfigure_WithPropertyValues() throws PropertyAccessException { final CONNECTTestClient<TestServicePortType> testClient = new CONNECTTestClient<>( new TestServicePortDescriptor()); final ServiceEndpoint<TestServicePortType> serviceEndpoint = testClient.getServiceEndpoint(); final PropertyAccessor mockPropAccessor = mock(PropertyAccessor.class); final AssertionType assertion = new AssertionType(); final HttpHeaderServiceEndpointDecorator headerDecorator = new HttpHeaderServiceEndpointDecorator( serviceEndpoint, assertion) { @Override protected PropertyAccessor getPropertyAccessor() { return mockPropAccessor; } }; final String customHeaderName = "customName"; final String customHeaderValue = "customValue"; final Set<String> headerNames = new HashSet<>(); headerNames.add(NhincConstants.CUSTOM_HTTP_HEADERS + "." + customHeaderName); when(mockPropAccessor.getProperty(NhincConstants.GATEWAY_PROPERTY_FILE, NhincConstants.KEEP_ALIVE_PROP)) .thenReturn("True"); when(mockPropAccessor.getPropertyNames(NhincConstants.GATEWAY_PROPERTY_FILE)).thenReturn(headerNames); when(mockPropAccessor.getProperty(NhincConstants.GATEWAY_PROPERTY_FILE, NhincConstants.CUSTOM_HTTP_HEADERS + "." + customHeaderName)).thenReturn(customHeaderValue); headerDecorator.configure(); validateConfiguration(headerDecorator); final BindingProvider bp = (BindingProvider) headerDecorator.getPort(); final Map<String, List<String>> bpMap = (Map<String, List<String>>) bp.getRequestContext() .get(NhincConstants.CUSTOM_HTTP_HEADERS); assertTrue(bpMap.containsKey("customName")); }