From 43812f2c0d81eaba7e07ece82acf396ac35e2b5d Mon Sep 17 00:00:00 2001 From: clemenso Date: Mon, 15 Sep 2008 18:03:25 +0000 Subject: encoding git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@41 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../stal/service/impl/STALRequestBrokerImpl.java | 9 + .../gv/egiz/stal/service/impl/STALServiceImpl.java | 370 ++++++++++----------- BKUOnline/src/main/webapp/WEB-INF/wsdl/stal.xsd | 3 +- 3 files changed, 192 insertions(+), 190 deletions(-) (limited to 'BKUOnline/src/main') 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 ef0bcdd6..727e8cf4 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 @@ -53,6 +53,7 @@ public class STALRequestBrokerImpl implements STALRequestBroker { protected List currentHashDataInput; private boolean isHandlingRequest = false; private boolean expectingResponse = false; + private boolean interrupted = false; // private Object handleRequestCondition = new Object(); // private Object gotResponsesCondition = new Object(); // public STALRequestBrokerImpl() { @@ -75,6 +76,9 @@ public class STALRequestBrokerImpl implements STALRequestBroker { */ @Override public synchronized List handleRequest(List requests) { + if (interrupted) { + return null; + } try { long beforeWait = System.currentTimeMillis(); while (isHandlingRequest) { @@ -161,6 +165,7 @@ public class STALRequestBrokerImpl implements STALRequestBroker { return resps; } catch (InterruptedException ex) { log.warn("interrupt in handleRequest(): " + ex.getMessage()); + interrupted = true; return null; } } @@ -172,6 +177,9 @@ public class STALRequestBrokerImpl implements STALRequestBroker { */ @Override public synchronized List nextRequest(List responses) { + if (interrupted) { + return null; + } try { if (responses != null && responses.size() > 0) { if (!expectingResponse) { @@ -244,6 +252,7 @@ public class STALRequestBrokerImpl implements STALRequestBroker { return reqs; } catch (InterruptedException ex) { log.warn("interrupt in nextRequest(): " + ex.getMessage()); + interrupted = true; return null; } } 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 f4cdc7d2..385888e9 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 @@ -56,206 +56,198 @@ import org.apache.commons.logging.LogFactory; @WebService(endpointInterface = "at.gv.egiz.stal.service.STALPortType") public class STALServiceImpl implements STALPortType { - public static final String BINDING_PROCESSOR_MANAGER = "bindingProcessorManager"; - public static final String TEST_SESSION_ID = "TestSession"; - protected static final Log log = LogFactory.getLog(STALServiceImpl.class); - @Resource - WebServiceContext wsContext; - protected IdFactory idF = IdFactory.getInstance(); - - @Override - public GetNextRequestResponseType getNextRequest(GetNextRequestType request) { - - // HttpSession session = ((HttpServletRequest) - // mCtx.get(MessageContext.SERVLET_REQUEST)).getSession(); - String sessId = request.getSessionId(); - List responses = request.getResponse(); - if (log.isDebugEnabled()) { - log.debug("Received GetNextRequest for session " + sessId + " containing " + responses.size() + " responses"); - } - - GetNextRequestResponseType response = new GetNextRequestResponseType(); - response.setSessionId(sessId); + public static final String BINDING_PROCESSOR_MANAGER = "bindingProcessorManager"; + public static final Id TEST_SESSION_ID = IdFactory.getInstance().createId("TestSession"); + protected static final Log log = LogFactory.getLog(STALServiceImpl.class); + @Resource + WebServiceContext wsContext; + protected IdFactory idF = IdFactory.getInstance(); + + @Override + public GetNextRequestResponseType getNextRequest(GetNextRequestType request) { + + Id sessionId = idF.createId(request.getSessionId()); + + List responsesIn = request.getResponse(); + + GetNextRequestResponseType response = new GetNextRequestResponseType(); + response.setSessionId(sessionId.toString()); + + if (TEST_SESSION_ID.equals(sessionId)) { + if (responsesIn.size() > 0 && responsesIn.get(0) instanceof ErrorResponse) { + log.info("Received TestSession GetNextRequest(ErrorResponse), returning QuitRequest"); + response.getRequest().add(new QuitRequest()); + } else { + log.info("Received TestSession GetNextRequest, returning InfoboxReadRequest "); + SignRequest sig = new SignRequest(); + sig.setKeyIdentifier("SecureSignatureKeypair"); + sig.setSignedInfo(" id('signed-data-object-0-1214921968-27971781-13578')/node() H1IePEEfGQ2SG03H6LTzw1TpCuM=yV6Q+I60buqR4mMaxA7fi+CV35A=".getBytes()); + response.getRequest().add(sig); + InfoboxReadRequest req = new InfoboxReadRequest(); + req.setInfoboxIdentifier("IdentityLink"); + req.setDomainIdentifier("hansiwurzel"); + response.getRequest().add(req); + req = new InfoboxReadRequest(); + req.setInfoboxIdentifier("CertifiedKeypair"); + response.getRequest().add(req); + req = new InfoboxReadRequest(); + req.setInfoboxIdentifier("SecureSignatureKeypair"); + response.getRequest().add(req); + } + return response; + } - if (TEST_SESSION_ID.equals(sessId)) { - if (responses.size() > 0 && responses.get(0) instanceof ErrorResponse) { - log.info("Received TestSession GetNextRequest(ErrorResponse), returning QuitRequest"); - response.getRequest().add(new QuitRequest()); - } else { - log.info("Received TestSession GetNextRequest, returning InfoboxReadRequest "); - SignRequest sig = new SignRequest(); - sig.setKeyIdentifier("SecureSignatureKeypair"); - sig.setSignedInfo(" id('signed-data-object-0-1214921968-27971781-13578')/node() H1IePEEfGQ2SG03H6LTzw1TpCuM=yV6Q+I60buqR4mMaxA7fi+CV35A=".getBytes()); - response.getRequest().add(sig); - InfoboxReadRequest req = new InfoboxReadRequest(); - req.setInfoboxIdentifier("IdentityLink"); - req.setDomainIdentifier("hansiwurzel"); - response.getRequest().add(req); - req = new InfoboxReadRequest(); - req.setInfoboxIdentifier("CertifiedKeypair"); - response.getRequest().add(req); - req = new InfoboxReadRequest(); - req.setInfoboxIdentifier("SecureSignatureKeypair"); - response.getRequest().add(req); - } - return response; + STALRequestBroker stal = getStal(sessionId); + + if (stal != null) { + if (log.isDebugEnabled()) { + StringBuilder sb = new StringBuilder("Received GetNextRequest ["); + sb.append(sessionId.toString()); + sb.append("] containing "); + sb.append(responsesIn.size()); + sb.append(" responses: "); + for (STALResponse respIn : responsesIn) { + sb.append(respIn); + sb.append(' '); } - - // get Session Id - Id sessionId = idF.createId(sessId); - STALRequestBroker stal = getStal(sessionId); - - if (stal == null) { - log.error("Failed to get STAL for session " + sessId + ", returning QuitRequest"); - response.getRequest().add(new QuitRequest()); - } else { - List responsesIn = request.getResponse(); - for (STALResponse resp : responsesIn) { - log.debug(resp); - } - List requestsOut = ((STALRequestBroker) stal).nextRequest(responsesIn); - response.getRequest().addAll(requestsOut); - if (log.isDebugEnabled()) { - log.debug("Returning GetNextRequestResponse for session " + sessId + " containing " + requestsOut.size() + " requests"); - } + } + + List requestsOut = ((STALRequestBroker) stal).nextRequest(responsesIn); + response.getRequest().addAll(requestsOut); + + if (log.isDebugEnabled()) { + StringBuilder sb = new StringBuilder("Returning GetNextRequestResponse ["); + sb.append(sessionId.toString()); + sb.append("] containing "); + sb.append(requestsOut.size()); + sb.append(" requests: "); + for (STALRequest reqOut : requestsOut) { + sb.append(reqOut); + sb.append(' '); } - return response; + } + } else { + log.error("Failed to get STAL for session " + sessionId + ", returning QuitRequest"); + response.getRequest().add(new QuitRequest()); } + return response; + } - @Override - public GetHashDataInputResponseType getHashDataInput( - GetHashDataInputType request) throws GetHashDataInputFault { + @Override + public GetHashDataInputResponseType getHashDataInput(GetHashDataInputType request) throws GetHashDataInputFault { - String sessId = request.getSessionId(); - if (log.isDebugEnabled()) { - log.debug("Received GetHashDataInputRequest for session " + sessId + " containing " + request.getReference().size() + " referencese"); - } - - // get Session Id - Id sessionId = idF.createId(sessId); - STALRequestBroker stal = getStal(sessionId); - - if (stal == null) { - String msg = "Failed to get STAL for session " + sessId; - log.error(msg); - GetHashDataInputFaultType faultInfo = new GetHashDataInputFaultType(); - faultInfo.setErrorCode(1); - faultInfo.setErrorMessage(msg); - throw new GetHashDataInputFault(msg, faultInfo); - } else { - - List hashDataInputs = stal.getHashDataInput(); - - if (TEST_SESSION_ID.equals(sessId)) { - log.debug("Received TestSession GetHashDataInput, setting dummy HashDataInputCallback"); - - HashDataInput testHdi = new HashDataInput() { + Id sessionId = idF.createId(request.getSessionId()); - @Override - public String getReferenceId() { - return "hashDataInputId_" + TEST_SESSION_ID; - } + if (log.isDebugEnabled()) { + log.debug("Received GetHashDataInputRequest for session " + sessionId + " containing " + request.getReference().size() + " reference(s)"); + } - @Override - public String getMimeType() { - return "text/plain"; - } + GetHashDataInputResponseType response = new GetHashDataInputResponseType(); + response.setSessionId(sessionId.toString()); + + if (TEST_SESSION_ID.equals(sessionId)) { + log.debug("Received GetHashDataInput for session " + TEST_SESSION_ID + ", return DummyHashDataInput"); + GetHashDataInputResponseType.Reference ref = new GetHashDataInputResponseType.Reference(); + ref.setID("Reference-" + TEST_SESSION_ID + "-001"); + ref.setMimeType("text/plain"); + ref.setEncoding("UTF-8"); + ref.setValue("hashdatainput-öäüß@€-00000000001".getBytes()); + response.getReference().add(ref); + return response; + } else { + STALRequestBroker stal = getStal(sessionId); + + if (stal != null) { + List hashDataInputs = stal.getHashDataInput(); + + if (hashDataInputs != null) { + + Map hashDataIdMap = new HashMap(); + for (HashDataInput hdi : hashDataInputs) { + if (log.isTraceEnabled()) { + log.trace("Provided HashDataInput for reference " + hdi.getReferenceId()); + } + hashDataIdMap.put(hdi.getReferenceId(), hdi); + } + + List reqRefs = request.getReference(); + for (GetHashDataInputType.Reference reqRef : reqRefs) { + String reqRefId = reqRef.getID(); + HashDataInput reqHdi = hashDataIdMap.get(reqRefId); + if (reqHdi == null) { + String msg = "Failed to resolve HashDataInput for reference " + reqRefId; + log.error(msg); + GetHashDataInputFaultType faultInfo = new GetHashDataInputFaultType(); + faultInfo.setErrorCode(1); + faultInfo.setErrorMessage(msg); + throw new GetHashDataInputFault(msg, faultInfo); + } - @Override - public InputStream getHashDataInput() { - byte[] hd = ("hashDataInput_" + TEST_SESSION_ID).getBytes(); - return new ByteArrayInputStream(hd); - } - }; - hashDataInputs = Collections.singletonList(testHdi); + InputStream hashDataIS = reqHdi.getHashDataInput(); + if (hashDataIS == null) { + //HashDataInput not cached? + String msg = "Failed to obtain HashDataInput for reference " + reqRefId + ", reference not cached"; + log.error(msg); + GetHashDataInputFaultType faultInfo = new GetHashDataInputFaultType(); + faultInfo.setErrorCode(1); + faultInfo.setErrorMessage(msg); + throw new GetHashDataInputFault(msg, faultInfo); } - - - if (hashDataInputs != null) { - - Map hashDataIdMap = new HashMap(); - for (HashDataInput hdi : hashDataInputs) { - if (log.isTraceEnabled()) { - log.trace("Provided HashDataInput for reference " + hdi.getReferenceId()); - } - hashDataIdMap.put(hdi.getReferenceId(), hdi); - } - - GetHashDataInputResponseType response = new GetHashDataInputResponseType(); - response.setSessionId(sessId); - - List reqRefs = request.getReference(); - for (GetHashDataInputType.Reference reqRef : reqRefs) { - String reqRefId = reqRef.getID(); - HashDataInput reqHdi = hashDataIdMap.get(reqRefId); - if (reqHdi == null) { - String msg = "Failed to resolve HashDataInput for reference " + reqRefId; - log.error(msg); - GetHashDataInputFaultType faultInfo = new GetHashDataInputFaultType(); - faultInfo.setErrorCode(1); - faultInfo.setErrorMessage(msg); - throw new GetHashDataInputFault(msg, faultInfo); - } - - InputStream hashDataIS = reqHdi.getHashDataInput(); - if (hashDataIS == null) { - //HashDataInput not cached? - String msg = "Failed to obtain HashDataInput for reference " + reqRefId + ", reference not cached"; - log.error(msg); - GetHashDataInputFaultType faultInfo = new GetHashDataInputFaultType(); - faultInfo.setErrorCode(1); - faultInfo.setErrorMessage(msg); - throw new GetHashDataInputFault(msg, faultInfo); - } - ByteArrayOutputStream baos = null; - try { - if(log.isDebugEnabled()) { - log.debug("Resolved HashDataInput " + reqRefId + " (" + reqHdi.getMimeType() + ")"); - } - baos = new ByteArrayOutputStream(hashDataIS.available()); - int c; - while ((c = hashDataIS.read()) != -1) { - baos.write(c); - } - GetHashDataInputResponseType.Reference ref = new GetHashDataInputResponseType.Reference(); - ref.setID(reqRefId); - ref.setMimeType(reqHdi.getMimeType()); - ref.setValue(baos.toByteArray()); - response.getReference().add(ref); - } catch (IOException ex) { - String msg = "Failed to get HashDataInput for reference " + reqRefId; - log.error(msg, ex); - GetHashDataInputFaultType faultInfo = new GetHashDataInputFaultType(); - faultInfo.setErrorCode(1); - faultInfo.setErrorMessage(msg); - throw new GetHashDataInputFault(msg, faultInfo, ex); - } finally { - try { - baos.close(); - } catch (IOException ex) { - } - } - } - return response; - } else { - String msg = "Failed to resolve any HashDataInputs for session " + sessId; - log.error(msg); - GetHashDataInputFaultType faultInfo = new GetHashDataInputFaultType(); - faultInfo.setErrorCode(1); - faultInfo.setErrorMessage(msg); - throw new GetHashDataInputFault(msg, faultInfo); + ByteArrayOutputStream baos = null; + try { + if (log.isDebugEnabled()) { + log.debug("Resolved HashDataInput " + reqRefId + " (" + reqHdi.getMimeType() + ";charset=" + reqHdi.getEncoding() + ")"); + } + baos = new ByteArrayOutputStream(hashDataIS.available()); + int c; + while ((c = hashDataIS.read()) != -1) { + baos.write(c); + } + GetHashDataInputResponseType.Reference ref = new GetHashDataInputResponseType.Reference(); + ref.setID(reqRefId); + ref.setMimeType(reqHdi.getMimeType()); + ref.setEncoding(reqHdi.getEncoding()); + ref.setValue(baos.toByteArray()); + response.getReference().add(ref); + } catch (IOException ex) { + String msg = "Failed to get HashDataInput for reference " + reqRefId; + log.error(msg, ex); + GetHashDataInputFaultType faultInfo = new GetHashDataInputFaultType(); + faultInfo.setErrorCode(1); + faultInfo.setErrorMessage(msg); + throw new GetHashDataInputFault(msg, faultInfo, ex); + } finally { + try { + baos.close(); + } catch (IOException ex) { + } } + } + return response; + } else { + String msg = "Failed to resolve any HashDataInputs for session " + sessionId; + log.error(msg); + GetHashDataInputFaultType faultInfo = new GetHashDataInputFaultType(); + faultInfo.setErrorCode(1); + faultInfo.setErrorMessage(msg); + throw new GetHashDataInputFault(msg, faultInfo); } + } else { + String msg = "Failed to get STAL for session " + sessionId; + log.error(msg); + GetHashDataInputFaultType faultInfo = new GetHashDataInputFaultType(); + faultInfo.setErrorCode(1); + faultInfo.setErrorMessage(msg); + throw new GetHashDataInputFault(msg, faultInfo); + } } - - private STALRequestBroker getStal(Id sessionId) { -// log.warn("RETURNING DUMMY STAL REQUEST BROKER"); -// return new STALRequestBrokerImpl(); - - MessageContext mCtx = wsContext.getMessageContext(); - ServletContext sCtx = (ServletContext) mCtx.get(MessageContext.SERVLET_CONTEXT); - BindingProcessorManager bpMgr = (BindingProcessorManager) sCtx.getAttribute(BINDING_PROCESSOR_MANAGER); - BindingProcessor bp = bpMgr.getBindingProcessor(sessionId); - return (bp == null) ? null : (STALRequestBroker) bp.getSTAL(); - } + } + + private STALRequestBroker getStal(Id sessionId) { + MessageContext mCtx = wsContext.getMessageContext(); + ServletContext sCtx = (ServletContext) mCtx.get(MessageContext.SERVLET_CONTEXT); + BindingProcessorManager bpMgr = (BindingProcessorManager) sCtx.getAttribute(BINDING_PROCESSOR_MANAGER); + BindingProcessor bp = bpMgr.getBindingProcessor(sessionId); + return (bp == null) ? null : (STALRequestBroker) bp.getSTAL(); + } } diff --git a/BKUOnline/src/main/webapp/WEB-INF/wsdl/stal.xsd b/BKUOnline/src/main/webapp/WEB-INF/wsdl/stal.xsd index c4e48e2c..b3c4841a 100644 --- a/BKUOnline/src/main/webapp/WEB-INF/wsdl/stal.xsd +++ b/BKUOnline/src/main/webapp/WEB-INF/wsdl/stal.xsd @@ -120,7 +120,8 @@ - + + -- cgit v1.2.3