|
1 /* |
|
2 * Copyright (c) 1997, 2010, 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.encoding; |
|
27 |
|
28 import com.sun.istack.internal.Nullable; |
|
29 import com.sun.istack.internal.NotNull; |
|
30 |
|
31 /** |
|
32 * @author Vivek Pandey |
|
33 */ |
|
34 public final class ContentTypeImpl implements com.sun.xml.internal.ws.api.pipe.ContentType { |
|
35 private final @NotNull String contentType; |
|
36 private final @NotNull String soapAction; |
|
37 private final @Nullable String accept; |
|
38 private final @Nullable String charset; |
|
39 |
|
40 public ContentTypeImpl(String contentType) { |
|
41 this(contentType, null, null); |
|
42 } |
|
43 |
|
44 public ContentTypeImpl(String contentType, @Nullable String soapAction) { |
|
45 this(contentType, soapAction, null); |
|
46 } |
|
47 |
|
48 public ContentTypeImpl(String contentType, @Nullable String soapAction, @Nullable String accept) { |
|
49 this(contentType, soapAction, accept, null); |
|
50 } |
|
51 |
|
52 public ContentTypeImpl(String contentType, @Nullable String soapAction, @Nullable String accept, String charsetParam) { |
|
53 this.contentType = contentType; |
|
54 this.accept = accept; |
|
55 this.soapAction = getQuotedSOAPAction(soapAction); |
|
56 if (charsetParam == null) { |
|
57 String tmpCharset = null; |
|
58 try { |
|
59 tmpCharset = new ContentType(contentType).getParameter("charset"); |
|
60 } catch(Exception e) { |
|
61 //Ignore the parsing exception. |
|
62 } |
|
63 charset = tmpCharset; |
|
64 } else { |
|
65 charset = charsetParam; |
|
66 } |
|
67 } |
|
68 |
|
69 /** |
|
70 * Returns the character set encoding. |
|
71 * |
|
72 * @return returns the character set encoding. |
|
73 */ |
|
74 public @Nullable String getCharSet() { |
|
75 return charset; |
|
76 } |
|
77 |
|
78 /** BP 1.1 R1109 requires SOAPAction too be a quoted value **/ |
|
79 private String getQuotedSOAPAction(String soapAction){ |
|
80 if(soapAction == null || soapAction.length() == 0){ |
|
81 return "\"\""; |
|
82 }else if(soapAction.charAt(0) != '"' && soapAction.charAt(soapAction.length() -1) != '"'){ |
|
83 //surround soapAction by double quotes for BP R1109 |
|
84 return "\"" + soapAction + "\""; |
|
85 }else{ |
|
86 return soapAction; |
|
87 } |
|
88 } |
|
89 |
|
90 public String getContentType() { |
|
91 return contentType; |
|
92 } |
|
93 |
|
94 public String getSOAPActionHeader() { |
|
95 return soapAction; |
|
96 } |
|
97 |
|
98 public String getAcceptHeader() { |
|
99 return accept; |
|
100 } |
|
101 |
|
102 public static class Builder { |
|
103 public String contentType; |
|
104 public String soapAction; |
|
105 public String accept; |
|
106 public String charset; |
|
107 public ContentTypeImpl build() { |
|
108 return new ContentTypeImpl(contentType, soapAction, accept, charset); |
|
109 } |
|
110 } |
|
111 } |