19 package org.turro.financials.handshake;
21 import java.io.IOException;
23 import java.util.logging.Level;
24 import java.util.logging.Logger;
25 import javax.servlet.ServletContext;
26 import javax.servlet.http.HttpServletRequest;
27 import javax.servlet.http.HttpServletResponse;
28 import org.turro.elephant.context.ElephantContext;
29 import org.turro.elephant.direct.DirectContent;
30 import org.turro.elephant.direct.DirectContents;
31 import org.turro.elephant.direct.IDirectContent;
32 import org.turro.financials.entity.Contract;
33 import org.turro.financials.entity.ContractHandshake;
34 import org.turro.financials.entity.Document;
35 import org.turro.financials.entity.Product;
36 import org.turro.http.ElephantPost;
37 import org.turro.http.ElephantResponse;
38 import org.turro.http.ElephantResponseType;
44 @DirectContent(identifier=
"handshake")
52 public boolean itsMe(String
id) {
53 return getIdentifier().equals(
id);
57 public boolean myTurn(HttpServletRequest request) {
62 public void execute(ServletContext context, HttpServletRequest request, HttpServletResponse response) {
65 Map<String, String[]> pars = request.getParameterMap();
69 case HANDSHAKE_STATUS:
87 case HANDSHAKE_PETITION:
94 case HANDSHAKE_ACCEPTANCE:
98 pars.containsKey(
"remoteServer") ? pars.get(
"remoteServer")[0] :
null,
99 pars.containsKey(
"remoteId") ? pars.get(
"remoteId")[0] :
null,
108 case HANDSHAKE_DOCUMENT:
116 case HANDSHAKE_PRODUCT:
119 }
catch (IOException ex) {
126 if(handshake !=
null) {
132 }
catch (IOException ex) {
145 }
catch (IOException ex) {
153 if(handshake !=
null) {
161 }
catch (IOException ex) {
171 if(handshake !=
null) {
177 }
catch (IOException ex) {
186 if(handshake !=
null) {
193 }
catch (IOException ex) {
static String logMsg(String msg)
static boolean isYourTurn(HttpServletRequest request, String path)
static String createURL(String server, String id)
ContractHandshake getContractHandshake()
static void saveHandshakePetition(HandshakeContract hc)
static String createJsonFromContract(Contract contract)
static ContractHandshake getContractHandshakeFromHandshake(HandshakeContract hc)
static boolean updateRemoteId(String remoteServer, String remoteId, long contractId)
static HandshakeContract createHandshakeFromJson(String value)
static HandshakeDocument createHandshakeFromJson(String value)
static void saveHandshakeDocument(HandshakeDocument hd)
static String createJsonFromDocument(Document document)
static String createJsonFromProduct(Product product)
static ElephantResponse sendAcceptance(Contract contract, String remoteServer, Long remoteId)
static ElephantResponse sendDocument(Document document)
static ElephantResponse sendPetition(Contract contract, String remoteUrl)
static ElephantResponse checkStatus(Contract contract)
void execute(ServletContext context, HttpServletRequest request, HttpServletResponse response)
static ElephantResponse sendProduct(Contract contract, Product product)
static String getIdentifier()
boolean myTurn(HttpServletRequest request)
ElephantResponse doPost()
void addParameter(String name, String value)
static boolean isValid(HttpServletRequest request)
static void writeToResponse(HttpServletResponse response, ElephantResponseType type, String message, String code)
static HandshakeAction getAction(String value)