org.bdware.doip.audit.client.DelegateDoipMessageCallback 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
The newest version!
package org.bdware.doip.audit.client;
import org.bdware.doip.audit.AuditDoaClient;
import org.bdware.doip.codec.doipMessage.DoipMessage;
import org.bdware.doip.codec.doipMessage.DoipResponseCode;
import org.bdware.doip.endpoint.client.DoipMessageCallback;
import java.net.URI;
public class DelegateDoipMessageCallback implements DoipMessageCallback {
private final AuditDoaClient auditDoaClient;
private final DoipMessageCallback originalCallback;
DoipMessage originalMessage;
AuditDoipClient previousClient;
public DelegateDoipMessageCallback(AuditDoaClient auditDoaClient, AuditDoipClient previousClient, DoipMessageCallback doipMessageCallback, DoipMessage originalMessage) {
this.auditDoaClient = auditDoaClient;
this.originalCallback = doipMessageCallback;
this.originalMessage = originalMessage;
this.previousClient = previousClient;
}
@Override
public void onResult(DoipMessage msg) {
if (msg.header.parameters.response == DoipResponseCode.DelegateRequired) {
try {
if (msg.header.parameters.attributes.has("port")) {
int port = msg.header.parameters.attributes.get("port").getAsInt();
URI uri = new URI(previousClient.serverURL);
String host = uri.getHost();
if (msg.header.parameters.attributes.has("host"))
host = msg.header.parameters.attributes.get("host").getAsString();
String newAddress = String.format("%s://%s:%d", uri.getScheme(), host, port);
String version = "2.1";
if (msg.header.parameters.attributes.has("version"))
version = msg.header.parameters.attributes.get("version").getAsString();
String repoID = previousClient.getServerRepoId();
if (msg.header.parameters.attributes.has("repoID"))
repoID = msg.header.parameters.attributes.get("repoID").getAsString();
AuditDoipClient client = auditDoaClient.getClientByUrl(repoID, newAddress, version);
this.previousClient = client;
client.sendRawMessage(originalMessage, this);
}
} catch (Exception e) {
e.printStackTrace();
originalCallback.onResult(msg);
}
} else originalCallback.onResult(msg);
return;
}
}