Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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!

0 votes



9 answers

Permanent link
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!

0 votes


Permanent link
InputStream is empty.
Yes, I can browse the artifact content successfully from web.

0 votes


Permanent link
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.

0 votes


Permanent link
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.

0 votes


Permanent link
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();
}

0 votes


Permanent link
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();
}

0 votes


Permanent link
I have just tried to reproduce on a 7.1.1.1 server and I am still not able to reproduce this issue.

0 votes


Permanent link
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.

0 votes


Permanent link
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.

0 votes

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details

Question asked: Dec 06 '10, 6:25 a.m.

Question was seen: 5,162 times

Last updated: Dec 06 '10, 6:25 a.m.

Confirmation Cancel Confirm