com.adaptris.core.http.client.net.MetadataResponseHeaderImpl.java Source code

Java tutorial

Introduction

Here is the source code for com.adaptris.core.http.client.net.MetadataResponseHeaderImpl.java

Source

/*
 * Copyright 2015 Adaptris Ltd.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/

package com.adaptris.core.http.client.net;

import static org.apache.commons.lang.StringUtils.defaultIfEmpty;

import java.net.HttpURLConnection;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.adaptris.core.AdaptrisMessage;
import com.adaptris.core.http.client.ResponseHeaderHandler;

public abstract class MetadataResponseHeaderImpl implements ResponseHeaderHandler<HttpURLConnection> {

    protected transient Logger log = LoggerFactory.getLogger(this.getClass());

    private String metadataPrefix;

    public MetadataResponseHeaderImpl() {

    }

    protected String generateKey(String header) {
        return defaultIfEmpty(getMetadataPrefix(), "") + header;
    }

    public String getMetadataPrefix() {
        return metadataPrefix;
    }

    public void setMetadataPrefix(String metadataPrefix) {
        this.metadataPrefix = metadataPrefix;
    }

    @Override
    public AdaptrisMessage handle(HttpURLConnection src, AdaptrisMessage msg) {
        addMetadata(src.getHeaderFields(), msg);
        return msg;
    }

    protected abstract void addMetadata(Map<String, List<String>> headers, AdaptrisMessage reply);
}