|
1 /* |
|
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. Oracle designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Oracle in the LICENSE file that accompanied this code. |
|
10 * |
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
|
15 * accompanied this code). |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License version |
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 * |
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 * or visit www.oracle.com if you need additional information or have any |
|
23 * questions. |
|
24 */ |
|
25 |
|
26 package com.sun.xml.internal.ws.developer; |
|
27 |
|
28 import com.sun.xml.internal.ws.api.FeatureConstructor; |
|
29 import com.sun.istack.internal.Nullable; |
|
30 |
|
31 import javax.xml.ws.WebServiceFeature; |
|
32 |
|
33 import com.sun.xml.internal.org.jvnet.mimepull.MIMEConfig; |
|
34 |
|
35 import com.sun.org.glassfish.gmbal.ManagedAttribute; |
|
36 import com.sun.org.glassfish.gmbal.ManagedData; |
|
37 |
|
38 /** |
|
39 * Proxy needs to be created with this feature to configure StreamingAttachment |
|
40 * attachments behaviour. |
|
41 * |
|
42 * <pre> |
|
43 * for e.g.: To configure all StreamingAttachment attachments to be kept in memory |
|
44 * <p> |
|
45 * |
|
46 * StreamingAttachmentFeature feature = new StreamingAttachmentFeature(); |
|
47 * feature.setAllMemory(true); |
|
48 * |
|
49 * proxy = HelloService().getHelloPort(feature); |
|
50 * |
|
51 * </pre> |
|
52 * |
|
53 * @author Jitendra Kotamraju |
|
54 */ |
|
55 @ManagedData |
|
56 public final class StreamingAttachmentFeature extends WebServiceFeature { |
|
57 /** |
|
58 * Constant value identifying the {@link StreamingAttachment} feature. |
|
59 */ |
|
60 public static final String ID = "http://jax-ws.dev.java.net/features/mime"; |
|
61 |
|
62 private MIMEConfig config; |
|
63 |
|
64 private String dir; |
|
65 private boolean parseEagerly; |
|
66 private long memoryThreshold; |
|
67 |
|
68 public StreamingAttachmentFeature() { |
|
69 } |
|
70 |
|
71 @FeatureConstructor({"dir","parseEagerly","memoryThreshold"}) |
|
72 public StreamingAttachmentFeature(@Nullable String dir, boolean parseEagerly, long memoryThreshold) { |
|
73 this.enabled = true; |
|
74 this.dir = dir; |
|
75 this.parseEagerly = parseEagerly; |
|
76 this.memoryThreshold = memoryThreshold; |
|
77 } |
|
78 |
|
79 @ManagedAttribute |
|
80 public String getID() { |
|
81 return ID; |
|
82 } |
|
83 |
|
84 /** |
|
85 * Returns the configuration object. Once this is called, you cannot |
|
86 * change the configuration. |
|
87 * |
|
88 * @return |
|
89 */ |
|
90 @ManagedAttribute |
|
91 public MIMEConfig getConfig() { |
|
92 if (config == null) { |
|
93 config = new MIMEConfig(); |
|
94 config.setDir(dir); |
|
95 config.setParseEagerly(parseEagerly); |
|
96 config.setMemoryThreshold(memoryThreshold); |
|
97 config.validate(); |
|
98 } |
|
99 return config; |
|
100 } |
|
101 |
|
102 /** |
|
103 * Directory in which large attachments are stored |
|
104 */ |
|
105 public void setDir(String dir) { |
|
106 this.dir = dir; |
|
107 } |
|
108 |
|
109 /** |
|
110 * StreamingAttachment message is parsed eagerly |
|
111 */ |
|
112 public void setParseEagerly(boolean parseEagerly) { |
|
113 this.parseEagerly = parseEagerly; |
|
114 } |
|
115 |
|
116 /** |
|
117 * After this threshold(no of bytes), large attachments are |
|
118 * written to file system |
|
119 */ |
|
120 public void setMemoryThreshold(long memoryThreshold) { |
|
121 this.memoryThreshold = memoryThreshold; |
|
122 } |
|
123 |
|
124 } |