5
votes

On client side I created 3 attachments in the following way:

public String sendMessage(MMSMessage mmsMessage, String formatCDR, FlowSessionData flowSessionData)
        throws IOException, ServiceException, PolicyException {

    SendMessage sendMessage = sendMessageService.getSendMessage();
    int index = 1;
    List<Attachment> atts = new ArrayList<Attachment>();
    BufferedImage image =  ImageIO.read(new URL(mmsMessage.getImgPath()));
    atts.add(createAttachmentPart(mmsMessage.getImgMimeType(), image, index));
    if (mmsMessage.getPrerollText() != null) {
        atts.add(createAttachmentPart("text/plain", mmsMessage.getPrerollText(), index++));
    }
    if (mmsMessage.getPostrollText() != null) {
        atts.add(createAttachmentPart("text/plain", mmsMessage.getPostrollText(), index++));
    }
    setServiceParams((BindingProvider) sendMessage, atts, configService.getSendMessageEndpointAddress());
    String value = null;
    validateURI(configService.getParlayxCallbackEndpointService() + "/" + NOTOFICATION_MMS_INTERFACE);
    SimpleReference correlator = new SimpleReference();
    correlator.setCorrelator(formatCDR);
    correlator.setInterfaceName(NOTOFICATION_MMS_INTERFACE);
    correlator.setEndpoint(configService.getParlayxCallbackEndpointService() + "/" + NOTOFICATION_MMS_INTERFACE);
    String toNumber = mmsMessage.getSmsServiceActivationNumber().get(0);
    if (!toNumber.startsWith(MSGConstants.PHONE_URI_PREFIX)) {
        if (!toNumber.startsWith("+")) {
            toNumber = "+" + toNumber;
        }
        toNumber = MSGConstants.PHONE_URI_PREFIX + toNumber;
    }
    validateURI(toNumber);
    List<String> addr = new ArrayList<String>();
    addr.add(toNumber);
    value = sendMessage.sendMessage(addr, mmsMessage.getSenderAddress(), mmsMessage.getSubject(), null, null,
            correlator);
    LOGGER.info(value);
    return value;
}

private Attachment createAttachmentPart(String mimeType, Object data, int index) {
        return new AttachmentImpl(String.valueOf(index), new DataHandler(data, mimeType));
    }

private void setServiceParams(BindingProvider serviceInf, Collection<Attachment> attachments, String endPoint) {
        Map<String, Object> requestContext = serviceInf.getRequestContext();
        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endPoint);
        requestContext.put(BindingProvider.USERNAME_PROPERTY, configService.getParlayxEndPointUserName());
        requestContext.put(BindingProvider.PASSWORD_PROPERTY, configService.getParlayxEndPointPassword());
        final Client client = ClientProxy.getClient(serviceInf);
        final HTTPConduit http = (HTTPConduit) client.getConduit();
        final HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
        httpClientPolicy.setReceiveTimeout(configService.getParlayxEndPointTimeOut());
        httpClientPolicy.setAllowChunking(false);
        httpClientPolicy.setConnectionTimeout(configService.getParlayxEndPointTimeOut());
        http.setClient(httpClientPolicy);
        if (attachments != null && !attachments.isEmpty()) {
            requestContext.put(org.apache.cxf.message.Message.ATTACHMENTS, attachments);
        }
    }

And I receive the exception below, what causes it and how can I fix it?

WARNING: Interceptor for {http://www.csapi.org/wsdl/parlayx/multimedia_messaging/send/v2_4/service}SendMessageService#{http://www.csapi.org/wsdl/parlayx/multimedia_messaging/send/v2_4/interface}sendMessage has thrown exception, unwinding now org.apache.cxf.binding.soap.SoapFault: Error reading XMLStreamReader. at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:222) at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:60) at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:255) at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:755) at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:2335) at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:2193) at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:2037) at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56) at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:697) at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62) at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:255) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:516) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:313) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:265) at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73) at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:124) at $Proxy92.sendMessage(Unknown Source) at com.amobee.common.sms.ParlayxMessagingService.sendMessage(ParlayxMessagingService.java:105) at com.amobee.nc.protocol.msg.MMSResponseBuilder.buildResponseMessage(MMSResponseBuilder.java:96) at com.amobee.nc.protocol.msg.BaseMSGResponseWriter.getResponse(BaseMSGResponseWriter.java:59) at com.amobee.nc.protocol.AbstractResponseWriter.write(AbstractResponseWriter.java:75) at com.amobee.frontend.servlets.AbstractBaseServlet.runCommand(AbstractBaseServlet.java:124) at com.amobee.frontend.servlets.AbstractBaseServlet.doGet(AbstractBaseServlet.java:64) at javax.servlet.http.HttpServlet.service(HttpServlet.java:575) at javax.servlet.http.HttpServlet.service(HttpServlet.java:668) at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:390) at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182) at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765) at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418) at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) at org.mortbay.jetty.Server.handle(Server.java:326) at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542) at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923) at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547) at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212) at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) at org.mortbay.jetty.bio.SocketConnector$Connection.run(SocketConnector.java:228) at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582) Caused by: com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog at [row,col {unknown-source}]: [1,0] at com.ctc.wstx.sr.StreamScanner.throwUnexpectedEOF(StreamScanner.java:682) at com.ctc.wstx.sr.BasicStreamReader.handleEOF(BasicStreamReader.java:2090) at com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:1996) at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1100) at com.ctc.wstx.sr.BasicStreamReader.nextTag(BasicStreamReader.java:1123) at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:122) ... 40 more

Thanks, Daniela

1
I've searched in many forums trying to find a solution for this problem and unfortunatelly there is no definitive solution. Please, verify if your code enters in a infinite loop during at the place where the output xml is being generated. In my case, there was cyclic reference between objects inside a loop.André Leitão

1 Answers

0
votes

This exception means that you have End of file character within the XML message, you should use Base64bit type to use attachments in Web services to avoid such error like that.