Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataHandler doesnt use proper encoding after publishing a Webservice #604

Closed
Tomas-Kraus opened this issue Jun 2, 2022 · 1 comment
Closed

Comments

@Tomas-Kraus
Copy link
Member

Previously tracked via: https://bugs.openjdk.java.net/browse/JDK-7029376

FULL PRODUCT VERSION :
java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Windows 2008 64Bit, Windows XP 64-Bit

A DESCRIPTION OF THE PROBLEM :
The DataHandler doesnt pay attention to the character-set after you publish a webservice via Endpoint.publish(..., ...).

The encoding is regarded when you dont publish a webservice.

I used a MimeBodyPart for testing but i could track the problem to the JDK-classes.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Please use the attached source-code. In order to compile you need mail.jar but the bug seems not to be related to this package.
run the code and take a look at system.out.
The umlauts are encoded in the same way in both lines despite different parameters for the encodign (utf-8 and iso-8859-1).
Uncomment the line with Endpoint.publish(..) and the line are encoded differently as they should be.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The encoding should be regarded. The umlauts should be encoded like:

=F6=E4=FCtest231
=C3=B6=C3=A4=C3=BCtest231
ACTUAL -
With the probided example the output looks like this:

=C3=B6=C3=A4=C3=BCtest231
=C3=B6=C3=A4=C3=BCtest231

or

=F6=E4=FCtest231
=F6=E4=FCtest231

depending on the file.encoding environment variable.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.io.OutputStream;

import javax.activation.DataHandler;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeUtility;
import javax.xml.ws.Endpoint;
import javax.jws.WebService;

@webservice(targetNamespace="http://www.mycompany.com/customerrelations", name="TestService")
public class enctest
{
public static void main(String[] args) throws Exception
{
enctest impl = new enctest();
Endpoint end = null;
//comment and uncomment the following line to see the difference
end = Endpoint.publish("http://localhost:81/Webservice", impl);

       MimeBodyPart mbptext = new MimeBodyPart();
       mbptext.setText("öäütest231", "iso-8859-1");
       mbptext.setHeader("Content-Type","text/plain; charset=\"iso-8859-1\"");

       DataHandler hdl = mbptext.getDataHandler();
       OutputStream os = MimeUtility.encode(System.out, "quoted-printable");
       //DataHandler->writeTo
       //--> ObjectDataContentHandler->writeTo
       //--> text_plain->writeTo
       hdl.writeTo(os);
       os.flush();

       System.out.println();

       MimeBodyPart mbptext2 = new MimeBodyPart();
       mbptext2.setText("öäütest231", "utf-8");
       mbptext2.setHeader("Content-Type","text/plain; charset=\"utf-8\"");

       DataHandler hdl2 = mbptext2.getDataHandler();
       OutputStream os2 = MimeUtility.encode(System.out, "quoted-printable");
       hdl2.writeTo(os2);
       os2.flush();

       if (end != null)
          end.stop();
}

public String doNothing()
{
    return "";
}

}

---------- END SOURCE ----------

Source: javaee/metro-jax-ws#1230
Author: LanceAndersen

@lukasj
Copy link
Member

lukasj commented Jun 9, 2022

works as expected in v4

@lukasj lukasj closed this as completed Jun 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants