Jump to content
scharles

Resolved: Createattachment Method policy limit exceeded

Recommended Posts

Hello,

I am trying to add an attachment to a change order. I can get the change order created but can't add the attchment:

FAIL: Error - could not perform the operation, policy limit exceeded

<div class='codetop'>CODE</div><div class='codemain' style='height:200px;white-space:pre;overflow:auto'> private static int createServiceDeskChangeOrder(String category, String orderDescription, String affectedUsers, String summaryDescription, int isrNumber)

throws Exception{

USD_WebServiceLocator client = new USD_WebServiceLocator();

//create a default service endpoint

USD_WebServiceSoap service = client.getUSD_WebServiceSoap();

String user = "xxxxxxx";

String pwd = "xxxxxxx";

String groupUUID = "cnt:xxxxxxxxxxxxxxxxxxxxxxxxx";

String creatorHandle = "";

int sid = 0;

try{

sid = loginServiceDesk(service, user, pwd);

// get user handle, needed to generate request

creatorHandle = service.getHandleForUserid(sid, user);

String userUUID = creatorHandle;

System.out.println("userUUID:" + userUUID);

// initialize the attrVal parameter for passing to createChangeOrder

String[] attrVals = new String[25];

attrVals[0] = "requestor";

attrVals[1] = userUUID;

//

attrVals[2] = "affected_contact";

attrVals[3] = userUUID;

//

attrVals[4] = "category";

attrVals[5] = category;

//

attrVals[6] = "status";

attrVals[7] = "chgstat:40020";//"Open"

//

attrVals[8] = "priority";

attrVals[9] = "pri:502";//500=1,501=2,502=3,503=4,504=5,505=none

//

attrVals[10] = "group";

attrVals[11] = groupUUID;

//

attrVals[12] = "description";

attrVals[13] = orderDescription;

//

attrVals[14] = "zcontact_list";

attrVals[15] = affectedUsers;

//

attrVals[16] = "log_agent";

attrVals[17] = userUUID;

//

attrVals[18] = "summary";

attrVals[19] = summaryDescription;

//

attrVals[20] = "zisr";

attrVals[21] = String.valueOf(isrNumber);

String[] propertyValues = new String[1];

propertyValues[0] = "";

String template = "";

String[] attributes = new String[1];

attributes[0] = "persistent_id";

StringHolder newChangeHandle = new StringHolder();

newChangeHandle.value = "";

StringHolder newChangeNumber = new StringHolder();

newChangeNumber.value = "";

//create new change order

System.out.println("Creating a Change Order...");

service.createChangeOrder(sid,

creatorHandle,

attrVals,

propertyValues,

template,

attributes,

newChangeHandle,

newChangeNumber);

System.out.println("New Change Order created:");

System.out.println("changeHandle = " + newChangeHandle.value);

System.out.println("changeNumber = " + newChangeNumber.value);

// add attachment to change order

service.createAttachment(sid, "attmnt", creatorHandle, "TEST Attachment", "C:\\Documents and Settings\\scharles\\Desktop\\changedToComplete.txt");

return Integer.parseInt(newChangeNumber.value);

} catch (Exception ex){

System.out.println("Exception: " + ex);

System.out.println();

return 0;

} finally {

if (sid > 0){

// logout of service desk

logoutServiceDesk(service, sid);

}

}

}

</div>

I saw someone else post the same error, but alas no answer.

Thanks!

-Shawn

Share this post


Link to post
Share on other sites

Hi Shawn

This is a issue with the way that SOAP handles attachments.

You 1st need to upload the attachment into the SOAP handler before you execute the attachdocument web service call.

CA has published the fix #QI89107 which details this.

in visual studio 2003 you can use the DIME methods to do this

VB.NET Code using DIME:

 Dim reqContext As SoapContext = objUSD_WS.RequestSoapContext  
Dim dimeAttach As New DimeAttachment("image/gif", TypeFormat.MediaType, "c:\test.txt")  

reqContext.Attachments.Add(dimeAttach)  

strResult = objUSD_WS.createAttachment(sid, "doc_rep:1002", "cr:400001", "my desc", "c:\test.txt")

I user viosual web developer 2008 to write my code and DIME has been replaced by MOTM after visual studio 2003.

im still trying to develope a way of doing this using the new methods with MOTM.

Hope this helps !!!

Cheers.

Da Nooblet

Share this post


Link to post
Share on other sites

Da Nooblet,

Thanks for the help:

