aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/protocol
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-12-17 01:10:53 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2019-12-17 01:10:53 -0800
commite4216e7eabcb99c585909a262a1cf8d626b97ca6 (patch)
tree65d58971ec6d2c70e53054a23a0f6057561261d3 /src/main/java/org/traccar/protocol
parentef2bd4662484e4a82bea5afb0d399eed33e859db (diff)
downloadtraccar-server-e4216e7eabcb99c585909a262a1cf8d626b97ca6.tar.gz
traccar-server-e4216e7eabcb99c585909a262a1cf8d626b97ca6.tar.bz2
traccar-server-e4216e7eabcb99c585909a262a1cf8d626b97ca6.zip
Send correct XML response
Diffstat (limited to 'src/main/java/org/traccar/protocol')
-rw-r--r--src/main/java/org/traccar/protocol/GlobalstarProtocolDecoder.java46
1 files changed, 45 insertions, 1 deletions
diff --git a/src/main/java/org/traccar/protocol/GlobalstarProtocolDecoder.java b/src/main/java/org/traccar/protocol/GlobalstarProtocolDecoder.java
index 5739a1224..26af8d5af 100644
--- a/src/main/java/org/traccar/protocol/GlobalstarProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/GlobalstarProtocolDecoder.java
@@ -17,28 +17,40 @@ package org.traccar.protocol;
import com.fasterxml.jackson.databind.util.ByteBufferBackedInputStream;
import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufOutputStream;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
+import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpRequest;
+import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpResponseStatus;
+import io.netty.handler.codec.http.HttpVersion;
import org.traccar.BaseHttpProtocolDecoder;
import org.traccar.DeviceSession;
+import org.traccar.NetworkMessage;
import org.traccar.Protocol;
import org.traccar.helper.DataConverter;
import org.traccar.model.Position;
import org.w3c.dom.Document;
+import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import java.net.SocketAddress;
+import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
@@ -67,6 +79,38 @@ public class GlobalstarProtocolDecoder extends BaseHttpProtocolDecoder {
}
}
+ private void sendResponse(Channel channel, String messageId) throws TransformerException {
+
+ Document document = documentBuilder.newDocument();
+ Element rootElement = document.createElement("stuResponseMsg");
+ rootElement.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
+ rootElement.setAttribute(
+ "xsi:noNamespaceSchemaLocation", "http://cody.glpconnect.com/XSD/StuResponse_Rev1_0.xsd");
+ rootElement.setAttribute("deliveryTimeStamp", new SimpleDateFormat("dd/MM/yyyy hh:mm:ss z").format(new Date()));
+ rootElement.setAttribute("messageID", "00000000000000000000000000000000");
+ rootElement.setAttribute("correlationID", messageId);
+ document.appendChild(rootElement);
+
+ Element state = document.createElement("state");
+ state.appendChild(document.createTextNode("pass"));
+ rootElement.appendChild(state);
+
+ Element stateMessage = document.createElement("stateMessage");
+ stateMessage.appendChild(document.createTextNode("Messages received and stored successfully"));
+ rootElement.appendChild(stateMessage);
+
+ Transformer transformer = TransformerFactory.newInstance().newTransformer();
+ ByteBuf content = Unpooled.buffer();
+ transformer.transform(new DOMSource(document), new StreamResult(new ByteBufOutputStream(content)));
+
+ FullHttpResponse response = new DefaultFullHttpResponse(
+ HttpVersion.HTTP_1_1, HttpResponseStatus.OK, content);
+ if (channel != null) {
+ channel.writeAndFlush(new NetworkMessage(response, channel.remoteAddress()));
+ }
+ }
+
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -112,7 +156,7 @@ public class GlobalstarProtocolDecoder extends BaseHttpProtocolDecoder {
}
}
- sendResponse(channel, HttpResponseStatus.OK);
+ sendResponse(channel, document.getFirstChild().getAttributes().getNamedItem("messageID").getNodeValue());
return positions;
}