Package com.volantis.mps.message

Examples of com.volantis.mps.message.ProtocolIndependentMessage


    public ProtocolIndependentMessage getChannelIndependentMessage(
            String deviceName,
            MultiChannelMessage message )
            throws MessageException {

        ProtocolIndependentMessage rawMessage = null;

        if( message.getMessage() != null ) {
            rawMessage = doInternalRequest( deviceName,
                    message.getMessage(),
                    message.getCharacterEncoding() );
        } else if( message.getMessageURL() != null ) {
            rawMessage = doExternalRequest( deviceName,
                    message.getMessageURL(),
                    message.getCharacterEncoding() );
            if( rawMessage != null ) {
                rawMessage.setBaseURL( message.getMessageURL() );
            }
        }
        return rawMessage;
    }
View Full Code Here


    protected ProtocolIndependentMessage doInternalRequest( String deviceName,
                                                            String messageXML,
                                                            String characterEncoding )
            throws MessageException {

        ProtocolIndependentMessage rawMessage = null;

        try {
            InternalConfig internalConfig = new InternalConfig();
            InternalRequest internalRequest = new InternalRequest( deviceName,
                                                                   "mps" );
            InternalResponse internalResponse = new InternalResponse();

            MarinerRequestContext requestContext =
                    new MarinerInternalRequestContext( internalConfig,
                            internalRequest,
                            internalResponse,
                            null );


            // set character encoding if not null
            if (characterEncoding != null) {
                requestContext.setCharacterEncoding(characterEncoding);
            }


            // Parse the contents of the response as Marlin markup.
            // The processed page will be written to the response, so
            // we don't need to do anything further.
            XMLReader reader =
                    MarlinSAXHelper.getXMLReader( requestContext, null );

            EnvironmentContext environmentContext =
                    ContextInternals.getEnvironmentContext( requestContext );

            // The getXMLReader() call above will set up the pipelineContext in
            // the environmentContext.  See MarlinSAXHelper.setPipelineContext()
            XMLPipelineContext pipelineContext =
                    environmentContext.getPipelineContext();
            // set the Base URI in the pipeline's context
            try {
                URL baseURI = new URL( baseUrl );
                if( logger.isDebugEnabled() ) {
                    logger.debug( "Setting Base URI "
                                        + baseURI.toExternalForm() );
                }
                pipelineContext.pushBaseURI( baseURI.toExternalForm() );
            } catch( MalformedURLException e ) {
                throw new MessageException( e );
            }
            reader.parse( new InputSource( new StringReader( messageXML ) ) );

            MPSApplicationContext applicationContext =
                 (MPSApplicationContext)ContextInternals.getApplicationContext(
                                                               requestContext );

            applicationContext.getAssetMap();

            // set charset type for content
            String contentType = getContentTypeHeader(
                                        internalResponse.getContentType(),
                                        characterEncoding);


            rawMessage = new ProtocolIndependentMessage(
                    internalResponse.getResponseAsString(),
                    contentType,
                    applicationContext.getAssetMap(),
                    characterEncoding);
            rawMessage.setBaseURL( new URL( baseUrl ) );
            rawMessage.setMaxFileSize( applicationContext.getMaxFileSize() );
            rawMessage.setMaxMMSize( applicationContext.getMaxMMSize() );

            requestContext.release();
        } catch (SAXException se) {
            Exception cause = se.getException();
            // Check the root cause of the SAXException, as it may not be
View Full Code Here

    protected ProtocolIndependentMessage doExternalRequest( String deviceName,
                                                            URL messageURL,
                                                            String characterEncoding )
            throws MessageException {

        ProtocolIndependentMessage rawMessage;

        try {
            Collection requestHeaders = new ArrayList();

            requestHeaders.add( "Mariner-Application:mps" );
            requestHeaders.add( "Mariner-DeviceName:" + deviceName );
            int port = messageURL.getPort();
            if (port == -1) {
                port = messageURL.getDefaultPort();
            }
            String hostHeader = "Host: " + messageURL.getHost();
            if (port != -1) {
                hostHeader = hostHeader + ":" + Integer.toString(port);
            }
            requestHeaders.add(hostHeader);
            if( characterEncoding != null ) {
                requestHeaders.add( "Accept-Charset: " + characterEncoding );
            }

            HttpClient client = new HttpClient( messageURL, requestHeaders );

            HttpResponseHeader responseHeaders = client.getResponseHeaders();

            if( responseHeaders.getErrorCode() == 200 ) {

                // read in message from URL
                InputStreamReader isr =
                        (InputStreamReader)client.getInputStreamReader();
                String encoding = isr.getEncoding();

                StringBuffer bodyContent = new StringBuffer();

                char[] line = new char[1024];
                int read = isr.read(line, 0, line.length);
                while( read > -1 ) {
                    bodyContent.append( line, 0, read );
                    read = isr.read(line, 0, line.length);
                }
                String msg = bodyContent.toString();

                // if a charset has been specified we need to convert from
                // the InputStreamReader charset into the specified
                // charset
                if (characterEncoding != null) {
                    msg = ContentUtilities.convertEncoding(msg,
                                                           encoding,
                                                           characterEncoding);
                }
                String contentType = getContentTypeHeader(
                        responseHeaders.getHeader("Content-Type"),
                        characterEncoding);
                rawMessage = new ProtocolIndependentMessage(
                                        msg,
                                        contentType,
                                        getAssetMapFromHeaders(responseHeaders),
                                        characterEncoding);
                rawMessage.setBaseURL(messageURL);
                rawMessage.setMaxFileSize(
                                getMaxFileSizeFromHeaders( responseHeaders ) );
                rawMessage.setMaxMMSize(
                                getMaxMMSizeFromHeaders( responseHeaders ) );
            } else {
                throw new MessageException(
                        localizer.format( "mcs-server-unknown-error",
                        new Integer( responseHeaders.getErrorCode() ) ) );
View Full Code Here

        MessageAsset asset2 = new MessageAsset(MessageAsset.ON_DEVICE,
                "http://127.0.0.1:9999/test.gif");
        assetMap.put("asset1", asset1);
        assetMap.put("asset2", asset2);

        ProtocolIndependentMessage mesg = new ProtocolIndependentMessage(
                "Hello", "text/plain", assetMap);

        MimeMultipart mimeMultipart = (MimeMultipart)
                mimeMessageAssembler.assembleMessage(mesg,
                                                     new MessageAttachments());
View Full Code Here

   
    /** Test of assembleMessage method, of class com.volantis.mps.assembler.PlainTextMessageAssembler. */
    public void testAssembleMessage() throws MessageException {
        System.out.println("testAssembleMessage");
       
        ProtocolIndependentMessage msg = new ProtocolIndependentMessage(
                                    "I am a message", "text/plain", null );
        PlainTextMessageAssembler assembler = new PlainTextMessageAssembler();
        String txt = (String)assembler.assembleMessage( msg, null );
        assertEquals( "I am a message", txt );
    }
View Full Code Here

TOP

Related Classes of com.volantis.mps.message.ProtocolIndependentMessage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.