phax / phase4

phase4 - AS4 client and server for integration into existing systems. Specific support for Peppol and CEF eDelivery built-in.
Apache License 2.0
154 stars 47 forks source link

Adding an Attachment throws an IllegalStateException #14

Closed AlexandruCiobanu closed 5 years ago

AlexandruCiobanu commented 5 years ago

PEPPOL Testbed complained that the payload was not sent as an attachment so I converted the setPayload call to an addAttachment one but i get the following error when sending: `java.lang.IllegalStateException: The input stream was already acquired 1 times! at com.helger.mail.datasource.InputStreamProviderDataSource.getInputStream(InputStreamProviderDataSource.java:71) ~[ph-mail-9.1.2.jar:9.1.2] at com.helger.mail.datasource.IEncodingAwareDataSource$1.getInputStream(IEncodingAwareDataSource.java:65) ~[ph-mail-9.1.2.jar:9.1.2] at javax.activation.DataHandler.writeTo(DataHandler.java:305) ~[?:1.8.0_161] at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1694) ~[javax.mail-1.6.2.jar:1.6.2] at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:996) ~[javax.mail-1.6.2.jar:1.6.2] at javax.mail.internet.MimeMultipart.writeTo(MimeMultipart.java:561) ~[javax.mail-1.6.2.jar:1.6.2] at com.sun.mail.handlers.multipart_mixed.writeTo(multipart_mixed.java:84) ~[javax.mail-1.6.2.jar:1.6.2] at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:889) ~[?:1.8.0_161] at javax.activation.DataHandler.writeTo(DataHandler.java:317) ~[?:1.8.0_161] at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1694) ~[javax.mail-1.6.2.jar:1.6.2] at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1913) ~[javax.mail-1.6.2.jar:1.6.2] at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1887) ~[javax.mail-1.6.2.jar:1.6.2] at com.helger.as4.http.HttpMimeMessageEntity.writeTo(HttpMimeMessageEntity.java:91) ~[classes/:?] at org.apache.http.impl.DefaultBHttpClientConnection.sendRequestEntity(DefaultBHttpClientConnection.java:156) ~[httpcore-4.4.11.jar:4.4.11] at org.apache.http.impl.conn.CPoolProxy.sendRequestEntity(CPoolProxy.java:152) ~[httpclient-4.5.8.jar:4.5.8] at org.apache.http.protocol.HttpRequestExecutor.doSendRequest(HttpRequestExecutor.java:238) ~[httpcore-4.4.11.jar:4.4.11] at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:123) ~[httpcore-4.4.11.jar:4.4.11] at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:272) ~[httpclient-4.5.8.jar:4.5.8] at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186) ~[httpclient-4.5.8.jar:4.5.8] at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89) ~[httpclient-4.5.8.jar:4.5.8] at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110) ~[httpclient-4.5.8.jar:4.5.8] at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) ~[httpclient-4.5.8.jar:4.5.8] at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72) ~[httpclient-4.5.8.jar:4.5.8] at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:221) ~[httpclient-4.5.8.jar:4.5.8] at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:165) ~[httpclient-4.5.8.jar:4.5.8] at com.helger.httpclient.HttpClientManager.execute(HttpClientManager.java:192) ~[ph-httpclient-9.1.2.jar:9.1.2] at com.helger.httpclient.HttpClientManager.execute(HttpClientManager.java:157) ~[ph-httpclient-9.1.2.jar:9.1.2] at com.helger.as4.client.BasicHttpPoster.sendGenericMessage(BasicHttpPoster.java:157) ~[classes/:?] at com.helger.as4.client.AbstractAS4Client.sendMessage(AbstractAS4Client.java:205) ~[classes/:?]

Any idea what might be wrong? BTW I was able to get past the previous encryption bug by creating a CertificateStore with the receivedCert :D.

phax commented 5 years ago

please ensure that As4HttpDebug is disabled. hth

AlexandruCiobanu commented 5 years ago

I disabled HTTPDebug and the error dissapears only if I also set a payload. Would I need to set the payload to something specific? Also when I send the message with attachment I get the following response from testbed: <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Body><soap:Fault><soap:Code><soap:Value>soap:Receiver</soap:Value></soap:Code><soap:Reason><soap:Text xml:lang="en">Fault occurred while processing.</soap:Text></soap:Reason></soap:Fault></soap:Body></soap:Envelope>

Maybe I am setting teh attachment wrong? Here is how I do it: aClient.addAttachment(WSS4JAttachment.createOutgoingFileAttachment(SBDHWriter.standardBusinessDocument().getAsBytes(aSBD), messageId, CMimeType.APPLICATION_XML, null, aClient.getResourceMgr()));

phax commented 5 years ago

No specific payload is needed. I am on vacation and dont have the code in front of me. pls be patient or try to figure it out yourself :)

phax commented 5 years ago

I improved the repetition handling of attachments in the 0.9.0 codebase and that should not happen again. Thanks for pointing that out.