axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vaibhav@Axis" <vaibhav.jun...@gmail.com>
Subject RE: Axis 1.4 - Attachments Problem
Date Wed, 28 Nov 2007 12:41:29 GMT

Hi,
Thanks for replying. 
When i used rdh.getDataSource().getName(), i get the name of the .att file
which gets stored by default in the temp folder. Something like this,
C:\DOCUME~1\ctr5654\LOCALS~1\Temp\Axis42312.att

How can i get the original name of the file i.e., the source file name ?


sietsenicolaas.tenhoeve wrote:
> 
> Hi Vaibhav,
> 
> Since you have a DataHandler instance you can ask it the name.
> E.g. rdh.getDataSource().getName();
> 
> According to the API: DataSources encapsulating files may choose to
> return the filename of the object. (Typically this would be the last
> component of the filename, not an entire pathname.)
> 
> Regards,
> Sietse
> 
> 
> -----Original Message-----
> From: Vaibhav@Axis [mailto:vaibhav.jungay@gmail.com] 
> Sent: 28 November 2007 11:54
> To: axis-user@ws.apache.org
> Subject: Axis 1.4 - Attachments Problem
> 
> 
> Hi,
> My Requirement is to receive a PDF file from a server which sends a pdf
> file as an attachment. I am able to download the pdf as an attachment
> but not with the correct file name. And also whenever i try to receive
> the PDF using a client program, a copy of the file with .ATT attachment
> is stored in temp folder. 
> Can anyone help me on this ? 
> I have attached the Service class, Client and WSDD.
> 
> Service Class
> ---------------
> import java.net.MalformedURLException;
> 
> import javax.activation.DataHandler;
> import javax.activation.DataSource;
> import javax.activation.FileDataSource;
> 
> public class PDFAttachmentsService {
> 
> 	public DataHandler sendPdfs() throws MalformedURLException {
> 
> 		DataSource ds = new FileDataSource("C:/XYZ.pdf");
> 		DataHandler dataHandler = new DataHandler(ds);		
> 		return dataHandler;
> 	}
> }
> ------------------------------------------------------------------------
> --
> Client Class
> -----------
> public class PDFAttachment {
> 	
> 	public static void main(String args[]) {
> 		try {
> 			Service service = new Service();
> 
> 			Call call = (Call) service.createCall();
> 
> 			call
> 				
> .setTargetEndpointAddress("http://localhost:8080/axis/services/urn:PDFAt
> tachmentsService");
> 
> 			call.setOperationName(new
> QName("urn:PDFAttachmentsService",
> 					"sendPdfs")); 
> 
> 			QName qnameAttachment = new
> QName("urn:PDFAttachmentsService",
> 					"DataHandler");
> 			call.registerTypeMapping(PDFAttachment.class,
> qnameAttachment,
> 	
> JAFDataHandlerSerializerFactory.class,
> 	
> JAFDataHandlerDeserializerFactory.class);
> 
> 			call.setReturnType(qnameAttachment);
> 
> 			Object ret = call.invoke(new Object[] {});
> 
> 			if (null == ret) {
> 				System.out.println("Received null ");
> 				throw new AxisFault("", "Received null",
> null, null);
> 			}
> 
> 			if (ret instanceof String) {
> 				System.out.println("Received problem
> response from server: "
> 						+ ret);
> 				throw new AxisFault("", (String) ret,
> null, null);
> 			}
> 
> 			if (!(ret instanceof DataHandler)) {
> 				// The wrong type of object that what
> was expected.
> 				System.out.println("Received problem
> response from server:"
> 						+
> ret.getClass().getName());
> 				throw new AxisFault("",
> 						"Received problem
> response from server:"
> 								+
> ret.getClass().getName(), null, null);
> 
> 			}
> 
> 			DataHandler rdh = (DataHandler) ret;
> 			FileOutputStream outputStream = new
> FileOutputStream("D:/CopiedPDF.pdf");
> 			rdh.writeTo(outputStream);
> 			outputStream.flush();
> 			outputStream.close();
> 		} catch (Exception e) {
> 			System.err.println(e);
> 			e.printStackTrace();
> 		}
> 	}
> }
> ------------------------------------------------------------------------
> ---------
> WSDD file
> ----------
> <!-- This deploys PDF attachment service.  --> <deployment
> xmlns="http://xml.apache.org/axis/wsdd/"
> xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"
> xmlns:ns1="urn:PDFAttachmentsService" >
>   <service name="urn:PDFAttachmentsService" provider="java:RPC" >
>     <parameter name="className"
> value="samples.pdfattachments.PDFAttachmentsService"/>
>     <parameter name="allowedMethods" value="sendPdfs"/>
>     <parameter name="dataHandler" type="ns1:DataHandler"/>    
> 
>  <typeMapping
> deserializer="org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFac
> tory"
>    languageSpecificType="java:javax.activation.DataHandler"
> qname="ns1:DataHandler"
>    
> serializer="org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory
> " 
>     encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
>      />
>   </service>
> 
> </deployment>
> 
> --
> View this message in context:
> http://www.nabble.com/Axis-1.4---Attachments-Problem-tf4887980.html#a139
> 90733
> Sent from the Axis - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Axis-1.4---Attachments-Problem-tf4887980.html#a13991477
Sent from the Axis - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Mime
View raw message