Here is the java version of the fix:

	public static void createCOAttachment(USD_WebServiceSoap service, int sid, String objectHandle, int srNumber){
String repositoryHandle = "doc_rep:1002"; // persid of document repsoitory in SD
String fileName = "";

try {
//Get DAO Factory
SRDAOFactory daoFactory = SRDAOFactory.getDAOFactory(Constants.SRDAOFACTORY_TYPE);

FileDataSource fds = new FileDataSource(fileName);
DataHandler dhandler = new DataHandler(fds);
// Affix DIME type header to attachment before sending
((javax.xml.rpc.Stub)service)._setProperty(org.apache.axis.client.Call.ATTACHMEN
T_ENCAPSULATION_FORMAT, Call.ATTACHMENT_ENCAPSULATION_FORMAT_DIME);
((org.apache.axis.client.Stub)service).addAttachment(dhandler);
//Create attachment
service.createAttachment(sid, repositoryHandle, objectHandle, "", fileName);
System.out.println("Creating attachment...SUCCESS");
}
} catch (Exception ex){
System.out.println("Creating attachment...FAIL: " + ex);
}
}

-shawn

Share this post


Link to post
Share on other sites

Thanks Shawn

Im sure this well help alot of people !

Can we add this to the USD Webservices wiki ?

Share this post


Link to post
Share on other sites

In your code:

Dim reqContext As SoapContext = objUSD_WS.RequestSoapContext  
Dim dimeAttach As New DimeAttachment("image/gif", TypeFormat.MediaType, "c:\test.txt")  

reqContext.Attachments.Add(dimeAttach)  

strResult = objUSD_WS.createAttachment(sid, "doc_rep:1002", "cr:400001", "my desc", "c:\test.txt")

where is the call to DIME, that uploads the file to Unicenter? I don't understand => reqContext.Attachments.Add(dimeAttach)

Share this post


Link to post
Share on other sites

You need to import the older web service class from VB6.

Microsoft.WebServices2 is the name I believe.

the new system.web services wont work because it doens't support DIME. CA has a tech doc on this.

Share this post


Link to post
Share on other sites

public static void createCOAttachment(USD_WebServiceSoap usd, int sid) {

String repositoryHandle = "doc_rep:1001";

String fileName = "c:\\123.txt";

FileDataSource fds = new FileDataSource(fileName);

DataHandler dhandler = new DataHandler(fds);

((javax.xml.rpc.Stub)usd)._setProperty(org.apache.axis.client.Call.ATTACHMENT_EN

CAPSULATION_FORMAT, org.apache.axis.client.Call.ATTACHMENT_ENCAPSULATION_FORMAT_DIME);

((org.apache.axis.client.Stub)usd).addAttachment(dhandler);

usd.createAttachment(sid, repositoryHandle, "400018", "Test", fileName);

}

Error:

java.lang.RuntimeException: No support for attachments

AxisFault

faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException

error in red line....

Any ideas????

Share this post


Link to post
Share on other sites

I think the error is quite obvious: your Java runtime environment (or more precisely Axis) does not support attachments (i.e. ATTACHMENT_ENCAPSULATION_FORMAT_DIME). It's a semi-known Axis 'error', see this link for details. Basically, you need 'activation.jar' and 'mail.jar' from a J2EE installation (I think they can also be downloaded separately) to be added to your java program's classpath at runtime.

Share this post


Link to post
Share on other sites

I have add the reference to Microsoft.Web.Services2 to my project in ASP.NET. I can see the all the available class's like SoapContext and RequestSoapContext etc...

I am running into a problem with the following statement in my code from the example above.

Dim reqContext As SoapContext = webSrvObj.RequestSoapContext

It says that RequestSoapContext is not part of this reference for webSrvObj.

webSrvObj is defined above in the code to the added Web Reference to the WSDL for USD.

webref_uatapp is the name of the webreference to the USD wsdl.

Dim proxy As New webref_uatapp.USD_WebService()

sid = proxy.login(username, password)

webSrvObj = proxy

Any help is greatly appreciated.

Bill

Share this post


Link to post
Share on other sites

I do have similar problem.

am using .NET framework 3.5 . I used WSE 1,2 & 3 no luck...

for me RequestSoapContext is not working also

You got any solution to this issue

Nivas

Edited by nivas pm

Share this post


Link to post
Share on other sites

I know it's old topic but here is my solution for .NET

1. Add 'Microsoft.Web.Services2' from NuGet Package;

2. Add Web Reference;

3. Change USD_WebService implementation from System.Web.Services.Protocols.SoapHttpClientProtocol to Microsoft.Web.Services2.WebServicesClientProtocol at Reference.cs;

4. Add code:

try
{
string filePath = @"D:\protocol.pdf";
CA.USD_WebService usd = new CA.USD_WebService();

if (File.Exists(filePath))
{
using (MemoryStream memoryStream = new MemoryStream())
{
using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
{
byte[] bytes = new byte[fileStream.Length];
fileStream.Read(bytes, 0, (int)fileStream.Length);
memoryStream.Write(bytes, 0, (int)fileStream.Length);

var dimeAttach = new DimeAttachment("image/gif", TypeFormat.MediaType, memoryStream);

int SID = usd.login(@"login", "password");

usd.RequestSoapContext.Attachments.Add(dimeAttach);
string strResult = usd.createAttachment(SID, "doc_rep:1002", "cr:1170671", "WebService Protocol", filePath);
Console.WriteLine(strResult);
}
}
}
else
{
Console.WriteLine("No file");
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
}

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×