AnsweredAssumed Answered

The message has expired (WSSecurityEngine: Invalid timestamp The security semantics of message have expired) while uploading large file using java webservice(SOAP))

Question asked by mrpathi on Oct 15, 2016
Latest reply on Oct 21, 2016 by openpj

Actually we are fully integrated alfresco community edition 4.0.d java web service. When i upload large files like 12 Mb and more than this failed because of the following exception

"org.apache.ws.security.WSSecurityException: The message has expired (WSSecurityEngine: Invalid timestamp The security semantics of message have expired)"

I am scratching my head for solving this problem.  I have pasted code for uploading file.

 

startAlfrescoSession();

String basefolderPath = TrackerConfiguration.getInstance().getDataDirLocation() + File.separator + documentName;

byte[] content = this.getFileContent(basefolderPath);

 

this.createDocumentInRepository();

private byte[] getFileContent(String filePath) {

        InputStream file;

        try {

            file = new FileInputStream(filePath);

            return IOUtils.toByteArray(file);

        } catch (FileNotFoundException f) {

            LOG.error("File not found " +

                    filePath + " because:" + f.getMessage());

            // Not necessary to throw the exception back for now.

        } catch (IOException e) {

            LOG.error("Exception while reading the document from filesystem from " +

                    filePath + " because:" + e.getMessage());

            LOG.error(LoggingUtils.getStackTraceAsString(e));

            // Not necessary to throw the exception back for now.

        }

        return new byte[0];

    }

 

private Reference createDocumentInRepository(

            String accountId,

            String projectId,

            String parentDirId,

            String contentType,

            DocumentType docType,

            byte[] content) throws ConnectorException {

        Reference createdReference = null;

        UpdateResult[] results = null;

        ParentReference parentRef =

                this.getParentReference(

                        accountId, projectId, parentDirId, docType.getName());

        if (parentRef != null) {

            // set directory properties

            NamedValue[] properties = this.getDocumentProperties(docType);

           

            // Create the space using CML (Content Manipulation Language)

            CMLCreate create =

                    new CMLCreate(

                            "1", parentRef, null, null, null, Constants.TYPE_CONTENT, properties);

            CML cml = new CML();

            cml.setCreate(new CMLCreate[]{create});

          

            try {

                RepositoryServiceSoapBindingStub service = this.getRepositoryService();

                results = service.update(cml);

            } catch (RepositoryFault e) {

                LOG.error("Cannot create the document "

                        + docType.getGuid() + " in account: " + accountId + " project: "+ projectId 

                        + " because : " + e.getMessage());

                LOG.error(LoggingUtils.getStackTraceAsString(e));

                throw new ConnectorException("Cannot create the document "

                        + docType.getGuid() + " in account: " + accountId +

                        " project: "+ projectId + " because: "+ e.getMessage(), e);

            } catch (RemoteException e) {

                LOG.error("Cannot create the document "

                        + docType.getGuid() + " in account: " + accountId + " project: "+ projectId 

                        + " because : " + e.getMessage());

                LOG.error(LoggingUtils.getStackTraceAsString(e));

                throw new ConnectorException("Cannot create the document "

                        + docType.getGuid() + " in account: " + accountId +

                        " project: "+ projectId + " because: "+ e.getMessage(), e);

            }

            if (results != null) {

                createdReference = results[0].getDestination();

            }

           

            // Set the Content format

            ContentFormat format = new ContentFormat();

            format.setEncoding("UTF-8");

            format.setMimetype(contentType);

                       

            try {

                this.getContentService().write(createdReference, Constants.PROP_CONTENT, content, format);

            } catch (ContentFault e) {

                LOG.error("Could not write the content of the newly created document "

                        + docType.getGuid() + " in account: " + accountId + " project: "+ projectId 

                        + " because : " + e.getMessage());

                LOG.error(LoggingUtils.getStackTraceAsString(e));

                throw new ConnectorException("Could not write the content of the newly created document "

                        + docType.getGuid() + " in account: " + accountId +

                        " project: "+ projectId + " because: "+ e.getLocalizedMessage(), e);

            } catch (RemoteException e) {

                LOG.error("Could not write the content of the newly created document "

                        + docType.getGuid() + " in account: " + accountId + " project: "+ projectId 

                        + " because : " + e.getMessage());

                LOG.error(LoggingUtils.getStackTraceAsString(e));

                throw new ConnectorException("Could not write the content of the newly created document "

                        + docType.getGuid() + " in account: " + accountId +

                        " project: "+ projectId + " because: "+ e.getLocalizedMessage(), e);

            }

        }

        // Add the versionable aspect to the newly created content. This

        // will allows the content to be versioned

        if (content.length != 0 && contentType != null) {

            this.makeVersionable(createdReference, docType);

        }

        return createdReference;

    }

 

