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

org.bdware.doip.event.NaiveSubscriber Maven / Gradle / Ivy

There is a newer version: 1.5.4
Show newest version
package org.bdware.doip.event;

import com.google.gson.JsonObject;
import org.bdware.doip.codec.doipMessage.DoipMessage;
import org.bdware.doip.codec.doipMessage.DoipMessageFactory;
import org.bdware.doip.codec.doipMessage.DoipResponseCode;
import org.bdware.doip.endpoint.event.Subscriber;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

public abstract class NaiveSubscriber implements Subscriber {
    public NaiveSubscriber() {
    }


    @Override
    public DoipMessage receiveData(String topicId, String publishId, DoipMessage request) {
        try {
            onReceiveData(topicId, publishId, request);
            DoipMessageFactory.DoipMessageBuilder builder = new DoipMessageFactory.DoipMessageBuilder();
            builder.createResponse(DoipResponseCode.Success, request).setBody(request.body.getEncodedData());
            return builder.create();
        } catch (Exception e) {
            ByteArrayOutputStream bo = new ByteArrayOutputStream();
            e.printStackTrace(new PrintStream(bo));
            DoipMessageFactory.DoipMessageBuilder builder = new DoipMessageFactory.DoipMessageBuilder();
            builder.createResponse(DoipResponseCode.UnKnownError, request);
            builder.setBody(bo.toByteArray());
            return builder.create();
        }
    }
    @Override
    public DoipMessage receiveHash(String topicId, String subscriberId, DoipMessage data) {
        throw new IllegalStateException("unsupported message type");
    }

    @Override
    public DoipMessage receiveDataAndHash(String topicId, String subscriberId, DoipMessage data) {
        throw new IllegalStateException("unsupported message type");
    }

    @Override
    public void receiveMerkelConfiguration(String topicId, JsonObject configuration, DoipMessage request) {
        //unsupported message type
        return;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy