Package com.fuelkiosk.camture.ws

Source Code of com.fuelkiosk.camture.ws.CamtureConnection

/*
* Provides a connection to the camture service, can send stream requests and
* meta data
*/
package com.fuelkiosk.camture.ws;


import com.fuelkiosk.camture.metaws.ObjectFactory;
import com.fuelkiosk.camture.streamsws.ConnectionType;
import com.fuelkiosk.camture.streamsws.ImageInfoType;
import com.fuelkiosk.camture.streamsws.ResultType;
import com.fuelkiosk.camture.streamsws.StreamChangeRequestType;
import com.fuelkiosk.camture.streamsws.StreamControlService;
import com.fuelkiosk.camture.streamsws.StreamRequestPortType;
import com.fuelkiosk.camture.streamsws.StreamRequestResponseType;
import com.fuelkiosk.camture.streamsws.StreamRequestType;
import com.fuelkiosk.camture.streamsws.StreamSelect;
import com.fuelkiosk.camture.streamsws.StreamStopRequestType;
import com.fuelkiosk.camture.streamsws.TimePeriodType;
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.logging.Logger;
import javax.xml.namespace.QName;
import javax.xml.ws.BindingProvider;

/**
* The class is used to send requests to the camture web service, after
* constructing a conncection simply call sendRequest and sendStopRequest
* Use the createxxx methods to constrct the request objects
*
*/
public class CamtureConnection {

    private static final Logger logger = Logger.getLogger(CamtureConnection.class.getName());
    private static final String STREAMS_WSDL_FILE = "streamsws.wsdl";
    private static final String STREAMS_SERVICE_FILE = "streamsws.php";
    private static final String STREAMS_NAMESPACE = "http://www.fuelkiosk.com/camture/streamsws.wsdl";
    private static final QName STREAMSSERVICENAME = new QName(STREAMS_NAMESPACE, "streamControlService");
    private static final QName STREAMSPORTNAME = new QName(STREAMS_NAMESPACE, "streamRequestPort");
    transient private final ObjectFactory factory = new ObjectFactory();
    transient private final StreamControlService service;
    transient private final StreamRequestPortType port;

    /**
     * Create a connection to the camture web service.
     * Also creates the port and binds it to the servers address
     * @param serverAddress
     * @throws java.net.MalformedURLException
     */
    public CamtureConnection(final String serverAddress)
            throws MalformedURLException {

        service = new StreamControlService(
                new URL("http", serverAddress,
                -1, STREAMS_WSDL_FILE), STREAMSSERVICENAME);
        port = service.getPort(STREAMSPORTNAME, StreamRequestPortType.class);
        ((BindingProvider) port).getRequestContext().put(
                BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                new URL("http", serverAddress.toString(),
                -1, STREAMS_SERVICE_FILE).toExternalForm());
    }

    /**
     * Send a stream request to the web service
     * @param request to send
     * @return the services response
     */
    public StreamRequestResponseType sendRequest(final StreamRequestType request) {
        return port.streamRequestMethod(request);
    }

    /**
     * Send stop request to the web serive
     * @param request details of the stream to stop
     * @return the result of the request
     */
    public ResultType sendStopRequest(final StreamStopRequestType request) {
        return port.streamStopRequestMethod(request);
    }

    /**
     * Send a stream request to the web service
     * @param request to send
     * @return the services response
     */
    public StreamRequestResponseType sendRequest(final StreamChangeRequestType request) {
        return port.streamRequestChangeMethod(request);
    }

    /**
     * Create a stop request
     * @param connection connection requesting the stop
     * @param streamId
     * @return StreamStopRequestType
     */
    public StreamStopRequestType createStopRequest(
            final ConnectionType connection,
            final long streamId) {
        final StreamStopRequestType stop = factory.createStreamStopRequestType();
        stop.setConnection(connection);
        stop.setStreamInstanceId(BigInteger.valueOf(streamId));
        return stop;
    }

    /**
     * Create a stream request
     * @param stream
     * @param imageInfo
     * @param time
     * @param connection
     * @return StreamRequestType
     */
    public StreamRequestType createStreamRequest(
            final StreamSelect stream,
            final ImageInfoType imageInfo,
            final TimePeriodType time,
            final ConnectionType connection) {

        final StreamRequestType request = factory.createStreamRequestType();
        request.setConnection(connection);
        request.setImageInfo(imageInfo);
        request.setStream(stream);
        request.setTimePeriod(time);
        return request;
    }

     /**
     * Create a stream request
     * @param stream
     * @param imageInfo
     * @param time
     * @param connection
     * @return StreamRequestType
     */
    public StreamChangeRequestType createStreamChangeRequest(
            final StreamRequestType request,
            final long streamId) {

        final StreamChangeRequestType change = factory.createStreamChangeRequestType();
        change.setStreamDetails(request);
        change.setStreamInstanceId(BigInteger.valueOf(streamId));
        return change;
    }

    /**
     * Stream select types.
     */
    public enum StreamSelectType {

        /** Select a stream using a fuelling point.*/
        FuelingPointID,
        /** Select a stream using the cameras ID.*/
        CameraID
    }

    /**
     * Create stream select.
     * @param type a CamtureConnection.StreamSelectType
     * @param selectId
     * @return StreamSelect
     */
    public StreamSelect createStreamSelect(
            final StreamSelectType type,
            final int selectId) {
        final StreamSelect stream = factory.createStreamSelect();
        switch (type) {
            case CameraID:
                stream.setStreamID(BigInteger.valueOf(selectId));
                break;
            case FuelingPointID:
                stream.setClientID(Integer.valueOf(selectId));
                break;
            default:
                logger.severe("Unknown Type:" + type);
        }
        return stream;
    }

    /**
     * Create an Image info object.
     * Describes the size and quality of the video stream requested
     * @param width
     * @param height
     * @param colourDepth
     * @param quality
     * @return
     */
    public ImageInfoType createImageInfo(
            final int width,
            final int height,
            final int colourDepth,
            final int quality) {
        final ImageInfoType imageInfo = factory.createImageInfoType();
        imageInfo.setColourDepth(BigInteger.valueOf(colourDepth));
        imageInfo.setWidth(BigInteger.valueOf(width));
        imageInfo.setHeight(BigInteger.valueOf(height));
        imageInfo.setQuality(BigInteger.valueOf(quality));
        return imageInfo;
    }

    /**
     * Create a connection object.
     * Describes the client connection to stream to.
     * This method uses the localhost address, multihomed systems should set
     * the correct address once returned
     * @param port
     * @return
     */
    public ConnectionType createConnection(final int port) {
        final ConnectionType connection = factory.createConnectionType();
        String host;
        try {
            host = InetAddress.getLocalHost().getHostAddress();           
        } catch (UnknownHostException ex) {
            logger.warning(ex.getLocalizedMessage());
            host = "";
        }
        connection.setHostAddress(host);
        connection.setPort(BigInteger.valueOf(port));
        return connection;
    }

    /**
     * Create a time period, this is used to specify what period of video to
     * stream.
     * @param fuellingPoint
     * @param transSeqNumber Trans number to show, if null live vide is shown
     * @return TimePeriodType
     */
    public TimePeriodType createTimePeriod(final int clientId,
            final Integer transSeqNumber) {

        final TimePeriodType timePeriod = factory.createTimePeriodType();
        timePeriod.setClientID(clientId);
        timePeriod.setTransSqeNum(transSeqNumber);
        return timePeriod;
    }
}
TOP

Related Classes of com.fuelkiosk.camture.ws.CamtureConnection

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.