Atttachment tutorial - issues


(Sweta Kedia) #1

Hi,

I am referring https://docs.corda.net/tutorial-attachments.html to modify corapp to include attachment along with PO creation.

In runSender method - following API is used to send the transaction to other recipient

serviceHub.startFlow(LOG_SENDER, FinalityFlow(tx, emptySet(), setOf(otherSide))).success {
        thread {
            Thread.sleep(1000L) // Give the other side time to request the attachment
            node.stop()
        }
    }.failure {
        println("Failed to relay message ")
    }

However I could not find any startFlow function for a ServiceHub object - https://docs.corda.net/api/net.corda.core.node/-service-hub/index.html


(Roger Willis) #2

The documentation is out of sync with the code base - apologies for this. Things are moving pretty quick and it’s difficult to keep up with the changes!

Have a look at the trader-demo code. Specifically:

  • TraderDemoApi.kt
  • BuyerFlow.kt and SellerFlow.kt

Api implementations no longer take a ServiceHub object, instead they require a CordaRPCOps object. This is because API server was changed to depend on the RPC framework, instead of accessing the node’s persistence layer directly.

Looking at the trader-demo code should give you a good idea on how to integrate attachments into your code. Let us know if you need any further assistance.


(Sweta Kedia) #3

Hi Roger,

I am using the milestone release 0.6 in which I am unable to import the net.corda.core.messaging.CordaRPCOps package.

Is it like, this I can implement in Snapshot release?


(Roger Willis) #4

That’s right, it’s a change for M7. So you’ll need to work on master until we release M7.


(Mike Hearn) #5

Sorry about that - I’m rewriting the attachment tutorial for M7. It should be out in the next day or two!


(Srinidhi) #6

Hi @mike @roger Does it support only “jar” or can we directly use the files(like PDF) ?

Regards,
Srinidhi N


(Mike Hearn) #7

You can only attach zips. You can just put your PDF inside a zip, but be aware that filenames may not overlap between attachments, so make sure to give your PDF a unique name, or put it inside a directory with a unique name.


(Srinidhi) #8

@mike Thanks. Does corda support reading PDFs just to verify the contents against the contract ?


(Mike Hearn) #9

Yes, absolutely. The APIs for that will change soon though. At the moment you get access to the attachments in the verify call via the TransactionForContract class. In future they will be converted into a classpath so you can access files using the standard java getResource() API.

Now, wanting a PDF in an attachment to be tightly bound to a contract or state is such a common task, we plan to make that a lot more straightforward. Right now the way contracts are bound to attachments is all temporary scaffolding: it won’t stay that way. If your PDF describes a legal contract that is meant to be implemented also in code, you can simply put your PDF in the same (java) package as your class. That way when the state refers to the attachment containing the code by hash, it will implicitly also refer to the PDF: they’re tightly bound by virtue of being in the same ZIP.

Once this part of the platform is more fleshed out, we will produce samples and documentation showing how to bind documents to transactions. We don’t have such samples yet because this part of the platform is still under construction.


(Srinidhi) #11

Hi @sweta88 @mike,

Configured “org.glassfish.jersey.media:jersey-media-multipart:2.25” in build.gradle.

Tried below code in Rest API to upload files.

@POST
@Path("/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadZippedFile(
        @FormDataParam("uploadFile") InputStream fileInputStream,
        @FormDataParam("uploadFile") FormDataContentDisposition fileFormDataContentDisposition) {
    
    String fileName = null;
    String uploadFilePath = null;

    try {
        fileName = fileFormDataContentDisposition.getFileName();
        uploadFilePath = writeToFileServer(fileInputStream, fileName);
    }
    catch(IOException ioe){
        ioe.printStackTrace();
    }
    finally{
        
    }
    return Response.ok("File uploaded successfully at " + uploadFilePath).build();
}  

On server startup getting below error.

org.glassfish.jersey.server.model.ModelValidationException: Validation of the application resource model has failed during application initialization.**
**[[FATAL] No injection source found for a parameter of type public javax.ws.rs.core.Response

is there anything i have missed out ?

Regards,
Srinidhi N


(Joel Dudley) #12

Hi Srinidhi,

Could it be related to: http://stackoverflow.com/questions/14288856/jersey-2-injection-source-for-multipart-formdata?


(Srinidhi) #13

@joeldudley We dont have web descriptor in our corDapp to register for MultiPartFeature.


(Ajitha) #14

@srinidhi, @joeldudley,

Is this issue “No injection source found for a parameter of type public javax.ws.rs.core.Response” resolved? I am also facing the same.

Regards
Ajitha


(Ajitha) #15

I have solved the problem by using org.apache.commons.fileupload.servlet.ServletFileUpload.

Thanks
Ajitha


(Srinidhi) #16

That’s Cool !! What version of corda are you using ?


(Viswanathan S) #17

@roger where to start to add attachment with transaction?


(Roger Willis) #18

@Viswa have a look at corda.net/samples - specifically these ones:

Attachments

FTP – Use attachments to drag-and-drop files between Corda nodes
Blacklist – Use an attachment to blacklist specific nodes from signing agreements

Cheers


(Viswanathan S) #19

@roger I have seen three examples.
attachementdemo and blacklist are seems same
but traderdemo is different from above two.
please clarify and do needful.

Thanks


(Roger Willis) #20

Don’t use the trader demo - I’d focus on using the CorDapps on www.corda.net/samples - cheers!