Skip to main content

Dynamically configure StreamingAttachment properties

Please note these forums are being decommissioned and use the new and improved forums at
1 reply [Last post]
Joined: 2012-02-01
Points: 0

I'm developing JAX-WS web service. My Java class looks like (with annotations):

@WebService(endpointInterface = "mtomtest.wsserver.mtomserver")
@StreamingAttachment(parseEagerly=true, memoryThreshold=4000000L, dir="D:\\projects\\123\\files\\temp")
public class mtomserverImpl implements mtomserver {

Note hardcoded values for StreamingAttachment annotation. I want to be able to dynamically initialize those values from my code - any way of dong that? So I want to do something like (on server):

configureMyself() {

Is this possible with JAX-WS RI?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2012-02-01
Points: 0

Found a way which does not involve modifications of JAX-WS classes.

  1. Inherit from WSServlet:

public class WSServletWithStreamingAttachmentInit extends WSServlet {

2. Override init method:

@Override public void init(ServletConfig servletConfig) throws ServletException {


// somehow obtain streaming attachment parameters you want to override, I loaded them from servlet config

// now call the method to override those params

modifyStreamingAttachmentFeature(dir, nThreshold);


3. Finally the method to override params:

protected void modifyStreamingAttachmentFeature(String directory, long threshold) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {

// tricky part - delegate field of WSServlet class is private. Use reflection to access it

Field fld = WSServlet.class.getDeclaredField("delegate");


WSServletDelegate dlgt = (WSServletDelegate)fld.get(this);

if (dlgt.adapters != null) {

for (ServletAdapter adapter : dlgt.adapters) {

WSBinding binding = adapter.getEndpoint().getBinding();

WSFeatureList wsfl = binding.getFeatures();

for (WebServiceFeature ft: wsfl) {

if (ft instanceof StreamingAttachmentFeature) {



4. In web.xml, specify your class as servlet rather than WSServlet (obviously include your class into your web app):