All Downloads are FREE. Search and download functionalities are using the official Maven repository.

at.spardat.xma.boot.transport.Transport Maven / Gradle / Ivy

/*******************************************************************************
 * Copyright (c) 2003, 2007 s IT Solutions AT Spardat GmbH .
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     s IT Solutions AT Spardat GmbH - initial API and implementation
 *******************************************************************************/

/*
 * Created on 16.05.2003
 */
package at.spardat.xma.boot.transport;

import java.util.Properties;

import at.spardat.xma.boot.component.IRtXMASessionClient;
import at.spardat.xma.boot.logger.LogLevel;

/**
 * this is the interface for the low level xma transport layer used on xma-client side.
 * At this time only an implementation for HTTP is provided, but additional protocols may
 * be added in the future.
 *
 * @author s2877, s3595
 * @version $Id: Transport.java 5899 2010-06-08 14:27:34Z gub $
 *
 */
public abstract class Transport {
    /** cached implementation */
    private static Transport impl;

    /**
     * Loads a resource from a server if it has been changed since modifiedSince.
     *
     * @param   session        the session this event belongs to. may be null.
     * @param   resource       unique identification of the resource.
     * @param   modifiedSince  timestamp of last modification.
     *
     * @return  a result that indicates the server response.
     *          If a new resource is loaded, the data is stored within the result.
     *          the content-length is set, and the buffer can be read by using the method getContent.
     *          If no resource is loaded, the result will only contain informational data about the request.
     *          e.g. a new expiration date.
     *
     * @throws ConnectException if anything goes wrong in the communication with the server, befor
     *      the server changed its state.
     * @throws ServerException if anything goes wrong in the communication with the server, after
     *      the server propably changed its state.
     */
    abstract public Result getResource(IRtXMASessionClient session, XMA_URI resource,long modifiedSince, String etag) throws CommunicationException;

    /**
     * Calls a server side event.
     *
     * @param session the session this event belongs to.
     * @param eventHandler unique identification of the eventhandler.
     * @param input All data that can be read from this InputStream is propagated to the eventhandler.
     * @return an InputStream pointing to the data send back by the enventhandler.
     * @throws ConnectException if anything goes wrong in the communication with the server, befor
     *      the server changed its state.
     * @throws ServerException if anything goes wrong in the communication with the server, after
     *      the server propably changed its state.
     */
    abstract public byte[] callServerEvent(IRtXMASessionClient session,XMA_URI eventHandler,byte[] input) throws CommunicationException;

    /**
     * Get an implementation of Transport. The implementation to use can be configured by the
     * property boot.transport.defaultimpl in the file at/spardat/xma/boot/bootcfg.properties which names
     * the fully qualified class name of the implementation class.
     *
     * @return a Transport - object.
     */
    static public Transport getTransport() {
        if(impl==null) {
            Properties props = new Properties();
            try {
                props.load(Transport.class.getClassLoader().getResourceAsStream("at/spardat/xma/boot/bootcfg.properties")); //$NON-NLS-1$
                String trans = props.getProperty("boot.transport.defaultimpl"); //$NON-NLS-1$
                Class transClass = Class.forName(trans);
                impl = (Transport)transClass.newInstance();
            } catch (Exception e) {
                e.printStackTrace();
                throw new RuntimeException("error reading configuration: ",e); //$NON-NLS-1$
            }
        }
        return impl;
    }

    /**
     * logs the proxy settings at the given level.
     */
    public void logProxyInfo(LogLevel level) {
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy