synapse-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ruwan Linton" <ruwan.lin...@gmail.com>
Subject Re: svn commit: r652962 - in /synapse/trunk/java/modules: core/src/main/java/org/apache/synapse/config/xml/endpoints/ core/src/main/java/org/apache/synapse/core/axis2/ core/src/main/java/org/apache/synapse/endpoints/utils/ transports/src/main/java/or
Date Sat, 03 May 2008 01:45:16 GMT
Hi Andreas,

Any specific reason why you didn't add this encoding attribute to the
WSDLEndpoint?

Thanks,
Ruwan

On Sat, May 3, 2008 at 6:32 AM, <veithen@apache.org> wrote:

> Author: veithen
> Date: Fri May  2 18:02:15 2008
> New Revision: 652962
>
> URL: http://svn.apache.org/viewvc?rev=652962&view=rev
> Log:
> SYNAPSE-261:
> * For text payloads in VFS and mail transports, always use the encoding as
> determined by BaseUtils.getOMOutputFormat.
> * Allow setting the charset encoding in <address> elements.
>
> Modified:
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointFactory.java
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointSerializer.java
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2FlexibleMEPClient.java
>
>  synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/utils/EndpointDefinition.java
>
>  synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/mail/MailTransportSender.java
>
>  synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/vfs/VFSTransportSender.java
>
> Modified:
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointFactory.java
> URL:
> http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointFactory.java?rev=652962&r1=652961&r2=652962&view=diff
>
> ==============================================================================
> ---
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointFactory.java
> (original)
> +++
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointFactory.java
> Fri May  2 18:02:15 2008
> @@ -38,7 +38,7 @@
>  * Configuration syntax:
>  * <pre>
>  * &lt;endpoint [name="<em>name</em>"] [trace="enable|disable"]>
> - *   &lt;address uri="<em>url</em>" [format="soap11|soap12|pox|get"]
> [optimize="mtom|swa"] [statistics="enable|disable"]>
> + *   &lt;address uri="<em>url</em>" [format="soap11|soap12|pox|get"]
> [optimize="mtom|swa"] [encoding="<em>charset encoding</em>"]
> [statistics="enable|disable"]>
>  *     .. extensibility ..
>  *
>  *     &lt;enableRM [policy="<em>key</em>"]/>?
> @@ -142,6 +142,7 @@
>         OMAttribute address = elem.getAttribute(new QName("uri"));
>         OMAttribute format = elem.getAttribute(new QName("format"));
>         OMAttribute optimize = elem.getAttribute(new QName("optimize"));
> +        OMAttribute encoding = elem.getAttribute(new QName("encoding"));
>
>         EndpointDefinition endpoint = new EndpointDefinition();
>         OMAttribute statistics = elem.getAttribute(
> @@ -200,6 +201,10 @@
>                 endpoint.setUseSwa(true);
>             }
>         }
> +
> +        if (encoding != null) {
> +            endpoint.setCharSetEncoding(encoding.getAttributeValue());
> +        }
>
>         OMElement wsAddr = elem.getFirstChildWithName(new QName(
>
> org.apache.synapse.config.xml.XMLConfigConstants.SYNAPSE_NAMESPACE,
>
> Modified:
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointSerializer.java
> URL:
> http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointSerializer.java?rev=652962&r1=652961&r2=652962&view=diff
>
> ==============================================================================
> ---
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointSerializer.java
> (original)
> +++
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointSerializer.java
> Fri May  2 18:02:15 2008
> @@ -109,6 +109,11 @@
>         } else if (endpt.isUseMTOM()) {
>             address.addAttribute(fac.createOMAttribute("optimize", null,
> "mtom"));
>         }
> +
> +        if (endpt.getCharSetEncoding() != null) {
> +            address.addAttribute(fac.createOMAttribute("encoding", null,
> endpt.getCharSetEncoding()));
> +        }
> +
>         if (endpt.getAddress() != null) {
>             address.addAttribute(fac.createOMAttribute(
>                     "uri", null, endpt.getAddress()));
>
> Modified:
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2FlexibleMEPClient.java
> URL:
> http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2FlexibleMEPClient.java?rev=652962&r1=652961&r2=652962&view=diff
>
> ==============================================================================
> ---
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2FlexibleMEPClient.java
> (original)
> +++
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2FlexibleMEPClient.java
> Fri May  2 18:02:15 2008
> @@ -107,7 +107,8 @@
>                     "] [ force soap11=" + endpoint.isForceSOAP11() +
>                     "] [ force soap12=" + endpoint.isForceSOAP12() +
>                     "] [ pox=" + endpoint.isForcePOX() +
> -                    "] [ get=" + endpoint.isForceGET() : "") +
> +                    "] [ get=" + endpoint.isForceGET() +
> +                    "] [ encoding=" + endpoint.getCharSetEncoding() : "")
> +
>                 "] [ to " + synapseOutMessageContext.getTo() + "]");
>         }
>
> @@ -170,6 +171,11 @@
>                 axisOutMsgCtx.setDoingSwA(true);
>             }
>
> +            if (endpoint.getCharSetEncoding() != null) {
> +
>  axisOutMsgCtx.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING,
> +                        endpoint.getCharSetEncoding());
> +            }
> +
>             if (endpoint.getAddress() != null) {
>                 axisOutMsgCtx.setTo(new
> EndpointReference(endpoint.getAddress()));
>             }
>
> Modified:
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/utils/EndpointDefinition.java
> URL:
> http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/utils/EndpointDefinition.java?rev=652962&r1=652961&r2=652962&view=diff
>
> ==============================================================================
> ---
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/utils/EndpointDefinition.java
> (original)
> +++
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/utils/EndpointDefinition.java
> Fri May  2 18:02:15 2008
> @@ -90,7 +90,12 @@
>      * Endpoint message format. pox/soap11/soap12
>      */
>     private String format = null;
> -
> +
> +    /**
> +     * The charset encoding for messages sent to the endpoint.
> +     */
> +    private String charSetEncoding;
> +
>     /**
>      * timeout duration for waiting for a response. if the user has set
> some timeout action and
>      * the timeout duration is not set, default is set to 0 seconds. note
> that if the user has
> @@ -327,6 +332,24 @@
>     }
>
>     /**
> +     * Get the charset encoding for messages sent to the endpoint.
> +     *
> +     * @param charSetEncoding
> +     */
> +    public String getCharSetEncoding() {
> +        return charSetEncoding;
> +    }
> +
> +    /**
> +     * Set the charset encoding for messages sent to the endpoint.
> +     *
> +     * @param charSetEncoding the charset encoding or <code>null</code>
> +     */
> +    public void setCharSetEncoding(String charSetEncoding) {
> +        this.charSetEncoding = charSetEncoding;
> +    }
> +
> +    /**
>      * To check whether statistics should have collected or not
>      *
>      * @return Returns the int value that indicate statistics is enabled
> or not.
>
> Modified:
> synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/mail/MailTransportSender.java
> URL:
> http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/mail/MailTransportSender.java?rev=652962&r1=652961&r2=652962&view=diff
>
> ==============================================================================
> ---
> synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/mail/MailTransportSender.java
> (original)
> +++
> synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/mail/MailTransportSender.java
> Fri May  2 18:02:15 2008
> @@ -340,24 +340,26 @@
>                     }
>                 }
>             } else if
> (BaseConstants.DEFAULT_TEXT_WRAPPER.equals(firstChild.getQName())) {
> -                if (firstChild instanceof OMSourcedElementImpl) {
> -                    // Note: this code will be replaced by something more
> efficient later
> -                    baos = new ByteArrayOutputStream();
> -                    try {
> -                        XMLStreamReader reader =
> firstChild.getXMLStreamReader();
> -                        while (reader.hasNext()) {
> -                            if (reader.next() ==
> XMLStreamReader.CHARACTERS) {
> -                                baos.write(reader.getText().getBytes());
> -                            }
> -                        }
> -                    } catch (XMLStreamException e) {
> -                        handleException("Error serializing 'text' payload
> from OMSourcedElement", e);
> -                    }
> -                    dataHandler = new DataHandler(new String(
> -                        baos.toByteArray(), format.getCharSetEncoding()),
> MailConstants.TEXT_PLAIN);
> -                } else {
> -                    dataHandler = new DataHandler(firstChild.getText(),
> MailConstants.TEXT_PLAIN);
> -                }
> +//                if (firstChild instanceof OMSourcedElementImpl) {
> +//                    // Note: this code will be replaced by something
> more efficient later
> +//                    baos = new ByteArrayOutputStream();
> +//                    try {
> +//                        XMLStreamReader reader =
> firstChild.getXMLStreamReader();
> +//                        while (reader.hasNext()) {
> +//                            if (reader.next() ==
> XMLStreamReader.CHARACTERS) {
> +//
>  baos.write(reader.getText().getBytes());
> +//                            }
> +//                        }
> +//                    } catch (XMLStreamException e) {
> +//                        handleException("Error serializing 'text'
> payload from OMSourcedElement", e);
> +//                    }
> +//                    dataHandler = new DataHandler(new String(
> +//                        baos.toByteArray(),
> format.getCharSetEncoding()), MailConstants.TEXT_PLAIN);
> +//                } else {
> +//                    dataHandler = new DataHandler(firstChild.getText(),
> MailConstants.TEXT_PLAIN);
> +//                }
> +                dataHandler = new DataHandler(firstChild.getText(),
> MailConstants.TEXT_PLAIN +
> +                        "; charset=" + format.getCharSetEncoding());
>             } else {
>
>                 baos = new ByteArrayOutputStream();
>
> Modified:
> synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/vfs/VFSTransportSender.java
> URL:
> http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/vfs/VFSTransportSender.java?rev=652962&r1=652961&r2=652962&view=diff
>
> ==============================================================================
> ---
> synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/vfs/VFSTransportSender.java
> (original)
> +++
> synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/vfs/VFSTransportSender.java
> Fri May  2 18:02:15 2008
> @@ -42,6 +42,8 @@
>  import java.io.OutputStream;
>  import java.io.IOException;
>  import java.io.ByteArrayOutputStream;
> +import java.io.OutputStreamWriter;
> +import java.io.Writer;
>
>  /**
>  * axis2.xml - transport definition
> @@ -179,6 +181,7 @@
>         // within the files but just get the payload in its native format
>
>         OMElement firstChild =
> msgContext.getEnvelope().getBody().getFirstElement();
> +        OMOutputFormat format = BaseUtils.getOMOutputFormat(msgContext);
>         if (firstChild != null) {
>             if
> (BaseConstants.DEFAULT_BINARY_WRAPPER.equals(firstChild.getQName())) {
>                 try {
> @@ -213,24 +216,25 @@
>
>             } else if
> (BaseConstants.DEFAULT_TEXT_WRAPPER.equals(firstChild.getQName())) {
>                 try {
> -                    OutputStream os =
> responseFile.getContent().getOutputStream();
> +                    Writer out = new
> OutputStreamWriter(responseFile.getContent().getOutputStream(),
> +                            format.getCharSetEncoding());
>                     try {
>                         if (firstChild instanceof OMSourcedElementImpl) {
>                             XMLStreamReader reader =
> firstChild.getXMLStreamReader();
>                             while (reader.hasNext()) {
>                                 if (reader.next() ==
> XMLStreamReader.CHARACTERS) {
> -
>  os.write(reader.getText().getBytes());
> +                                    out.write(reader.getText());
>                                 }
>                             }
>                         } else {
> -                            os.write(firstChild.getText().getBytes());
> +                            out.write(firstChild.getText());
>                         }
>                     } catch (IOException e) {
>                         metrics.incrementFaultsSending();
>                         handleException("Error serializing text content of
> element : " +
>
> BaseConstants.DEFAULT_TEXT_WRAPPER, e);
>                     } finally {
> -                       os.close();
> +                       out.close();
>                     }
>                 } catch (FileSystemException e) {
>                     metrics.incrementFaultsSending();
> @@ -244,10 +248,10 @@
>                     handleException("Error serializing OMSourcedElement
> content", e);
>                 }
>             } else {
> -                populateSOAPFile(responseFile, msgContext);
> +                populateSOAPFile(responseFile, msgContext, format);
>             }
>         } else {
> -            populateSOAPFile(responseFile, msgContext);
> +            populateSOAPFile(responseFile, msgContext, format);
>         }
>
>         // update metrics
> @@ -267,8 +271,7 @@
>      * @param msgContext the message context that holds the message to be
> written
>      * @throws AxisFault on error
>      */
> -    private void populateSOAPFile(FileObject responseFile, MessageContext
> msgContext) throws AxisFault {
> -        OMOutputFormat format = BaseUtils.getOMOutputFormat(msgContext);
> +    private void populateSOAPFile(FileObject responseFile, MessageContext
> msgContext, OMOutputFormat format) throws AxisFault {
>         MessageFormatter messageFormatter = null;
>         try {
>             messageFormatter =
> TransportUtils.getMessageFormatter(msgContext);
>
>
>


-- 
Ruwan Linton
http://www.wso2.org - "Oxygenating the Web Services Platform"

Mime
View raw message