From bba1cfcc4672a22cb0d0d579d4a51e7ae984f715 Mon Sep 17 00:00:00 2001 From: "peter.danner" Date: Fri, 27 Jul 2007 13:46:51 +0000 Subject: Changed Apache Axis to version 1.4 git-svn-id: https://joinup.ec.europa.eu/svn/moa-idspss/trunk@855 d688527b-c9ab-4aba-bd8d-4036d912da1d --- .../moa/spss/server/service/AxisHandler.java | 135 +++++++++++++++++++-- .../server/service/SignatureCreationService.java | 9 +- .../service/SignatureVerificationService.java | 19 ++- 3 files changed, 147 insertions(+), 16 deletions(-) (limited to 'spss.server/src/at/gv/egovernment/moa/spss/server/service') diff --git a/spss.server/src/at/gv/egovernment/moa/spss/server/service/AxisHandler.java b/spss.server/src/at/gv/egovernment/moa/spss/server/service/AxisHandler.java index 64bbb8dbe..985012da2 100644 --- a/spss.server/src/at/gv/egovernment/moa/spss/server/service/AxisHandler.java +++ b/spss.server/src/at/gv/egovernment/moa/spss/server/service/AxisHandler.java @@ -1,34 +1,39 @@ package at.gv.egovernment.moa.spss.server.service; +import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.security.cert.X509Certificate; +import java.util.Iterator; import javax.servlet.http.HttpServletRequest; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - import org.apache.axis.AxisFault; +import org.apache.axis.Message; import org.apache.axis.MessageContext; +import org.apache.axis.attachments.AttachmentPart; import org.apache.axis.handlers.BasicHandler; import org.apache.axis.transport.http.HTTPConstants; import org.apache.axis.utils.Messages; import org.apache.axis.utils.XMLUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; import at.gv.egovernment.moa.logging.LogMsg; import at.gv.egovernment.moa.logging.Logger; import at.gv.egovernment.moa.logging.LoggingContext; import at.gv.egovernment.moa.logging.LoggingContextManager; - import at.gv.egovernment.moa.spss.MOASystemException; import at.gv.egovernment.moa.spss.server.config.ConfigurationProvider; import at.gv.egovernment.moa.spss.server.transaction.TransactionContext; import at.gv.egovernment.moa.spss.server.transaction.TransactionContextManager; import at.gv.egovernment.moa.spss.server.transaction.TransactionIDGenerator; import at.gv.egovernment.moa.spss.util.MessageProvider; +import at.gv.egovernment.moa.util.DOMUtils; /** * An handler that is invoked on each web service request and performs some @@ -44,7 +49,7 @@ import at.gv.egovernment.moa.spss.util.MessageProvider; public class AxisHandler extends BasicHandler { /** The resource names of the messages to load. */ - private static final String MOA_SPSS_WSDL_RESOURCE_ = "/resources/wsdl/MOA-SPSS-1.2.wsdl"; + private static final String MOA_SPSS_WSDL_RESOURCE_ = "/resources/wsdl/MOA-SPSS-1.3.wsdl"; /** The property name for accessing the HTTP request. */ private static final String REQUEST_PROPERTY = HTTPConstants.MC_HTTP_SERVLETREQUEST; @@ -55,6 +60,18 @@ public class AxisHandler extends BasicHandler { /** The property name for accessing the SOAP action header. */ private static final String SOAP_ACTION_HEADER = "soapaction"; + /** URI of the SOAP XML namespace. */ + public static final String SOAP_NS_URI = "http://schemas.xmlsoap.org/soap/envelope/"; + + /** Prefix used for the SOAP XML namespace */ + public static final String SOAP_PREFIX = "soapenv"; + + /** Simple string contains the front part of the enveloping SOAP wrapping */ + private static final String SOAP_PART_PRE = ""; + + /** Simple string contains the post part of the enveloping SOAP wrapping */ + private static final String SOAP_PART_POST = ""; + /** * Handle an invocation of this handler. * @@ -86,16 +103,68 @@ public class AxisHandler extends BasicHandler { X509Certificate[] clientCert = (X509Certificate[]) request.getAttribute(X509_CERTIFICATE_PROPERTY); + //Configure Axis + //msgContext.setProperty(org.apache.axis.SOAPPart.ALLOW_FORM_OPTIMIZATION, Boolean.FALSE); + + Message soapMessage = msgContext.getCurrentMessage(); + ConfigurationProvider configuration = ConfigurationProvider.getInstance(); + Element xmlRequest = null; + Element soapPart = DOMUtils.parseDocument(new ByteArrayInputStream(soapMessage.getSOAPPartAsBytes()), false, null, null).getDocumentElement(); + if (soapPart!=null) { + NodeList soapBodies = soapPart.getElementsByTagNameNS(SOAP_NS_URI, "Body"); + if (soapBodies!=null && soapBodies.getLength()>0) { + xmlRequest = (Element) soapBodies.item(0).getFirstChild(); + } + //oder TODO: Evaluierung ob XPATH schneller + /* + HashMap nSMap = new HashMap(); + nSMap.put((String)SOAP_PREFIX, SOAP_NS_URI); + Element soapBody = (Element) XPathUtils.selectSingleNode(soapPart, nSMap, "/"+SOAP_PREFIX+":Envelope/"+SOAP_PREFIX+":Body"); + if (soapBody!=null) { + xmlRequest= (Element) soapBody.getFirstChild(); + } + */ + } + TransactionContext context = new TransactionContext( TransactionIDGenerator.nextID(), clientCert, - configuration); + configuration, + xmlRequest, + null); + + String soapAction = (String) request.getHeader(SOAP_ACTION_HEADER); + if ("\"\"".equals(soapAction)) { + // if http soap action header is empty + soapAction = msgContext.getTargetService(); + } + context.setRequestName(soapAction); - context.setRequestName((String) request.getHeader(SOAP_ACTION_HEADER)); + int attachmentCount = soapMessage.getAttachmentsImpl().getAttachmentCount(); + if (attachmentCount>0) { + + // add SOAP attachments to transaction context + Iterator iterator = soapMessage.getAttachments(); + while (iterator.hasNext()) { + AttachmentPart attachment = (AttachmentPart)iterator.next(); + String id = attachment.getContentId(); + String type = attachment.getContentType(); + + //Now get the InputStream (note: we could also get the content with Object content = attachment.getContent();) + InputStream is = null; + javax.activation.DataHandler datahandler = attachment.getDataHandler(); + org.apache.axis.attachments.ManagedMemoryDataSource mmds = (org.apache.axis.attachments.ManagedMemoryDataSource)datahandler.getDataSource(); + if (mmds!=null){ + is = mmds.getInputStream(); + } + debug("handler.06", new Object[] {id, type}); + context.addAttachment(id, type, mmds); + } + } setUpContexts(context); @@ -118,7 +187,7 @@ public class AxisHandler extends BasicHandler { info("handler.03", null); } if (Logger.isDebugEnabled()) { - String msg = msgContext.getCurrentMessage().getSOAPPartAsString(); + String msg = soapMessage.getSOAPPartAsString(); Logger.debug(new LogMsg(msg)); } } catch (MOASystemException e) { @@ -127,6 +196,8 @@ public class AxisHandler extends BasicHandler { fault.setFaultDetail(new Element[] { se.toErrorResponse()}); throw fault; } catch (Throwable t) { + t.printStackTrace(); + Logger.info(new LogMsg(t.getStackTrace())); MOASystemException e = new MOASystemException("2900", null, t); AxisFault fault = AxisFault.makeFault(e); fault.setFaultDetail(new Element[] { e.toErrorResponse()}); @@ -142,10 +213,35 @@ public class AxisHandler extends BasicHandler { * @throws AxisFault An error occurred during processing of the response. */ private void handleResponse(MessageContext msgContext) throws AxisFault { + String xmlResponseString = null; + String soapResponseString = null; + + TransactionContext context = TransactionContextManager.getInstance().getTransactionContext(); + Element xmlResponse = context.getResponse(); + + if (xmlResponse!=null) { + try { + xmlResponseString = DOMUtils.serializeNode(xmlResponse, true); + soapResponseString = SOAP_PART_PRE + xmlResponseString + SOAP_PART_POST; + //override axis response-message + msgContext.setResponseMessage(new Message(soapResponseString)); + } catch (Throwable t) { + t.printStackTrace(); + Logger.info(new LogMsg(t.getStackTrace())); + MOASystemException e = new MOASystemException("2900", null, t); + AxisFault fault = AxisFault.makeFault(e); + fault.setFaultDetail(new Element[] { e.toErrorResponse()}); + throw fault; + } + + } else { + //Fallback: if functions do not set the resulting response in the transaction, the original one from axis will be used + xmlResponseString = msgContext.getCurrentMessage().getSOAPPartAsString(); + } + info("handler.04", null); if (Logger.isDebugEnabled()) { - String msg = msgContext.getCurrentMessage().getSOAPPartAsString(); - Logger.debug(new LogMsg(msg)); + Logger.debug(new LogMsg(xmlResponseString)); } tearDownContexts(); } @@ -183,8 +279,13 @@ public class AxisHandler extends BasicHandler { * Tear down the thread-local contexts. */ private void tearDownContexts() { - // unset the transaction context TransactionContextManager tcm = TransactionContextManager.getInstance(); + + //delete temporary files + TransactionContext context = tcm.getTransactionContext(); + context.cleanAttachmentCache(); + + // unset the transaction context tcm.setTransactionContext(null); // unset the logging context @@ -250,4 +351,16 @@ public class AxisHandler extends BasicHandler { Logger.info(new LogMsg(msg.getMessage(messageId, parameters))); } + /** + * Utility function to issue an debug message to the log. + * + * @param messageId The ID of the message to log. + * @param parameters Additional message parameters. + */ + private static void debug(String messageId, Object[] parameters) { + MessageProvider msg = MessageProvider.getInstance(); + + Logger.debug(new LogMsg(msg.getMessage(messageId, parameters))); + } + } diff --git a/spss.server/src/at/gv/egovernment/moa/spss/server/service/SignatureCreationService.java b/spss.server/src/at/gv/egovernment/moa/spss/server/service/SignatureCreationService.java index 70dd3129c..2d548ea3a 100644 --- a/spss.server/src/at/gv/egovernment/moa/spss/server/service/SignatureCreationService.java +++ b/spss.server/src/at/gv/egovernment/moa/spss/server/service/SignatureCreationService.java @@ -16,6 +16,8 @@ import at.gv.egovernment.moa.spss.api.xmlbind.CreateXMLSignatureResponseBuilder; import at.gv.egovernment.moa.spss.api.xmlsign.CreateXMLSignatureRequest; import at.gv.egovernment.moa.spss.api.xmlsign.CreateXMLSignatureResponse; import at.gv.egovernment.moa.spss.server.invoke.XMLSignatureCreationInvoker; +import at.gv.egovernment.moa.spss.server.transaction.TransactionContext; +import at.gv.egovernment.moa.spss.server.transaction.TransactionContextManager; import at.gv.egovernment.moa.util.Constants; import at.gv.egovernment.moa.util.StreamUtils; @@ -64,8 +66,10 @@ public class SignatureCreationService { CreateXMLSignatureRequest requestObj; CreateXMLSignatureResponse responseObj; + //since Axis (1.1 ff) has problem with namespaces we take the raw request stored by the Axishandler. + TransactionContext context = TransactionContextManager.getInstance().getTransactionContext(); // validate the request - reparsedReq = ServiceUtils.reparseRequest(request[0]); + reparsedReq = ServiceUtils.reparseRequest(context.getRequest()); // convert to API objects requestObj = requestParser.parse(reparsedReq); @@ -76,6 +80,9 @@ public class SignatureCreationService { // map back to XML response[0] = responseBuilder.build(responseObj).getDocumentElement(); + + // save response in transaction + context.setResponse(response[0]); } catch (MOAException e) { AxisFault fault = AxisFault.makeFault(e); diff --git a/spss.server/src/at/gv/egovernment/moa/spss/server/service/SignatureVerificationService.java b/spss.server/src/at/gv/egovernment/moa/spss/server/service/SignatureVerificationService.java index 1b15a197f..b335a6e23 100644 --- a/spss.server/src/at/gv/egovernment/moa/spss/server/service/SignatureVerificationService.java +++ b/spss.server/src/at/gv/egovernment/moa/spss/server/service/SignatureVerificationService.java @@ -1,8 +1,7 @@ package at.gv.egovernment.moa.spss.server.service; -import org.w3c.dom.Element; - import org.apache.axis.AxisFault; +import org.w3c.dom.Element; import at.gv.egovernment.moa.logging.Logger; import at.gv.egovernment.moa.spss.MOAException; @@ -17,6 +16,8 @@ import at.gv.egovernment.moa.spss.api.xmlverify.VerifyXMLSignatureRequest; import at.gv.egovernment.moa.spss.api.xmlverify.VerifyXMLSignatureResponse; import at.gv.egovernment.moa.spss.server.invoke.CMSSignatureVerificationInvoker; import at.gv.egovernment.moa.spss.server.invoke.XMLSignatureVerificationInvoker; +import at.gv.egovernment.moa.spss.server.transaction.TransactionContext; +import at.gv.egovernment.moa.spss.server.transaction.TransactionContextManager; import at.gv.egovernment.moa.util.StreamUtils; /** @@ -52,8 +53,10 @@ public class SignatureVerificationService { VerifyCMSSignatureRequest requestObj; VerifyCMSSignatureResponse responseObj; + //since Axis (1.1 ff) has problem with namespaces we take the raw request stored by the Axishandler. + TransactionContext context = TransactionContextManager.getInstance().getTransactionContext(); // validate the request - reparsedReq = ServiceUtils.reparseRequest(request[0]); + reparsedReq = ServiceUtils.reparseRequest(context.getRequest()); // convert to API objects requestObj = requestParser.parse(reparsedReq); @@ -64,6 +67,9 @@ public class SignatureVerificationService { // map back to XML response[0] = responseBuilder.build(responseObj).getDocumentElement(); + // save response in transaction + context.setResponse(response[0]); + } catch (MOAException e) { AxisFault fault = AxisFault.makeFault(e); fault.setFaultDetail(new Element[] { e.toErrorResponse()}); @@ -107,8 +113,10 @@ public class SignatureVerificationService { VerifyXMLSignatureRequest requestObj; VerifyXMLSignatureResponse responseObj; + //since Axis (1.1 ff) has problem with namespaces we take the raw request stored by the Axishandler. + TransactionContext context = TransactionContextManager.getInstance().getTransactionContext(); // validate the request - reparsedReq = ServiceUtils.reparseRequest(request[0]); + reparsedReq = ServiceUtils.reparseRequest(context.getRequest()); // convert to API objects requestObj = requestParser.parse(reparsedReq); @@ -118,6 +126,9 @@ public class SignatureVerificationService { // map back to XML response[0] = responseBuilder.build(responseObj).getDocumentElement(); + + // save response in transaction + context.setResponse(response[0]); } catch (MOAException e) { AxisFault fault = AxisFault.makeFault(e); -- cgit v1.2.3