org.bdware.doip.event.NaiveSubscriber Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of doip-audit-tool Show documentation
Show all versions of doip-audit-tool Show documentation
doip audit tool developed by bdware
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;
}
}