From 212bbffc24ccc1cd909cabdc9650491dd221cd60 Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 22 Jan 2009 13:21:50 +0000 Subject: STALTranslator git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@283 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../stal/service/impl/STALRequestBrokerImpl.java | 109 ++++++++++++++------- .../gv/egiz/stal/service/impl/STALServiceImpl.java | 4 +- 2 files changed, 78 insertions(+), 35 deletions(-) (limited to 'BKUOnline/src/main/java/at') diff --git a/BKUOnline/src/main/java/at/gv/egiz/stal/service/impl/STALRequestBrokerImpl.java b/BKUOnline/src/main/java/at/gv/egiz/stal/service/impl/STALRequestBrokerImpl.java index 252327d3..a617c61f 100644 --- a/BKUOnline/src/main/java/at/gv/egiz/stal/service/impl/STALRequestBrokerImpl.java +++ b/BKUOnline/src/main/java/at/gv/egiz/stal/service/impl/STALRequestBrokerImpl.java @@ -24,13 +24,14 @@ import at.gv.egiz.stal.QuitRequest; import at.gv.egiz.stal.STALRequest; import at.gv.egiz.stal.STALResponse; import at.gv.egiz.stal.SignRequest; +import at.gv.egiz.stal.service.translator.STALTranslator; +import at.gv.egiz.stal.service.translator.TranslationException; import at.gv.egiz.stal.service.types.InfoboxReadRequestType; import at.gv.egiz.stal.service.types.ObjectFactory; import at.gv.egiz.stal.service.types.QuitRequestType; import at.gv.egiz.stal.service.types.RequestType; import at.gv.egiz.stal.service.types.ResponseType; import at.gv.egiz.stal.service.types.SignRequestType; -import at.gv.egiz.stal.util.STALTranslator; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -54,7 +55,8 @@ public class STALRequestBrokerImpl implements STALRequestBroker { private static final Log log = LogFactory.getLog(STALRequestBrokerImpl.class); - private ObjectFactory stalObjFactory = new ObjectFactory(); + private ObjectFactory of = new ObjectFactory(); + private STALTranslator translator = new STALTranslator(); private boolean interrupted = false; @@ -69,6 +71,7 @@ public class STALRequestBrokerImpl implements STALRequestBroker { if (timeoutMillisec <= 0) timeoutMillisec = DEFAULT_TIMEOUT_MS; timeout = timeoutMillisec; +// translator.registerTranslationHandler(handler); requests = new ArrayList>(); responses = new ArrayList>(); hashDataInputs = new ArrayList(); @@ -97,42 +100,70 @@ public class STALRequestBrokerImpl implements STALRequestBroker { hashDataInputs.clear(); for (STALRequest stalRequest : stalRequests) { + try { + JAXBElement request = translator.translate(stalRequest); + requests.add(request); if (stalRequest instanceof SignRequest) { - log.trace("Received SignRequest, keep HashDataInput."); - SignRequestType reqT = stalObjFactory.createSignRequestType(); - reqT.setKeyIdentifier(((SignRequest) stalRequest).getKeyIdentifier()); - reqT.setSignedInfo(((SignRequest) stalRequest).getSignedInfo()); - JAXBElement req = stalObjFactory.createGetNextRequestResponseTypeSignRequest(reqT); - requests.add(req); - //DataObjectHashDataInput with reference caching enabled DataObject + //TODO refactor SignRequestType to keep HDI + // and getHashDataInput() accesses request obj + // (requests are cleared only when we receive the response) + // DataObjectHashDataInput with reference caching enabled DataObject hashDataInputs.addAll(((SignRequest) stalRequest).getHashDataInput()); - break; - } else if (stalRequest instanceof InfoboxReadRequest) { - log.trace("Received InfoboxReadRequest"); - InfoboxReadRequestType reqT = new InfoboxReadRequestType(); - reqT.setInfoboxIdentifier(((InfoboxReadRequest) stalRequest).getInfoboxIdentifier()); - reqT.setDomainIdentifier(((InfoboxReadRequest) stalRequest).getDomainIdentifier()); - JAXBElement req = stalObjFactory.createGetNextRequestResponseTypeInfoboxReadRequest(reqT); - requests.add(req); } else if (stalRequest instanceof QuitRequest) { log.trace("Received QuitRequest, do not wait for responses."); - QuitRequestType reqT = stalObjFactory.createQuitRequestType(); - JAXBElement req = stalObjFactory.createGetNextRequestResponseTypeQuitRequest(reqT); - requests.add(req); - log.trace("notifying request consumers"); - requests.notify(); - return new ArrayList(); - } else { - log.error("Received unsupported STAL request: " + stalRequest.getClass().getName() + ", send QUIT"); - requests.clear(); - QuitRequestType reqT = stalObjFactory.createQuitRequestType(); - JAXBElement req = stalObjFactory.createGetNextRequestResponseTypeQuitRequest(reqT); - requests.add(req); log.trace("notifying request consumers"); requests.notify(); return new ArrayList(); } + } catch (TranslationException ex) { + log.error(ex.getMessage() + ", send QUIT"); + requests.clear(); + QuitRequestType reqT = of.createQuitRequestType(); + JAXBElement req = of.createGetNextRequestResponseTypeQuitRequest(reqT); + requests.add(req); + log.trace("notifying request consumers"); + requests.notify(); + return new ArrayList(); + } } + + +// if (stalRequest instanceof SignRequest) { +// log.trace("Received SignRequest, keep HashDataInput."); +// SignRequestType reqT = of.createSignRequestType(); +// reqT.setKeyIdentifier(((SignRequest) stalRequest).getKeyIdentifier()); +// reqT.setSignedInfo(((SignRequest) stalRequest).getSignedInfo()); +// JAXBElement req = of.createGetNextRequestResponseTypeSignRequest(reqT); +// requests.add(req); +// //DataObjectHashDataInput with reference caching enabled DataObject +// hashDataInputs.addAll(((SignRequest) stalRequest).getHashDataInput()); +// break; +// } else if (stalRequest instanceof InfoboxReadRequest) { +// log.trace("Received InfoboxReadRequest"); +// InfoboxReadRequestType reqT = new InfoboxReadRequestType(); +// reqT.setInfoboxIdentifier(((InfoboxReadRequest) stalRequest).getInfoboxIdentifier()); +// reqT.setDomainIdentifier(((InfoboxReadRequest) stalRequest).getDomainIdentifier()); +// JAXBElement req = of.createGetNextRequestResponseTypeInfoboxReadRequest(reqT); +// requests.add(req); +// } else if (stalRequest instanceof QuitRequest) { +// log.trace("Received QuitRequest, do not wait for responses."); +// QuitRequestType reqT = of.createQuitRequestType(); +// JAXBElement req = of.createGetNextRequestResponseTypeQuitRequest(reqT); +// requests.add(req); +// log.trace("notifying request consumers"); +// requests.notify(); +// return new ArrayList(); +// } else { +// log.error("Received unsupported STAL request: " + stalRequest.getClass().getName() + ", send QUIT"); +// requests.clear(); +// QuitRequestType reqT = of.createQuitRequestType(); +// JAXBElement req = of.createGetNextRequestResponseTypeQuitRequest(reqT); +// requests.add(req); +// log.trace("notifying request consumers"); +// requests.notify(); +// return new ArrayList(); +// } +// } log.trace("notifying request consumers"); requests.notify(); } @@ -150,12 +181,24 @@ public class STALRequestBrokerImpl implements STALRequestBroker { } } log.trace("consuming responses"); - List resps = STALTranslator.toSTAL(responses); + List stalResponses = new ArrayList(); + try { + for (JAXBElement resp : responses) { + STALResponse stalResp = translator.translate(resp); + stalResponses.add(stalResp); + } + } catch (TranslationException ex) { + log.error(ex.getMessage() + ", return ErrorResponse (4000)"); + ErrorResponse stalResp = new ErrorResponse(4000); + stalResp.setErrorMessage(ex.getMessage()); + stalResponses = Collections.singletonList((STALResponse) stalResp); + } + responses.clear(); log.trace("notifying response producers"); responses.notify(); - return resps; + return stalResponses; } } catch (InterruptedException ex) { log.warn("interrupt in handleRequest(): " + ex.getMessage()); @@ -277,8 +320,8 @@ public class STALRequestBrokerImpl implements STALRequestBroker { } private List> createSingleQuitRequest() { - QuitRequestType quitT = stalObjFactory.createQuitRequestType(); - JAXBElement quit = stalObjFactory.createGetNextRequestResponseTypeQuitRequest(quitT); + QuitRequestType quitT = of.createQuitRequestType(); + JAXBElement quit = of.createGetNextRequestResponseTypeQuitRequest(quitT); ArrayList> l = new ArrayList>(); l.add(quit); return l; diff --git a/BKUOnline/src/main/java/at/gv/egiz/stal/service/impl/STALServiceImpl.java b/BKUOnline/src/main/java/at/gv/egiz/stal/service/impl/STALServiceImpl.java index 45629869..afeba9cb 100644 --- a/BKUOnline/src/main/java/at/gv/egiz/stal/service/impl/STALServiceImpl.java +++ b/BKUOnline/src/main/java/at/gv/egiz/stal/service/impl/STALServiceImpl.java @@ -147,8 +147,8 @@ public class STALServiceImpl implements STALPortType { sb.append("] containing "); sb.append(responsesIn.size()); sb.append(" responses: "); - for (Object respIn : responsesIn) { - sb.append(respIn.getClass()); + for (JAXBElement respIn : responsesIn) { + sb.append(respIn.getValue().getClass()); sb.append(' '); } log.debug(sb.toString()); -- cgit v1.2.3