Download Artifact from an asset in Eclipse
Hi,
I am having an artifact XML attached to an asset. I need to retrieve its contents through eclipse client.I've used below RAM APIs, but could not get the artifact contents -
AssetIdentification assetIden = new AssetIdentification(guid, version);
RAMAsset asset = session.getAsset(assetIden);
FolderArtifact root = asset.getArtifactsRoot();
Artifact[] artifacts = root.getChildren();
RAMArtifact artifact = (RAMArtifact)artifacts;
InputStream is = artifact.downloadContents();
It is not returning me the xml contents, although it gives the correct XML name when I check - artifact.getName()
I was able to get xml contents through Web client but it does not work with Eclipse.
Kindly help.
Thanks!
I am having an artifact XML attached to an asset. I need to retrieve its contents through eclipse client.I've used below RAM APIs, but could not get the artifact contents -
AssetIdentification assetIden = new AssetIdentification(guid, version);
RAMAsset asset = session.getAsset(assetIden);
FolderArtifact root = asset.getArtifactsRoot();
Artifact[] artifacts = root.getChildren();
RAMArtifact artifact = (RAMArtifact)artifacts;
InputStream is = artifact.downloadContents();
It is not returning me the xml contents, although it gives the correct XML name when I check - artifact.getName()
I was able to get xml contents through Web client but it does not work with Eclipse.
Kindly help.
Thanks!
9 answers
What content is in the Input Stream? Is it just empty or is it returning invalid content? When you go to the web can you browse the artifact content successfully?
Hi,
I am having an artifact XML attached to an asset. I need to retrieve its contents through eclipse client.I've used below RAM APIs, but could not get the artifact contents -
AssetIdentification assetIden = new AssetIdentification(guid, version);
RAMAsset asset = session.getAsset(assetIden);
FolderArtifact root = asset.getArtifactsRoot();
Artifact[] artifacts = root.getChildren();
RAMArtifact artifact = (RAMArtifact)artifacts;
InputStream is = artifact.downloadContents();
It is not returning me the xml contents, although it gives the correct XML name when I check - artifact.getName()
I was able to get xml contents through Web client but it does not work with Eclipse.
Kindly help.
Thanks!
Thanks for the reply. I think xml name does not matter. For my testing I had given name "test.xml".
Steps to reproduce the problem are -
1) Click on any existing RAM asset->Click on "Modify Asset" icon.
2) Go to "Attach" tab.
3) Upload an XML file.
4) Click on "Confirm".So xml will be attached to the asset.
5) Try getting XML contents programmatically.
To get this, I used the code which I had pasted yesterday, but not able to fetch the xml contents.
Thanks!
Steps to reproduce the problem are -
1) Click on any existing RAM asset->Click on "Modify Asset" icon.
2) Go to "Attach" tab.
3) Upload an XML file.
4) Click on "Confirm".So xml will be attached to the asset.
5) Try getting XML contents programmatically.
To get this, I used the code which I had pasted yesterday, but not able to fetch the xml contents.
Thanks!
What is the name of your XML artifact I will try to reproduce.
InputStream is empty.
Yes, I can browse the artifact content successfully from web.
So a created an asset with one .xml artifact. I am running the RAM 7.5.0.1 client and server. What version of the client and server are you running? I had no problems running the following code (my xml content was printed as expected)...
RAMSession session = new RAMSession(URL, USERID, PASS);
try{
AssetIdentification assetIden = new AssetIdentification(GUID, VERSION);
RAMAsset asset = session.getAsset(assetIden);
FolderArtifact root = asset.getArtifactsRoot();
Artifact[] artifacts = root.getChildren();
RAMArtifact artifact = (RAMArtifact)artifacts[0];
InputStream is = artifact.downloadContents();
byte[] buffer = new byte[1024];
int read = -1;
while((read = is.read(buffer)) != -1){
String st = new String(buffer, 0, read);
System.out.print(st);
}
}catch (Exception e) {
e.printStackTrace();
}
finally{
if(session != null)session.release();
}
I am using IBM Rational Asset Manager Version 7.1.1.
I am not able to get XML contents.
I am not able to get XML contents.
So a created an asset with one .xml artifact. I am running the RAM 7.5.0.1 client and server. What version of the client and server are you running? I had no problems running the following code (my xml content was printed as expected)...
RAMSession session = new RAMSession(URL, USERID, PASS);
try{
AssetIdentification assetIden = new AssetIdentification(GUID, VERSION);
RAMAsset asset = session.getAsset(assetIden);
FolderArtifact root = asset.getArtifactsRoot();
Artifact[] artifacts = root.getChildren();
RAMArtifact artifact = (RAMArtifact)artifacts[0];
InputStream is = artifact.downloadContents();
byte[] buffer = new byte[1024];
int read = -1;
while((read = is.read(buffer)) != -1){
String st = new String(buffer, 0, read);
System.out.print(st);
}
}catch (Exception e) {
e.printStackTrace();
}
finally{
if(session != null)session.release();
}
It works now.
To read the artifact contents I was creating a byte array based on the InputStream size. Somehow size of InputStream comes as -1 always.So it was not getting written to the byte array.
After using your approach, it worked well.
Many Thanks for your valuable time.
To read the artifact contents I was creating a byte array based on the InputStream size. Somehow size of InputStream comes as -1 always.So it was not getting written to the byte array.
After using your approach, it worked well.
Many Thanks for your valuable time.
I have just tried to reproduce on a 7.1.1.1 server and I am still not able to reproduce this issue.
To support large artifacts (over 2 gig) we chunk the response which marks the response size as -1 (unknown).
It works now.
To read the artifact contents I was creating a byte array based on the InputStream size. Somehow size of InputStream comes as -1 always.So it was not getting written to the byte array.
After using your approach, it worked well.
Many Thanks for your valuable time.
I have just tried to reproduce on a 7.1.1.1 server and I am still not able to reproduce this issue.