Note that there are some explanatory texts on larger screens.

plurals
  1. POsaaj exception - Unable to parse content type: null
    primarykey
    data
    text
    <p>I'm fairly new to webservices and working through a SAAJ example of sending and recieving attachments (binary files). I can get it to work when the client sends the file but not when it requests it. I get an exception on the client side:<br> ERROR: 'Content is not allowed in prolog.' 24-Oct-2012 13:59:28 com.sun.xml.internal.messaging.saaj.soap.EnvelopeFactory createEnvelope SEVERE: SAAJ0511: Unable to create envelope from given source com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Unable to create envelope from given source</p> <p>Anybody have any ideas???my client code is as follows: </p> <pre><code>SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance(); SOAPConnection con = scf.createConnection(); SOAPFactory soapFactory = SOAPFactory.newInstance(); MessageFactory mf = MessageFactory.newInstance(); SOAPMessage msg = mf.createMessage(); SOAPHeader header = msg.getSOAPHeader(); header.detachNode(); SOAPBody body = msg.getSOAPBody(); Name bodyName = soapFactory.createName( "remoteOpen", "remoteOpen", "http://schemas.remoteOpen.com/remoteOpen"); SOAPBodyElement bodyElement = body.addBodyElement(bodyName); SOAPElement projectName = bodyElement.addChildElement("projectName"); projectName.addTextNode("filename"); msg.saveChanges(); // create the endpoint and send the message URL endpoint = new URL("http://localhost:8080/RemoteSaveProject/OpenServlet"); SOAPMessage response = con.call(msg, endpoint); con.close(); SOAPBody responseBody = response.getSOAPBody(); SOAPElement ackElem = (SOAPElement)responseBody.getFirstChild(); String acknowledgement = ackElem.getValue(); </code></pre> <p>the server code looks like this: </p> <pre><code>MimeHeaders mimeHeaders = new MimeHeaders(); Enumeration en = request.getHeaderNames(); while (en.hasMoreElements()) { String headerName = (String)en.nextElement(); String headerVal = request.getHeader(headerName); StringTokenizer tk = new StringTokenizer(headerVal, ","); while (tk.hasMoreTokens()){ mimeHeaders.addHeader(headerName, tk.nextToken().trim()); } } SOAPMessage message = mf.createMessage(mimeHeaders, request.getInputStream()); SOAPBody body = message.getSOAPBody(); Name bodyName = soapFactory.createName( "remoteOpen", "remoteOpen", "http://schemas.remoteOpen.com/remoteOpen"); Iterator projects = body.getChildElements(bodyName); SOAPElement project = (SOAPElement)projects.next(); Iterator projectNameIter = project.getChildElements(soapFactory.createName("projectName")); SOAPElement projectNameEle = (SOAPElement)projectNameIter.next(); String projectName = projectNameEle.getValue(); File file = new File(projectName); SOAPMessage reply = mf.createMessage(); SOAPHeader header = reply.getSOAPHeader(); header.detachNode(); SOAPBody replyBody = reply.getSOAPBody(); SOAPBodyElement bodyElement = replyBody.addBodyElement(soapFactory.createName("ack")); bodyElement.addTextNode("OK"); DataHandler dh = new DataHandler(new FileDataSource(file)); AttachmentPart attachment = reply.createAttachmentPart(dh); attachment.setContentId("123"); reply.addAttachmentPart(attachment); reply.saveChanges(); response.setStatus(HttpServletResponse.SC_OK); putHeaders(reply.getMimeHeaders(), response); response.setContentType("text/xml"); ServletOutputStream replyOS = response.getOutputStream(); reply.writeTo(replyOS); replyOS.flush(); replyOS.close(); </code></pre> <p>putHeaders looks like: </p> <pre><code>Iterator it = headers.getAllHeaders(); while (it.hasNext()) { MimeHeader header = (MimeHeader) it.next(); String[] values = headers.getHeader(header.getName()); if (values.length == 1) { res.setHeader( header.getName(), header.getValue()); } else { StringBuffer concat = new StringBuffer(); int i = 0; while (i &lt; values.length) { if (i != 0) { concat.append(','); } concat.append(values[i++]); } res.setHeader(header.getName(), concat.toString()); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload