Search in sources :

Example 1 with Headers

use of org.jboss.resteasy.core.Headers in project openremote by openremote.

the class HTTPProtocol method doLinkAttribute.

@Override
protected void doLinkAttribute(String assetId, Attribute<?> attribute, HTTPAgentLink agentLink) {
    AttributeRef attributeRef = new AttributeRef(assetId, attribute.getName());
    String method = agentLink.getMethod().map(Enum::name).orElse(DEFAULT_HTTP_METHOD);
    String path = agentLink.getPath().orElse(null);
    String contentType = agentLink.getContentType().orElse(null);
    Map<String, List<String>> headers = agentLink.getHeaders().orElse(null);
    Map<String, List<String>> queryParams = agentLink.getQueryParameters().orElse(null);
    Integer pollingMillis = agentLink.getPollingMillis().map(millis -> Math.max(millis, MIN_POLLING_MILLIS)).orElse(null);
    boolean pagingEnabled = agentLink.getPagingMode().orElse(false);
    String pollingAttribute = agentLink.getPollingAttribute().orElse(null);
    if (!TextUtil.isNullOrEmpty(pollingAttribute)) {
        synchronized (pollingLinkedAttributeMap) {
            AttributeRef pollingSourceRef = new AttributeRef(attributeRef.getId(), pollingAttribute);
            pollingLinkedAttributeMap.compute(pollingSourceRef, (ref, links) -> {
                if (links == null) {
                    links = new HashSet<>();
                }
                links.add(attributeRef);
                return links;
            });
        }
    }
    String body = agentLink.getWriteValue().orElse(null);
    if (client == null) {
        LOG.warning("Client is undefined: " + this);
        return;
    }
    HttpClientRequest clientRequest = buildClientRequest(path, method, headers != null ? WebTargetBuilder.mapToMultivaluedMap(headers, new MultivaluedHashMap<>()) : null, queryParams != null ? WebTargetBuilder.mapToMultivaluedMap(queryParams, new MultivaluedHashMap<>()) : null, pagingEnabled, contentType);
    LOG.fine("Creating HTTP request for attributeRef '" + clientRequest + "': " + attributeRef);
    requestMap.put(attributeRef, clientRequest);
    Optional.ofNullable(pollingMillis).ifPresent(seconds -> pollingMap.put(attributeRef, schedulePollingRequest(attributeRef, agentLink, clientRequest, body, seconds)));
}
Also used : java.util(java.util) ScheduledFuture(java.util.concurrent.ScheduledFuture) Protocol(org.openremote.model.asset.agent.Protocol) ConnectionStatus(org.openremote.model.asset.agent.ConnectionStatus) URISyntaxException(java.net.URISyntaxException) AttributeRef(org.openremote.model.attribute.AttributeRef) ResponseBuilderImpl(org.jboss.resteasy.specimpl.ResponseBuilderImpl) ValueUtil(org.openremote.model.util.ValueUtil) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) HttpMethod(javax.ws.rs.HttpMethod) WebTargetBuilder(org.openremote.container.web.WebTargetBuilder) Level(java.util.logging.Level) AgentLink(org.openremote.model.asset.agent.AgentLink) MediaType(javax.ws.rs.core.MediaType) Attribute(org.openremote.model.attribute.Attribute) AttributeEvent(org.openremote.model.attribute.AttributeEvent) SyslogCategory(org.openremote.model.syslog.SyslogCategory) TextUtil(org.openremote.model.util.TextUtil) URI(java.net.URI) AttributeState(org.openremote.model.attribute.AttributeState) OAuthGrant(org.openremote.model.auth.OAuthGrant) ValueType(org.openremote.model.value.ValueType) QUERY_PARAMETERS_PROPERTY(org.openremote.container.web.QueryParameterInjectorFilter.QUERY_PARAMETERS_PROPERTY) URIBuilder(org.apache.http.client.utils.URIBuilder) Invocation(javax.ws.rs.client.Invocation) Logger(java.util.logging.Logger) Entity(javax.ws.rs.client.Entity) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) AbstractProtocol(org.openremote.agent.protocol.AbstractProtocol) Container(org.openremote.model.Container) PROTOCOL(org.openremote.model.syslog.SyslogCategory.PROTOCOL) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) BuiltResponse(org.jboss.resteasy.specimpl.BuiltResponse) Headers(org.jboss.resteasy.core.Headers) Response(javax.ws.rs.core.Response) Type(java.lang.reflect.Type) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) Annotation(java.lang.annotation.Annotation) WebTargetBuilder.createClient(org.openremote.container.web.WebTargetBuilder.createClient) UsernamePassword(org.openremote.model.auth.UsernamePassword) WebTarget(javax.ws.rs.client.WebTarget) QueryParameterInjectorFilter(org.openremote.container.web.QueryParameterInjectorFilter) ProtocolUtil(org.openremote.model.protocol.ProtocolUtil) GlobalLock.withLock(org.openremote.container.concurrent.GlobalLock.withLock) AttributeRef(org.openremote.model.attribute.AttributeRef)

Example 2 with Headers

use of org.jboss.resteasy.core.Headers in project brave by openzipkin.

the class ClientRequestContextWrapperTest method putHeader.

@Test
public void putHeader() {
    MultivaluedMap<String, Object> headers = new Headers<>();
    when(request.getHeaders()).thenReturn(headers);
    new ClientRequestContextWrapper(request).header("name", "value");
    assertThat(headers).containsExactly(entry("name", Collections.singletonList("value")));
}
Also used : Headers(org.jboss.resteasy.core.Headers) ClientRequestContextWrapper(brave.jaxrs2.TracingClientFilter.ClientRequestContextWrapper) Test(org.junit.Test)

Aggregations

Headers (org.jboss.resteasy.core.Headers)2 ClientRequestContextWrapper (brave.jaxrs2.TracingClientFilter.ClientRequestContextWrapper)1 Annotation (java.lang.annotation.Annotation)1 Type (java.lang.reflect.Type)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 java.util (java.util)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1 TimeUnit (java.util.concurrent.TimeUnit)1 Consumer (java.util.function.Consumer)1 Level (java.util.logging.Level)1 Logger (java.util.logging.Logger)1 HttpMethod (javax.ws.rs.HttpMethod)1 Entity (javax.ws.rs.client.Entity)1 Invocation (javax.ws.rs.client.Invocation)1 WebTarget (javax.ws.rs.client.WebTarget)1 MediaType (javax.ws.rs.core.MediaType)1 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)1 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)1 Response (javax.ws.rs.core.Response)1