Description: Allows you to route a specific web service call to a specific GOS system. Use this code extension type to create code extensions for the web service request that can include the GOS URL, GOS username, and GOS password, so that you are not restricted to those defined in the N4 GOS settings: GOS_WS_URL, GOS_WS_USERNAME, and GOS_WS_PASSWORD. If you do not send these values using the code extension, N4 reads them from the N4 GOS settings, by default.
You cannot send one specific web service call to multiple GOS systems at the same time. However, you can route two web service requests to two different GOS systems based on the code extension definition.
Abstract Base Class: AbstractGosAdaptorInterceptor
Methods: getGosAddress(GosAdaptorExtensionContext inContext, GosAdaptorExtensionResponse inResponse), addMessages(List<UserMessage> inMessages), List<UserMessage> getMessages()
Interface: com.navis.external.road.EGosAdaptorInterceptor
Module: Road
Version Added: 2.2
Requires Code Extension Name or Name Pattern: No
Code Extension Name or Name Pattern: N/A
Where to Specify Code Extensions of this Type: N/A
System-Seeded Code Extensions Using this Type: None
Code Example
Below is an example of this code extension that you can use to route a print-ticket request to GOS1 with Gate ID "MG", and also route a print-ticket request to GOS2 for a different other gate (“MGONE” is used in this example). The "open-gate-arm" and "notify-resume" webservice requests are always sent to GOS1.
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.xml.stream.events.ElementTypeNames;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import java.io.StringReader;
import com.navis.argo.util.XmlUtil;
import com.navis.external.road.AbstractGosAdaptorInterceptor;
import com.navis.framework.persistence.HibernateApi;
import com.navis.road.business.model.TruckVisitDetails;
import com.navis.road.extension.gos.GosAdaptorExtensionContext;
import com.navis.road.extension.gos.GosAdaptorExtensionResponse;
import com.navis.road.extension.gos.GosClient;
public class GosAdaptor1 extends AbstractGosAdaptorInterceptor {
@Override
public void getGosAddress(GosAdaptorExtensionContext inContext, GosAdaptorExtensionResponse inResponse) {
this.log("Called getGosAddress from CodeExtension");
GosClient gosClient = new GosClient();
SAXBuilder builder = new SAXBuilder();
String xmlRequest = inContext.getXmlRequest();
try {
Document document = builder.build(new StringReader(xmlRequest));
if (document.getRootElement().getChild("print-ticket") != null){
Element printTicketElement = document.getRootElement().getChild("print-ticket");
this.log("Processing GOS Request printer-id:"+printTicketElement.getChild("documents").getChild("document").getAttribute(
"printer-id").getValue());
this.log("Processing GOS Request document type:"+printTicketElement.getChild("documents").getChild("document").getAttribute("type").getValue());
this.log("Processing GOS Request doc-key:"+printTicketElement.getChild("documents").getChild("document").getAttribute("doc-key").getValue());
String xmlDocument = printTicketElement.getChild("documents").getChild("document").getChild("content").getText();
try {
org.jdom.Document documentDoc = builder.build(new StringReader(xmlDocument));
Element rootElement = documentDoc.getRootElement();
Element tvElement = ((Element) rootElement.getContent().get(1)).getChild("truckVisit", XmlUtil.ARGO_NAMESPACE) ;
Element tranElement = ((Element) rootElement.getContent().get(1)).getChild("trkTransaction", XmlUtil.ARGO_NAMESPACE);
String tvGkey = tvElement.getChild("tvdtlsTvKey").getText();
TruckVisitDetails tvdtls = (TruckVisitDetails) HibernateApi.getInstance().load(TruckVisitDetails.class,Long.parseLong(tvGkey));
String gateId = tvdtls.getTvdtlsGate().getGateId();
this.log("print document request sent for gate: "+gateId);
this.log("print document request sent for stage: "+tranElement.getChild("tranStageId").getText());
if (gateId == "MG"){
gosClient.setUrl("http://localhost:8280/apex/services/argobasicservice");
} else {
gosClient.setUrl("http://134.37.94.xxx:8280/apex/services/argobasicservice");
}
} catch (Exception e) {
this.log("Exception occured while validating the document: " + e);
}
} else if (document.getRootElement().getChild("open-gate-arm") != null) {
Element openGateArmElement = document.getRootElement().getChild("open-gate-arm");
this.log("Processing GOS Request gate-id:"+openGateArmElement.getChild("gate-id").getText());
this.log("Processing GOS Request stage-id:"+openGateArmElement.getChild("stage-id").getText());
this.log("Processing GOS Request lane-id:"+openGateArmElement.getChild("lane-id").getText());
this.log("Processing GOS Request status:"+openGateArmElement.getChild("status").getText());
gosClient.setUrl("http://localhost:8280/apex/services/argobasicservice");
} else if (document.getRootElement().getChild("notify-resume") != null) {
Element notifyResumeElement = document.getRootElement().getChild("notify-resume");
this.log("Processing GOS Request gate-id:"+notifyResumeElement.getChild("gate-id").getText());
this.log("Processing GOS Request stage-id:"+notifyResumeElement.getChild("stage-id").getText());
this.log("Processing GOS Request lane-id:"+notifyResumeElement.getChild("lane-id").getText());
this.log("Processing GOS Request status:"+notifyResumeElement.getChild("status").getText());
gosClient.setUrl("http://localhost:8280/apex/services/argobasicservice");
}
} catch (Exception e) {
this.log("Exception occured while validating the document: " + e);
}
gosClient.setUserName("admin");
this.log("gosClient URL:"+gosClient.getUrl());
this.log("gosClient User:"+gosClient.getUserName());
inResponse.setGosClient(gosClient);
}
}