Hello Brian,
Thanks for your prompt response, we had already validated that option and it worked, but the client does not want to publish port 8050, we must necessarily use tomcat on port 8080. I did tests with the new jars in the directory C:\Program Files (x86)\CA\Service Desk Manager\bopcfg\www\CATALINA_BASE\shared\lib
jakarta.activation-1.2.1.jar
jakarta.mail-1.6.3.jar
The code example is this:
FileDataSource fds = new FileDataSource(rutaArchivo);
DataHandler dhandler = new DataHandler(fds);
// Affix DIME type header to attachment before sending
((javax.xml.rpc.Stub) usd)._setProperty(
org.apache.axis.client.Call.ATTACHMENT_ENCAPSULATION_FORMAT,
org.apache.axis.client.Call.ATTACHMENT_ENCAPSULATION_FORMAT_DIME);
((org.apache.axis.client.Stub) usd).addAttachment(dhandler);
or
((org.apache.axis.client.Stub) usd)._setProperty(Call.ATTACHMENT_ENCAPSULATION_FORMAT,
Call.ATTACHMENT_ENCAPSULATION_FORMAT_DIME);
((org.apache.axis.client.Stub) usd).addAttachment(dhandler);
The attachment uploads with a limit of 1mb, if it is greater I receive the message from
<soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Fault>
<faultcode>soapenv:Server.generalException</faultcode>
<faultstring>Error - could not perform the operation, policy limit exceeded</faultstring>
<detail>
<ns1:hostname xmlns:ns1="http://xml.apache.org/axis/">WIN-VGUGCV3E7ES</ns1:hostname>
</detail>
</soapenv:Fault>
</soapenv:Body>
I am currently testing with SOAPMessage and I get the same message :(, the code I use is this:
SOAPConnection connection = SOAPConnectionFactory.newInstance().createConnection();
SOAPMessage message = MessageFactory.newInstance().createMessage();
SOAPPart part = message.getSOAPPart();
SOAPEnvelope envelope = part.getEnvelope();
SOAPBody body = envelope.getBody();
SOAPBodyElement operation = body.addBodyElement(
envelope.createName("createAttachment", "ser", "http://www.ca.com/UnicenterServicePlus/ServiceDesk"));
DataHandler dh = new DataHandler(new FileDataSource(file));
AttachmentPart attachment = message.createAttachmentPart(dh);
SOAPElement sidElement = operation.addChildElement("sid", "");
SOAPElement repositoryHandleElement = operation.addChildElement("repositoryHandle", "");
SOAPElement objectHandleElement = operation.addChildElement("objectHandle", "");
SOAPElement descriptionElement = operation.addChildElement("description", "");
SOAPElement fileNameElement = operation.addChildElement("fileName", "");
message.addAttachmentPart(attachment);
sidElement.addTextNode(String.valueOf(sid));
repositoryHandleElement.addTextNode(repository);
objectHandleElement.addTextNode(persid);
descriptionElement.addTextNode(attachmentDescription);
fileNameElement.addTextNode(filePath);
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
message.writeTo(out);
System.out.println(out.toByteArray());
} catch (IOException ex) {
Logger.getLogger(ServicioWebSD.class.getName()).log(Level.SEVERE, null, ex);
}
SOAPMessage result = connection.call(message, url);
part = result.getSOAPPart();
envelope = part.getEnvelope();
body = envelope.getBody();
if (!body.hasFault()) {
Iterator iterator = result.getAttachments();
if (iterator.hasNext()) {
dh = ((AttachmentPart) iterator.next()).getDataHandler();
String fname = dh.getName();
}
But with Soapui works!!!
Original Message:
Sent: 07-21-2021 08:28 AM
From: Brian Mathato
Subject: createAttachment webservice ca servicedesk
just FYI...
I have previously and successfully ran the SampleNewResourceWithAttachment provided in the Samples folder (~%NX_ROOT\samples\sdk\rest\java) on r17.3 (RU3).
------------------------------
Kind Regards,
Brian
Original Message:
Sent: 07-20-2021 05:20 PM
From: miguel jimenez
Subject: createAttachment webservice ca servicedesk
Hello Michaell,
The example does not work in SDM 17.3, the log pdm_tomcat show
java.lang.LinkageError: loader constraint violation for class org.apache.axis.attachments.AttachmentPart: when selecting overriding method org.apache.axis.attachments.AttachmentPart.setDataHandler(Ljavax/activation/DataHandler;)V the class loader org.apache.catalina.loader.ParallelWebappClassLoader @65afeb6d (instance of org.apache.catalina.loader.ParallelWebappClassLoader, child of java.net.URLClassLoader @18be83e4 java.net.URLClassLoader) of the selected method's type org.apache.axis.attachments.AttachmentPart, and the class loader java.net.URLClassLoader @18be83e4 (instance of java.net.URLClassLoader, child of java.net.URLClassLoader @8bd1b6a java.net.URLClassLoader) for its super type javax.xml.soap.AttachmentPart have different Class objects for the type javax.activation.DataHandler used in the signature
I think the problem is the activation.jar and mail.jar that no longer work with java 11, I appreciate your comments.
Greetings,
Original Message:
Sent: 05-18-2021 06:39 AM
From: Michael Müller
Subject: createAttachment webservice ca servicedesk
A good SOAP example is in $NX_ROOT/samples/sdk/websvc/java/test3_attachments/create_attachment.java. There you can see ,how to set the DIME encapsulation as documented and required.
// Setup the client soap request
FileDataSource fds = new FileDataSource(filename);
DataHandler dhandler = new DataHandler(fds);
((org.apache.axis.client.Stub)usd)._setProperty(Call.ATTACHMENT_ENCAPSULATION_FORMAT, Call.ATTACHMENT_ENCAPSULATION_FORMAT_DIME);
((org.apache.axis.client.Stub)usd).addAttachment(dhandler);
Hope that helps
.....Michael
------------------------------
Principal Services Consultant
HCL Enterprise Studio
Germany
Original Message:
Sent: 05-12-2021 11:50 PM
From: alan Andre
Subject: createAttachment webservice ca servicedesk
Hello good day
My problem is that I can't use the createAttachment method because I don't know how to upload the file, I don't know what I'm missing
my code:
try {
int sid = wsUSD.login("xxxxxxxxxx", "xxxxxx");
System.out.println("SID del CA: " + sid);
try {
FileDataSource fds = new FileDataSource(filename);
DataHandler dhandler = new DataHandler(fds);
String handle = wsUSD.createAttachment(sid, "doc_rep:1002", "cr:11494369", "comment", filename);
System.out.println("Este es el Handle de archivo: " + handle);
} catch (Exception ex){
System.out.println("Creating attachment...FAIL: " + ex);
}
wsUSD.logout(sid);
System.out.println("logout ");
} catch (Exception ex) {
System.out.println("creatin SID...FAIL: " + ex);
}
I am using java 8 with jax-ws