Exception stack trace;

org.apache.ws.security.WSSecurityException: The message has expired (WSSecurityEngine: Invalid timestamp The security semantics of message have expired)

2016-10-15 17:36:28,795 ERROR AlfrescoDocumentConnectorImpl - AxisFault

faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.generalException

faultSubcode:

faultString: WSDoAllReceiver: security processing failed; nested exception is:

    org.apache.ws.security.WSSecurityException: The message has expired (WSSecurityEngine: Invalid timestamp The security semantics of message have expired)

faultActor:

faultNode:

faultDetail:

    {http://xml.apache.org/axis/}hostname:localhost

 

WSDoAllReceiver: security processing failed; nested exception is:

    org.apache.ws.security.WSSecurityException: The message has expired (WSSecurityEngine: Invalid timestamp The security semantics of message have expired)

    at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222)

    at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129)

    at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)

    at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)

    at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)

    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)

    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)

    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)

    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)

    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)

    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)

    at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)

    at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source)

    at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)

    at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)

    at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)

    at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)

    at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)

    at org.apache.axis.client.Call.invokeEngine(Call.java:2784)

    at org.apache.axis.client.Call.invoke(Call.java:2767)

    at org.apache.axis.client.Call.invoke(Call.java:2443)

    at org.apache.axis.client.Call.invoke(Call.java:2366)

    at org.apache.axis.client.Call.invoke(Call.java:1812)

    at org.alfresco.webservice.content.ContentServiceSoapBindingStub.write(ContentServiceSoapBindingStub.java:513)

    at com.nadhi.tracker.server.connector.impl.alfresco.AlfrescoDocumentConnectorImpl.createDocumentInRepository(AlfrescoDocumentConnectorImpl.java:3161)

    at com.nadhi.tracker.server.connector.impl.alfresco.AlfrescoDocumentConnectorImpl.addDocument(AlfrescoDocumentConnectorImpl.java:7853)

    at com.nadhi.tracker.AlfrescoMigrationHelper.uploadDocument(AlfrescoMigrationHelper.java:369)

    at com.nadhi.tracker.AlfrescoMigrationHelper.renderDocument(AlfrescoMigrationHelper.java:504)

    at com.nadhi.tracker.AlfrescoMigrationHelper.getAllChildren(AlfrescoMigrationHelper.java:266)

    at com.nadhi.tracker.AlfrescoMigrationHelper.renderDirectory(AlfrescoMigrationHelper.java:481)

    at com.nadhi.tracker.AlfrescoMigrationHelper.getAllChildren(AlfrescoMigrationHelper.java:263)

    at com.nadhi.tracker.AlfrescoMigrationHelper.renderDocuments(AlfrescoMigrationHelper.java:218)

    at com.nadhi.tracker.AlfrescoMigrationHelper.getDocuments(AlfrescoMigrationHelper.java:112)

    at com.nadhi.tracker.AlfrescoMigrationHelper.main(AlfrescoMigrationHelper.j

 

Can someone help me to fix this issue? Or Is there any work around to over come this issue.

Waiting for your suggestions?

Thanks in advance.

Outcomes