src/share/jaxws_classes/com/sun/xml/internal/ws/transport/http/HttpAdapter.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2013, 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.transport.http;
  27 
  28 import java.io.ByteArrayOutputStream;
  29 import java.io.IOException;
  30 import java.io.InputStream;
  31 import java.io.OutputStream;
  32 import java.io.OutputStreamWriter;
  33 import java.io.PrintWriter;
  34 import java.net.HttpURLConnection;


  35 import java.util.Collections;
  36 import java.util.HashMap;
  37 import java.util.List;
  38 import java.util.Map;
  39 import java.util.Map.Entry;

  40 import java.util.TreeMap;
  41 import java.util.logging.Level;
  42 import java.util.logging.Logger;
  43 
  44 import javax.xml.ws.Binding;
  45 import javax.xml.ws.WebServiceException;
  46 import javax.xml.ws.http.HTTPBinding;
  47 
  48 import com.oracle.webservices.internal.api.message.PropertySet;
  49 import com.sun.istack.internal.NotNull;
  50 import com.sun.istack.internal.Nullable;
  51 import com.sun.xml.internal.ws.api.Component;
  52 import com.sun.xml.internal.ws.api.EndpointAddress;
  53 import com.sun.xml.internal.ws.api.SOAPVersion;
  54 import com.sun.xml.internal.ws.api.addressing.AddressingVersion;
  55 import com.sun.xml.internal.ws.api.addressing.NonAnonymousResponseProcessor;
  56 import com.sun.xml.internal.ws.api.ha.HaInfo;
  57 import com.sun.xml.internal.ws.api.message.ExceptionHasMessage;
  58 import com.sun.xml.internal.ws.api.message.Message;
  59 import com.sun.xml.internal.ws.api.message.Packet;


 155         this.owner = owner;
 156         this.urlPattern = urlPattern;
 157 
 158         initWSDLMap(endpoint.getServiceDefinition());
 159     }
 160 
 161     /**
 162      * Return the last known service definition of the endpoint.
 163      *
 164      * @return The service definition of the endpoint
 165      */
 166     public ServiceDefinition getServiceDefinition() {
 167         return this.serviceDefinition;
 168     }
 169 
 170     /**
 171      * Fill in WSDL map.
 172      *
 173      * @param sdef service definition
 174      */
 175     public final void initWSDLMap(ServiceDefinition sdef) {
 176         this.serviceDefinition = sdef;
 177         if(sdef==null) {
 178             wsdls = Collections.emptyMap();
 179             revWsdls = Collections.emptyMap();
 180         } else {
 181             wsdls = new HashMap<String, SDDocument>();  // wsdl=1 --> Doc







 182             // Sort WSDL, Schema documents based on SystemId so that the same
 183             // document gets wsdl=x mapping
 184             Map<String, SDDocument> systemIds = new TreeMap<String, SDDocument>();
 185             for (SDDocument sdd : sdef) {
 186                 if (sdd == sdef.getPrimary()) { // No sorting for Primary WSDL
 187                     wsdls.put("wsdl", sdd);
 188                     wsdls.put("WSDL", sdd);
 189                 } else {
 190                     systemIds.put(sdd.getURL().toString(), sdd);
 191                 }
 192             }
 193 
 194             int wsdlnum = 1;
 195             int xsdnum = 1;
 196             for (Entry<String, SDDocument> e : systemIds.entrySet()) {
 197                 SDDocument sdd = e.getValue();
 198                 if (sdd.isWSDL()) {
 199                     wsdls.put("wsdl="+(wsdlnum++),sdd);
 200                 }
 201                 if (sdd.isSchema()) {
 202                     wsdls.put("xsd="+(xsdnum++),sdd);


































 203                 }




 204             }
 205 
 206             revWsdls = new HashMap<SDDocument,String>();    // Doc --> wsdl=1


































 207             for (Entry<String,SDDocument> e : wsdls.entrySet()) {
 208                 if (!e.getKey().equals("WSDL")) {           // map Doc --> wsdl, not WSDL
 209                     revWsdls.put(e.getValue(),e.getKey());
 210                 }
 211             }

































































 212         }
 213     }
 214 
 215     /**
 216      * Returns the "/abc/def/ghi" portion if
 217      * the URL pattern is "/abc/def/ghi/*".
 218      */
 219     public String getValidPath() {
 220         if (urlPattern.endsWith("/*")) {
 221             return urlPattern.substring(0, urlPattern.length() - 2);
 222         } else {
 223             return urlPattern;
 224         }
 225     }
 226 
 227     @Override
 228     protected HttpToolkit createToolkit() {
 229         return new HttpToolkit();
 230     }
 231 


 964     }
 965 
 966     static {
 967         try {
 968             dump = Boolean.getBoolean(HttpAdapter.class.getName() + ".dump");
 969         } catch (SecurityException se) {
 970             if (LOGGER.isLoggable(Level.CONFIG)) {
 971                 LOGGER.log(Level.CONFIG, "Cannot read ''{0}'' property, using defaults.",
 972                         new Object[] {HttpAdapter.class.getName() + ".dump"});
 973             }
 974         }
 975         try {
 976             dump_threshold = Integer.getInteger(HttpAdapter.class.getName() + ".dumpTreshold", 4096);
 977         } catch (SecurityException se) {
 978             if (LOGGER.isLoggable(Level.CONFIG)) {
 979                 LOGGER.log(Level.CONFIG, "Cannot read ''{0}'' property, using defaults.",
 980                         new Object[] {HttpAdapter.class.getName() + ".dumpTreshold"});
 981             }
 982         }
 983         try {

 984             setPublishStatus(Boolean.getBoolean(HttpAdapter.class.getName() + ".publishStatusPage"));

 985         } catch (SecurityException se) {
 986             if (LOGGER.isLoggable(Level.CONFIG)) {
 987                 LOGGER.log(Level.CONFIG, "Cannot read ''{0}'' property, using defaults.",
 988                         new Object[] {HttpAdapter.class.getName() + ".publishStatusPage"});
 989             }
 990         }
 991     }
 992 
 993     public static void setDump(boolean dumpMessages) {
 994         HttpAdapter.dump = dumpMessages;
 995     }
 996 }
   1 /*
   2  * Copyright (c) 1997, 2014, 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.transport.http;
  27 
  28 import java.io.ByteArrayOutputStream;
  29 import java.io.IOException;
  30 import java.io.InputStream;
  31 import java.io.OutputStream;
  32 import java.io.OutputStreamWriter;
  33 import java.io.PrintWriter;
  34 import java.net.HttpURLConnection;
  35 import java.util.AbstractMap;
  36 import java.util.Collection;
  37 import java.util.Collections;
  38 import java.util.HashMap;
  39 import java.util.List;
  40 import java.util.Map;
  41 import java.util.Map.Entry;
  42 import java.util.Set;
  43 import java.util.TreeMap;
  44 import java.util.logging.Level;
  45 import java.util.logging.Logger;
  46 
  47 import javax.xml.ws.Binding;
  48 import javax.xml.ws.WebServiceException;
  49 import javax.xml.ws.http.HTTPBinding;
  50 
  51 import com.oracle.webservices.internal.api.message.PropertySet;
  52 import com.sun.istack.internal.NotNull;
  53 import com.sun.istack.internal.Nullable;
  54 import com.sun.xml.internal.ws.api.Component;
  55 import com.sun.xml.internal.ws.api.EndpointAddress;
  56 import com.sun.xml.internal.ws.api.SOAPVersion;
  57 import com.sun.xml.internal.ws.api.addressing.AddressingVersion;
  58 import com.sun.xml.internal.ws.api.addressing.NonAnonymousResponseProcessor;
  59 import com.sun.xml.internal.ws.api.ha.HaInfo;
  60 import com.sun.xml.internal.ws.api.message.ExceptionHasMessage;
  61 import com.sun.xml.internal.ws.api.message.Message;
  62 import com.sun.xml.internal.ws.api.message.Packet;


 158         this.owner = owner;
 159         this.urlPattern = urlPattern;
 160 
 161         initWSDLMap(endpoint.getServiceDefinition());
 162     }
 163 
 164     /**
 165      * Return the last known service definition of the endpoint.
 166      *
 167      * @return The service definition of the endpoint
 168      */
 169     public ServiceDefinition getServiceDefinition() {
 170         return this.serviceDefinition;
 171     }
 172 
 173     /**
 174      * Fill in WSDL map.
 175      *
 176      * @param sdef service definition
 177      */
 178     public final void initWSDLMap(final ServiceDefinition serviceDefinition) {
 179         this.serviceDefinition = serviceDefinition;
 180         if(serviceDefinition==null) {
 181             wsdls = Collections.emptyMap();
 182             revWsdls = Collections.emptyMap();
 183         } else {
 184             wsdls = new AbstractMap<String, SDDocument>() {
 185                 private Map<String, SDDocument> delegate = null;
 186 
 187                 private synchronized Map<String, SDDocument> delegate() {
 188                     if (delegate != null)
 189                         return delegate;
 190 
 191                     delegate = new HashMap<String, SDDocument>();  // wsdl=1 --> Doc
 192                     // Sort WSDL, Schema documents based on SystemId so that the same
 193                     // document gets wsdl=x mapping
 194                     Map<String, SDDocument> systemIds = new TreeMap<String, SDDocument>();
 195                     for (SDDocument sdd : serviceDefinition) {
 196                         if (sdd == serviceDefinition.getPrimary()) { // No sorting for Primary WSDL
 197                             delegate.put("wsdl", sdd);
 198                             delegate.put("WSDL", sdd);
 199                         } else {
 200                             systemIds.put(sdd.getURL().toString(), sdd);
 201                         }
 202                     }
 203 
 204                     int wsdlnum = 1;
 205                     int xsdnum = 1;
 206                     for (Entry<String, SDDocument> e : systemIds.entrySet()) {
 207                         SDDocument sdd = e.getValue();
 208                         if (sdd.isWSDL()) {
 209                             delegate.put("wsdl="+(wsdlnum++),sdd);
 210                         }
 211                         if (sdd.isSchema()) {
 212                             delegate.put("xsd="+(xsdnum++),sdd);
 213                         }
 214                     }
 215 
 216                     return delegate;
 217                 }
 218 
 219                 @Override
 220                 public void clear() {
 221                     delegate().clear();
 222                 }
 223 
 224                 @Override
 225                 public boolean containsKey(Object arg0) {
 226                     return delegate().containsKey(arg0);
 227                 }
 228 
 229                 @Override
 230                 public boolean containsValue(Object arg0) {
 231                     return delegate.containsValue(arg0);
 232                 }
 233 
 234                 @Override
 235                 public SDDocument get(Object arg0) {
 236                     return delegate().get(arg0);
 237                 }
 238 
 239                 @Override
 240                 public boolean isEmpty() {
 241                     return delegate().isEmpty();
 242                 }
 243 
 244                 @Override
 245                 public Set<String> keySet() {
 246                     return delegate().keySet();
 247                 }
 248 
 249                 @Override
 250                 public SDDocument put(String arg0, SDDocument arg1) {
 251                     return delegate().put(arg0, arg1);
 252                 }
 253 
 254                 @Override
 255                 public void putAll(
 256                         Map<? extends String, ? extends SDDocument> arg0) {
 257                     delegate().putAll(arg0);
 258                 }
 259 
 260                 @Override
 261                 public SDDocument remove(Object arg0) {
 262                     return delegate().remove(arg0);
 263                 }
 264 
 265                 @Override
 266                 public int size() {
 267                     return delegate().size();
 268                 }
 269 
 270                 @Override
 271                 public Collection<SDDocument> values() {
 272                     return delegate().values();
 273                 }
 274 
 275                 @Override
 276                 public Set<java.util.Map.Entry<String, SDDocument>> entrySet() {
 277                     return delegate().entrySet();
 278                 }
 279             };
 280 
 281             revWsdls = new AbstractMap<SDDocument, String>() {
 282                 private Map<SDDocument, String> delegate = null;
 283 
 284                 private synchronized Map<SDDocument, String> delegate() {
 285                     if (delegate != null)
 286                         return delegate;
 287 
 288                     delegate = new HashMap<SDDocument,String>();    // Doc --> wsdl=1
 289                     for (Entry<String,SDDocument> e : wsdls.entrySet()) {
 290                         if (!e.getKey().equals("WSDL")) {           // map Doc --> wsdl, not WSDL
 291                             delegate.put(e.getValue(),e.getKey());
 292                         }
 293                     }
 294 
 295                     return delegate;
 296                 }
 297 
 298                 @Override
 299                 public void clear() {
 300                     delegate().clear();
 301                 }
 302 
 303                 @Override
 304                 public boolean containsKey(Object key) {
 305                     return delegate().containsKey(key);
 306                 }
 307 
 308                 @Override
 309                 public boolean containsValue(Object value) {
 310                     return delegate().containsValue(value);
 311                 }
 312 
 313                 @Override
 314                 public Set<Entry<SDDocument, String>> entrySet() {
 315                     return delegate().entrySet();
 316                 }
 317 
 318                 @Override
 319                 public String get(Object key) {
 320                     return delegate().get(key);
 321                 }
 322 
 323                 @Override
 324                 public boolean isEmpty() {
 325                     // TODO Auto-generated method stub
 326                     return super.isEmpty();
 327                 }
 328 
 329                 @Override
 330                 public Set<SDDocument> keySet() {
 331                     return delegate().keySet();
 332                 }
 333 
 334                 @Override
 335                 public String put(SDDocument key, String value) {
 336                     return delegate().put(key, value);
 337                 }
 338 
 339                 @Override
 340                 public void putAll(Map<? extends SDDocument, ? extends String> m) {
 341                     delegate().putAll(m);
 342                 }
 343 
 344                 @Override
 345                 public String remove(Object key) {
 346                     return delegate().remove(key);
 347                 }
 348 
 349                 @Override
 350                 public int size() {
 351                     return delegate().size();
 352                 }
 353 
 354                 @Override
 355                 public Collection<String> values() {
 356                     return delegate().values();
 357                 }
 358             };
 359         }
 360     }
 361 
 362     /**
 363      * Returns the "/abc/def/ghi" portion if
 364      * the URL pattern is "/abc/def/ghi/*".
 365      */
 366     public String getValidPath() {
 367         if (urlPattern.endsWith("/*")) {
 368             return urlPattern.substring(0, urlPattern.length() - 2);
 369         } else {
 370             return urlPattern;
 371         }
 372     }
 373 
 374     @Override
 375     protected HttpToolkit createToolkit() {
 376         return new HttpToolkit();
 377     }
 378 


