01: package com.sun.xml.ws.developer;
02:
03: import com.sun.xml.ws.api.FeatureConstructor;
04: import com.sun.istack.Nullable;
05:
06: import javax.xml.ws.WebServiceFeature;
07:
08: import org.jvnet.mimepull.MIMEConfig;
09:
10: /**
11: * Proxy needs to be created with this feature to configure StreamingAttachment
12: * attachments behaviour.
13: *
14: * <pre>
15: * for e.g.: To configure all StreamingAttachment attachments to be kept in memory
16: * <p>
17: *
18: * StreamingAttachmentFeature feature = new StreamingAttachmentFeature();
19: * feature.setAllMemory(true);
20: *
21: * proxy = HelloService().getHelloPort(feature);
22: *
23: * </pre>
24: *
25: * @author Jitendra Kotamraju
26: */
27: public final class StreamingAttachmentFeature extends WebServiceFeature {
28: /**
29: * Constant value identifying the {@link @StreamingAttachment} feature.
30: */
31: public static final String ID = "http://jax-ws.dev.java.net/features/mime";
32:
33: private MIMEConfig config;
34:
35: private String dir;
36: private boolean parseEagerly;
37: private long memoryThreshold;
38:
39: public StreamingAttachmentFeature() {
40: }
41:
42: @FeatureConstructor({"dir","parseEagerly","memoryThreshold"})
43: public StreamingAttachmentFeature(@Nullable
44: String dir, boolean parseEagerly, long memoryThreshold) {
45: this .enabled = true;
46: this .dir = dir;
47: this .parseEagerly = parseEagerly;
48: this .memoryThreshold = memoryThreshold;
49: }
50:
51: public String getID() {
52: return ID;
53: }
54:
55: /**
56: * Returns the configuration object. Once this is called, you cannot
57: * change the configuration.
58: *
59: * @return
60: */
61: public MIMEConfig getConfig() {
62: if (config == null) {
63: config = new MIMEConfig();
64: config.setDir(dir);
65: config.setParseEagerly(parseEagerly);
66: config.setMemoryThreshold(memoryThreshold);
67: config.validate();
68: }
69: return config;
70: }
71:
72: /**
73: * Directory in which large attachments are stored
74: */
75: public void setDir(String dir) {
76: this .dir = dir;
77: }
78:
79: /**
80: * StreamingAttachment message is parsed eagerly
81: */
82: public void setParseEagerly(boolean parseEagerly) {
83: this .parseEagerly = parseEagerly;
84: }
85:
86: /**
87: * After this threshold(no of bytes), large attachments are
88: * written to file system
89: */
90: public void setMemoryThreshold(int memoryThreshold) {
91: this.memoryThreshold = memoryThreshold;
92: }
93:
94: }
|