This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

processing attachments in web service  RSS feed

Tom Griffith
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello. if anybody has a minute, I can't seem to get a grasp on this. I have a web service that accepts parameters and returns a response string, no problem. I modified the client to send an attachment. however, I can't figure out how to make the web service implementation class process attachments. It seems to begin with having to obtain a handle to the incomng SOAPMessage, right...via SOAPMessageContext and MessageContext? Therein lies my problem (if what i said is true)...i can't figure out how to obtain or instantiate the/a MessageContext inside the web service...

something along the lines of...

MessageContext context = MessageContext.getCurrentContext();

does anybody have an example that begins before a MessageCntext object is created? Again, i just don't know how to instantiate a MessageContext inside the web service (if that is indeed the approach). Is it similar to servlets on some level where I need to obtain the request object?

Thank you very much for reading and for your time.
Peer Reynders
Posts: 2968
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You didn't mention which technology you are using.

In a SOAP Message handler it is handed to you:

javax.xml.rpc.handler.Handler.handleRequest(javax.xml.rpc.handler.MessageContext context);
javax.xml.rpc.handler.Handler.handleResponse(javax.xml.rpc.handler.MessageContext context);

In a JAX-RPC Servlet endpoint (JSE) you get it through ServiceEndpointContext.getMessageContext()

In an EJB endpoint you get it through SessionContext.getMessageContext().

That being said attachments in JAX-RPC are usually being handled with javax.activation.DataHandler.

SOAP attachments with JAX-RPC

This makes some sense as "SOAP with Attachments" are actually sent in a multi-part MIME envelope (the SOAP envelope travels in the first part) and DataHandlers were designed to deal with the serialization/de-serialization of MIME types.

JAX-WS 2.0:
You get the MessageContext through WebServiceContext.getMessageContext()

Faster Data Transport Means Faster Web Services with MTOM/XOP
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!