1111     }
1112 
1113     static {
1114         try {
1115             dump = Boolean.getBoolean(HttpAdapter.class.getName() + ".dump");
1116         } catch (SecurityException se) {
1117             if (LOGGER.isLoggable(Level.CONFIG)) {
1118                 LOGGER.log(Level.CONFIG, "Cannot read ''{0}'' property, using defaults.",
1119                         new Object[] {HttpAdapter.class.getName() + ".dump"});
1120             }
1121         }
1122         try {
1123             dump_threshold = Integer.getInteger(HttpAdapter.class.getName() + ".dumpTreshold", 4096);
1124         } catch (SecurityException se) {
1125             if (LOGGER.isLoggable(Level.CONFIG)) {
1126                 LOGGER.log(Level.CONFIG, "Cannot read ''{0}'' property, using defaults.",
1127                         new Object[] {HttpAdapter.class.getName() + ".dumpTreshold"});
1128             }
1129         }
1130         try {
1131             if (System.getProperty(HttpAdapter.class.getName() + ".publishStatusPage") != null) {
1132                 setPublishStatus(Boolean.getBoolean(HttpAdapter.class.getName() + ".publishStatusPage"));
1133             }
1134         } catch (SecurityException se) {
1135             if (LOGGER.isLoggable(Level.CONFIG)) {
1136                 LOGGER.log(Level.CONFIG, "Cannot read ''{0}'' property, using defaults.",
1137                         new Object[] {HttpAdapter.class.getName() + ".publishStatusPage"});
1138             }
1139         }
1140     }
1141 
1142     public static void setDump(boolean dumpMessages) {
1143         HttpAdapter.dump = dumpMessages;
1144     }
1145 }