Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5845957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:30:32+00:00 2026-05-22T12:30:32+00:00

tl;dr version: Is there a way to force a strict mode for JAX-WS that

  • 0

tl;dr version: Is there a way to force a strict mode for JAX-WS that rejects invalid base64 for the base64Binary XSD data type?


Longer version: I have a web service that receives binary data which gets mapped to the XSD type base64Binary. While testing the service I found out that JAX-WS is very lenient when it comes to parsing of Base64 strings. No matter how invalid my input was, I could not get JAX-WS to produce an error.

I created a small test service and client that illustrates the problem. It can be copied more or less verbatim:

Service interface:

@WebService
public interface ITest2 {
    @WebMethod
    void foo(byte[] bs);
}

Service implementation and test:

@WebService(endpointInterface="foo.bar.ITest2")
public class Test2 implements ITest2 {

    private static final String requestTemplate = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:bar=\"http://bar.foo/\">" +
            "<soapenv:Header/>" +
            "<soapenv:Body>" +
            "<bar:foo>" +
            "<arg0>%s</arg0>" +
            "</bar:foo>" +
            "</soapenv:Body>" +
            "</soapenv:Envelope>";

    private static final String[] testVector = {
        "////==",
        "///==",
        "//==",
        "/==",
        "/==/==/==",
        "&lt;&gt;",
        "=====",
        "%%%///%%%==%%"
    };

    private static PrintWriter pw;

    static {
        try {
            pw = new PrintWriter("/tmp/output");
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) throws Exception {

        Endpoint e = Endpoint.publish("http://localhost:54321/foo", new Test2());

        URL requestUrl = new URL("http://localhost:54321/foo");

        for(String testVal : testVector) {
            pw.println("[client] >" + testVal + "<");
            HttpURLConnection urlc = (HttpURLConnection) requestUrl.openConnection();
            urlc.setRequestProperty("Content-Type", "text/xml;charset=UTF-8");

            urlc.setDoOutput(true);

            OutputStream out = urlc.getOutputStream();

            String request = String.format(requestTemplate, testVal);

            out.write(request.getBytes());
            out.flush();

            InputStream in = urlc.getInputStream();
            int read = -1;
            byte[] buf = new byte[1024];
            while((read = in.read(buf)) != -1) {
                System.err.print(new String(buf, 0, read));
            }
            System.err.println();
        }

        pw.flush();
        pw.close();

    }

    @Override
    public void foo(byte[] bs) {
        String encoded;
        if(bs == null) {
            encoded = "<null>";
        } else if(bs.length == 0) {
            encoded = "<empty>";
        } else {
            encoded = new String(Base64.encodeBase64(bs));
        }
        pw.println("[server] >" + encoded + "<");
    }

}

This produces the following output in /tmp/output (I’m using Jetty which logs quite a lot to the console and didn’t want to bother with that):

[client] >////==<
[server] ><null><
[client] >///==<
[server] ><null><
[client] >/w==<
[server] >/w==<
[client] >/==<
[server] ><null><
[client] >/==/==/==<
[server] >/////w==<
[client] >&lt;&gt;<
[server] ><empty><
[client] >=====<
[server] >/w==<
[client] >%%%///%%%==%%<
[server] >//8=<

So it’s a complete mess. Sometimes I receive null, sometimes an empty string and sometimes garbage gets replaced by other garbage. Also every request produces an HTTP reply 200 so nobody knows that anywhere something went wrong.

I know that you can force JAXB to validate this by adding a schema to an Unmarshaller. Since JAX-WS uses JAXB internally I hope that there is a possibility to turn that on for web services as well. Does anybody know if that’s possible and how?

I use the default JAX-WS implementation from Oracle Java 1.6.0_24 on Ubuntu.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T12:30:33+00:00Added an answer on May 22, 2026 at 12:30 pm

    You can enable schema validation in Metro (the JAXWS-RI) by adding the com.sun.xml.internal.ws.developer.SchemaValidation annotation on your endpoint implementation – Test2.

    This causes a SOAP fault of the form:

    ...
    <S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope">
      <faultcode>S:Server</faultcode>
      <faultstring>com.sun.istack.internal.XMLStreamException2:
           org.xml.sax.SAXParseException: cvc-datatype-valid.1.2.1: 
           'foo' is not a valid value for 'base64Binary'.</faultstring>
    ...
    

    Technically, I believe that faultcode should be S:Client, but what do I know.

    To the best of my knowledge there is no implementation agnostic way to do this; so if you deploy the code in another JAX-WS container, you’ll have to use the mechanism for that container.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to force a C# application to use a specific version
Short Version Is there a way to force (or provide a hint to) Microsoft
Is there any way to include the SVN repository revision number in the version
I have an assembly. Is there a way to detect which version of .NET
Is there a standard way to associate version string with a Python package in
There is a way to know the flash player version installed on the computer
Is there a reliable way of detecting what version of Java is installed on
Is there a version of memset() which sets a value that is larger than
Is there a version of FitNesse that works on Delphi 2006/2007/2009? If so where
Is there any way to force my asp.net application to load the assembly from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.