Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

How to get SOAP attachment

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,

I have been developing a web service which receives soap message with attachments.
what i want to do is get the attachments body as text format.
To achieve this, i added a basichandler to my web service and tried to print the attachment content to console.
But receiving this exception;
java.io.IOException: Resource has been deleted.
at org.apache.axis.attachments.ManagedMemoryDataSource$Instream.<init>(ManagedMemoryDataSource.java:517)
at org.apache.axis.attachments.ManagedMemoryDataSource.getInputStream(ManagedMemoryDataSource.java:182)
at webservice.messagehandlers.CfDataSourceReader.convertToString(CfDataSourceReader.java:25)
at webservice.messagehandlers.ReceiveMMSSoapContextHandler.invoke(ReceiveMMSSoapContextHandler.java:46)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.server.AxisServer.invoke(AxisServer.java:249)
at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Thread.java:595)

Below some examples for my case is added.

Is there any idea about this case?

Thanks in advance...

MY HANDLER
public class ReceiveMMSSoapContextHandler extends BasicHandler {
private static PrintStream out = System.out;


public void invoke(org.apache.axis.MessageContext arg0) throws AxisFault {
SOAPMessage soapMessage = arg0.getMessage();
try {
Date now = new Date();
out.println("SOAP MESSAGE: - JUST CAME- "now"\n");
soapMessage.writeTo(out);
out.println("END OF SOAP MESSAGE - MESSAGE END - \n");

Iterator attachments = soapMessage.getAttachments();
// Process all attachments
while(attachments.hasNext()){
AttachmentPart attachment = (AttachmentPart)attachments.next();
DataHandler dh = attachment.getDataHandler();
System.out.println("ATTACHMENT CONTENT ID=" + attachment.getContentId());
System.out.println("ATTACHMENT CONTENT LOCATION="+ attachment.getContentLocation());
System.out.println("ATTACHMENT CONTENT TYPE="+ attachment.getContentType());
System.out.println("ATTACHMENT TO_STRING ="+ attachment.toString());
System.out.println("ATTACHMENT CONTTENT BODY=" + CfDataSourceReader.convertToString(dh.getDataSource()));
}

} catch (SOAPException e) {
// TODO Auto-generated catch block
out.println("ReceiveMMSSoapContextHandler invoke SOAPEXCEPTION OCCURRED!!");
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
out.println("ReceiveMMSSoapContextHandler invoke IOEXCEPTION OCCURRED!!");
e.printStackTrace();
}

}

public static String convertToString(DataSource ds){

try{
InputStream inps = ds.getInputStream();
ByteArrayOutputStream lous = new ByteArrayOutputStream();
byte buf[] = new byte4096;
int length;
while (true){
length = inps.read (buf);
if (length < 0)
break;
lous.write (buf, 0, length);
}
return lous.toString();
}
catch(Exception e){
System.out.println("Error converting datasource");
e.printStackTrace();
return null;
}
}
}

Example soap message sent to my web service :

------=_Part_19_33004442.1239440873484
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: binary
Content-Id: <254A6812A527C261291DF34B5ADACC29>

<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Header>
<mm7:TransactionID SOAP-ENV:mustUnderstand="1" xmlns:mm7="http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-2">xxxxxxxxxxxxxxxxxxxxxxx</mm7:TransactionID>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<mm7:DeliverReq xmlns:mm7="http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-2">
<MM7Version>5.3.0</MM7Version><LinkedID>xxxxxxxxxxxxxxxxxx</LinkedID><Subject></Subject><Sender><Number>05327004899</Number></Sender><Recipients><To><Number>3300</Number></To></Recipients><TimeStamp>2009-04-11T11:59:37Z</TimeStamp><Priority>Normal</Priority></mm7:DeliverReq>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

------=_Part_19_33004442.1239440873484
Content-Type: multipart/mixed; boundary="----=_Part_36464_30886160.1239440977866"
Content-Transfer-Encoding: binary
Content-Id: <5CED6F2764685513F43EC3F31E1DE107>

------=_Part_36464_30886160.1239440977866
Content-Type: application/smil; filename=01smil; name=01smil
Content-Transfer-Encoding: 7bit
Content-Location: 01smil
Content-ID: <AEHXm>

<smil>
<head>
<layout>
<root-layout width="128" height="160" />
<region id="Text" width="100%" height="30%" left="0%" top="70%" fit="scroll" />
<region id="Image" width="100%" height="70%" left="0%" top="0%" fit="fill" />
</layout>
</head>
<body>
<par dur="8000ms">
<text src="Text01.txt" region="Text" />

</par>
</body>
</smil>

------=_Part_36464_30886160.1239440977866
Content-Type: text/plain; filename=Text01.txt; name=Text01.txt;
charset=utf-8
Content-Transfer-Encoding: quoted-printable
Content-Location: Text01.txt

Can=C4=B1m sende re=C5=9Fmini g=C3=B4ndr yoksa yazmam daha
------=_Part_36464_30886160.1239440977866
Content-Type: image/jpeg; filename=G_r_nt024.jpg; name=G_r_nt024.jpg
Content-Transfer-Encoding: base64
Content-Location: G_r_nt024.jpg

//SOME BINARY DATA

------=_Part_36464_30886160.1239440977866--

------=_Part_19_33004442.1239440873484--
reply
    Bookmark Topic Watch Topic
  • New Topic