It's all about the answers!

Ask a question

Download Artifact from an asset in Eclipse


Sapna Girdhani (2112) | asked Dec 06 '10, 6:25 a.m.
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!

9 answers



permanent link
Kevin Bauer (34621) | answered Dec 06 '10, 9:45 a.m.
JAZZ DEVELOPER
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!

permanent link
Sapna Girdhani (2112) | answered Dec 06 '10, 11:59 a.m.
InputStream is empty.
Yes, I can browse the artifact content successfully from web.

permanent link
Kevin Bauer (34621) | answered Dec 06 '10, 1:48 p.m.
JAZZ DEVELOPER
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.

permanent link
Sapna Girdhani (2112) | answered Dec 06 '10, 11:37 p.m.
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!

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.

permanent link
Kevin Bauer (34621) | answered Dec 07 '10, 11:32 a.m.
JAZZ DEVELOPER
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();
}

permanent link
Sapna Girdhani (2112) | answered Dec 07 '10, 1:10 p.m.
I am using IBM Rational Asset Manager Version 7.1.1.
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();
}

permanent link
Kevin Bauer (34621) | answered Dec 07 '10, 3:22 p.m.
JAZZ DEVELOPER
I have just tried to reproduce on a 7.1.1.1 server and I am still not able to reproduce this issue.

permanent link
Sapna Girdhani (2112) | answered Dec 08 '10, 5:54 a.m.
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.

permanent link
Kevin Bauer (34621) | answered Dec 08 '10, 10:39 a.m.
JAZZ DEVELOPER
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.

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.