Dynamically configure StreamingAttachment properties
I'm developing JAX-WS web service. My Java class looks like (with annotations):
@MTOM
@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() {
setMemoryThreshold(12345);
setTempDir("c:\\mydirectory");
}
Is this possible with JAX-WS RI?





Found a way which does not involve modifications of JAX-WS classes.
Inherit from WSServlet:
public class WSServletWithStreamingAttachmentInit extends WSServlet {
2. Override init method:
@Override public void init(ServletConfig servletConfig) throws ServletException {
super.init(servletConfig);
// 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");
fld.setAccessible(true);
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) {
((StreamingAttachmentFeature)ft).setDir(directory);
((StreamingAttachmentFeature)ft).setMemoryThreshold(threshold);
4. In web.xml, specify your class as servlet rather than WSServlet (obviously include your class into your web app):
<servlet-class>mtomtest.wsserver.WSServletWithStreamingAttachmentInit</servlet-class>