src/share/jaxws_classes/com/sun/xml/internal/ws/client/dispatch/DispatchImpl.java

changeset 368
0989ad8c0860
parent 286
f50545b5e2f1
child 384
8f2986ff0235
     1.1 --- a/src/share/jaxws_classes/com/sun/xml/internal/ws/client/dispatch/DispatchImpl.java	Thu Apr 04 19:05:24 2013 -0700
     1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/client/dispatch/DispatchImpl.java	Tue Apr 09 14:51:13 2013 +0100
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -33,13 +33,15 @@
    1.11  import com.sun.xml.internal.ws.api.addressing.AddressingVersion;
    1.12  import com.sun.xml.internal.ws.api.addressing.WSEndpointReference;
    1.13  import com.sun.xml.internal.ws.api.client.WSPortInfo;
    1.14 +import com.sun.xml.internal.ws.api.message.AddressingUtils;
    1.15  import com.sun.xml.internal.ws.api.message.Attachment;
    1.16  import com.sun.xml.internal.ws.api.message.AttachmentSet;
    1.17  import com.sun.xml.internal.ws.api.message.Message;
    1.18  import com.sun.xml.internal.ws.api.message.Packet;
    1.19  import com.sun.xml.internal.ws.api.pipe.Fiber;
    1.20  import com.sun.xml.internal.ws.api.pipe.Tube;
    1.21 -import com.sun.xml.internal.ws.api.pipe.FiberContextSwitchInterceptor;
    1.22 +import com.sun.xml.internal.ws.api.server.Container;
    1.23 +import com.sun.xml.internal.ws.api.server.ContainerResolver;
    1.24  import com.sun.xml.internal.ws.binding.BindingImpl;
    1.25  import com.sun.xml.internal.ws.client.*;
    1.26  import com.sun.xml.internal.ws.encoding.soap.DeserializationException;
    1.27 @@ -63,8 +65,6 @@
    1.28  import javax.xml.ws.http.HTTPBinding;
    1.29  import javax.xml.ws.soap.SOAPBinding;
    1.30  import javax.xml.ws.soap.SOAPFaultException;
    1.31 -import javax.xml.ws.WebServiceClient;
    1.32 -import javax.xml.ws.WebEndpoint;
    1.33  import java.net.MalformedURLException;
    1.34  import java.net.URI;
    1.35  import java.net.URISyntaxException;
    1.36 @@ -74,11 +74,7 @@
    1.37  import java.util.List;
    1.38  import java.util.Map;
    1.39  import java.util.concurrent.Callable;
    1.40 -import java.util.concurrent.Executor;
    1.41 -import java.util.concurrent.ExecutorService;
    1.42  import java.util.concurrent.Future;
    1.43 -import java.util.concurrent.TimeUnit;
    1.44 -import java.lang.reflect.Method;
    1.45  import java.util.logging.Level;
    1.46  import java.util.logging.Logger;
    1.47  
    1.48 @@ -152,9 +148,8 @@
    1.49      }
    1.50      /**
    1.51       *
    1.52 -     * @param port    dispatch instance is associated with this wsdl port qName
    1.53 +     * @param portportInfo dispatch instance is associated with this wsdl port qName
    1.54       * @param mode    Service.mode associated with this Dispatch instance - Service.mode.MESSAGE or Service.mode.PAYLOAD
    1.55 -     * @param owner   Service that created the Dispatch
    1.56       * @param pipe    Master pipe for the pipeline
    1.57       * @param binding Binding of this Dispatch instance, current one of SOAP/HTTP or XML/HTTP
    1.58       * @param allowFaultResponseMsg A packet containing a SOAP fault message is allowed as the response to a request on this dispatch instance.
    1.59 @@ -180,14 +175,19 @@
    1.60      abstract T toReturnValue(Packet response);
    1.61  
    1.62      public final Response<T> invokeAsync(T param) {
    1.63 -        if (LOGGER.isLoggable(Level.FINE)) {
    1.64 -          dumpParam(param, "invokeAsync(T)");
    1.65 +        Container old = ContainerResolver.getDefault().enterContainer(owner.getContainer());
    1.66 +        try {
    1.67 +            if (LOGGER.isLoggable(Level.FINE)) {
    1.68 +              dumpParam(param, "invokeAsync(T)");
    1.69 +            }
    1.70 +            AsyncInvoker invoker = new DispatchAsyncInvoker(param);
    1.71 +            AsyncResponseImpl<T> ft = new AsyncResponseImpl<T>(invoker,null);
    1.72 +            invoker.setReceiver(ft);
    1.73 +            ft.run();
    1.74 +            return ft;
    1.75 +        } finally {
    1.76 +            ContainerResolver.getDefault().exitContainer(old);
    1.77          }
    1.78 -        AsyncInvoker invoker = new DispatchAsyncInvoker(param);
    1.79 -        AsyncResponseImpl<T> ft = new AsyncResponseImpl<T>(invoker,null);
    1.80 -        invoker.setReceiver(ft);
    1.81 -        ft.run();
    1.82 -        return ft;
    1.83      }
    1.84  
    1.85      private void dumpParam(T param, String method) {
    1.86 @@ -201,10 +201,10 @@
    1.87            SOAPVersion sv = DispatchImpl.this.getBinding().getSOAPVersion();
    1.88            action =
    1.89              av != null && message.getMessage() != null ?
    1.90 -              message.getMessage().getHeaders().getAction(av, sv) : null;
    1.91 +              AddressingUtils.getAction(message.getMessage().getHeaders(), av, sv) : null;
    1.92            msgId =
    1.93              av != null && message.getMessage() != null ?
    1.94 -              message.getMessage().getHeaders().getMessageID(av, sv) : null;
    1.95 +              AddressingUtils.getMessageID(message.getMessage().getHeaders(), av, sv) : null;
    1.96            LOGGER.fine("In DispatchImpl." + method + " for message with action: " + action + " and msg ID: " + msgId + " msg: " + message.getMessage());
    1.97  
    1.98            if (message.getMessage() == null) {
    1.99 @@ -214,16 +214,21 @@
   1.100        }
   1.101      }
   1.102      public final Future<?> invokeAsync(T param, AsyncHandler<T> asyncHandler) {
   1.103 -        if (LOGGER.isLoggable(Level.FINE)) {
   1.104 -          dumpParam(param, "invokeAsync(T, AsyncHandler<T>)");
   1.105 +        Container old = ContainerResolver.getDefault().enterContainer(owner.getContainer());
   1.106 +        try {
   1.107 +            if (LOGGER.isLoggable(Level.FINE)) {
   1.108 +              dumpParam(param, "invokeAsync(T, AsyncHandler<T>)");
   1.109 +            }
   1.110 +            AsyncInvoker invoker = new DispatchAsyncInvoker(param);
   1.111 +            AsyncResponseImpl<T> ft = new AsyncResponseImpl<T>(invoker,asyncHandler);
   1.112 +            invoker.setReceiver(ft);
   1.113 +            invoker.setNonNullAsyncHandlerGiven(asyncHandler != null);
   1.114 +
   1.115 +            ft.run();
   1.116 +            return ft;
   1.117 +        } finally {
   1.118 +            ContainerResolver.getDefault().exitContainer(old);
   1.119          }
   1.120 -        AsyncInvoker invoker = new DispatchAsyncInvoker(param);
   1.121 -        AsyncResponseImpl<T> ft = new AsyncResponseImpl<T>(invoker,asyncHandler);
   1.122 -        invoker.setReceiver(ft);
   1.123 -        invoker.setNonNullAsyncHandlerGiven(asyncHandler != null);
   1.124 -
   1.125 -        ft.run();
   1.126 -        return ft;
   1.127      }
   1.128  
   1.129      /**
   1.130 @@ -239,6 +244,7 @@
   1.131                      checkNullAllowed(in, rc, binding, mode);
   1.132  
   1.133                      Packet message = createPacket(in);
   1.134 +                    message.setState(Packet.State.ClientRequest);
   1.135                      resolveEndpointAddress(message, rc);
   1.136                      setProperties(message,true);
   1.137                      response = process(message,rc,receiver);
   1.138 @@ -274,32 +280,43 @@
   1.139      }
   1.140  
   1.141      public final T invoke(T in) {
   1.142 -        if (LOGGER.isLoggable(Level.FINE)) {
   1.143 -          dumpParam(in, "invoke(T)");
   1.144 +        Container old = ContainerResolver.getDefault().enterContainer(owner.getContainer());
   1.145 +        try {
   1.146 +            if (LOGGER.isLoggable(Level.FINE)) {
   1.147 +              dumpParam(in, "invoke(T)");
   1.148 +            }
   1.149 +
   1.150 +            return doInvoke(in,requestContext,this);
   1.151 +        } finally {
   1.152 +            ContainerResolver.getDefault().exitContainer(old);
   1.153          }
   1.154 -
   1.155 -        return doInvoke(in,requestContext,this);
   1.156      }
   1.157  
   1.158      public final void invokeOneWay(T in) {
   1.159 -        if (LOGGER.isLoggable(Level.FINE)) {
   1.160 -          dumpParam(in, "invokeOneWay(T)");
   1.161 -        }
   1.162 +        Container old = ContainerResolver.getDefault().enterContainer(owner.getContainer());
   1.163 +        try {
   1.164 +            if (LOGGER.isLoggable(Level.FINE)) {
   1.165 +              dumpParam(in, "invokeOneWay(T)");
   1.166 +            }
   1.167  
   1.168 -        try {
   1.169 -            checkNullAllowed(in, requestContext, binding, mode);
   1.170 +            try {
   1.171 +                checkNullAllowed(in, requestContext, binding, mode);
   1.172  
   1.173 -            Packet request = createPacket(in);
   1.174 -            setProperties(request,false);
   1.175 -            Packet response = process(request,requestContext,this);
   1.176 -        } catch(WebServiceException e){
   1.177 -            //it could be a WebServiceException or a ProtocolException
   1.178 -            throw e;
   1.179 -        } catch(Throwable e){
   1.180 -            // it could be a RuntimeException resulting due to some internal bug or
   1.181 -            // its some other exception resulting from user error, wrap it in
   1.182 -            // WebServiceException
   1.183 -            throw new WebServiceException(e);
   1.184 +                Packet request = createPacket(in);
   1.185 +                request.setState(Packet.State.ClientRequest);
   1.186 +                setProperties(request,false);
   1.187 +                process(request,requestContext,this);
   1.188 +            } catch(WebServiceException e){
   1.189 +                //it could be a WebServiceException or a ProtocolException
   1.190 +                throw e;
   1.191 +            } catch(Throwable e){
   1.192 +                // it could be a RuntimeException resulting due to some internal bug or
   1.193 +                // its some other exception resulting from user error, wrap it in
   1.194 +                // WebServiceException
   1.195 +                throw new WebServiceException(e);
   1.196 +            }
   1.197 +        } finally {
   1.198 +            ContainerResolver.getDefault().exitContainer(old);
   1.199          }
   1.200      }
   1.201  
   1.202 @@ -358,36 +375,54 @@
   1.203          return portname;
   1.204      }
   1.205  
   1.206 -    void resolveEndpointAddress(@NotNull Packet message, @NotNull RequestContext requestContext) {
   1.207 +    void resolveEndpointAddress(@NotNull final Packet message, @NotNull final RequestContext requestContext) {
   1.208 +        final boolean p = message.packetTakesPriorityOverRequestContext;
   1.209 +
   1.210          //resolve endpoint look for query parameters, pathInfo
   1.211 -        String endpoint = (String) requestContext.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
   1.212 +        String endpoint;
   1.213 +        if (p && message.endpointAddress != null) {
   1.214 +            endpoint = message.endpointAddress.toString();
   1.215 +        } else {
   1.216 +            endpoint = (String) requestContext.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
   1.217 +        }
   1.218 +        // This is existing before packetTakesPriorityOverRequestContext so leaving in place.
   1.219          if (endpoint == null)
   1.220              endpoint = message.endpointAddress.toString();
   1.221  
   1.222          String pathInfo = null;
   1.223          String queryString = null;
   1.224 -        if (requestContext.get(MessageContext.PATH_INFO) != null)
   1.225 +        if (p && message.invocationProperties.get(MessageContext.PATH_INFO) != null) {
   1.226 +            pathInfo = (String) message.invocationProperties.get(MessageContext.PATH_INFO);
   1.227 +        } else if (requestContext.get(MessageContext.PATH_INFO) != null) {
   1.228              pathInfo = (String) requestContext.get(MessageContext.PATH_INFO);
   1.229 +        }
   1.230  
   1.231 -        if (requestContext.get(MessageContext.QUERY_STRING) != null)
   1.232 +        if (p && message.invocationProperties.get(MessageContext.QUERY_STRING) != null) {
   1.233 +            queryString = (String) message.invocationProperties.get(MessageContext.QUERY_STRING);
   1.234 +        } else if (requestContext.get(MessageContext.QUERY_STRING) != null) {
   1.235              queryString = (String) requestContext.get(MessageContext.QUERY_STRING);
   1.236 +        }
   1.237  
   1.238 -
   1.239 -        String resolvedEndpoint = null;
   1.240          if (pathInfo != null || queryString != null) {
   1.241              pathInfo = checkPath(pathInfo);
   1.242              queryString = checkQuery(queryString);
   1.243              if (endpoint != null) {
   1.244                  try {
   1.245                      final URI endpointURI = new URI(endpoint);
   1.246 -                    resolvedEndpoint = resolveURI(endpointURI, pathInfo, queryString);
   1.247 +                    endpoint = resolveURI(endpointURI, pathInfo, queryString);
   1.248                  } catch (URISyntaxException e) {
   1.249                      throw new WebServiceException(DispatchMessages.INVALID_URI(endpoint));
   1.250                  }
   1.251              }
   1.252 -            requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, resolvedEndpoint);
   1.253 -            //message.endpointAddress = EndpointAddress.create(resolvedEndpoint);
   1.254          }
   1.255 +        // These two lines used to be inside the above if.  It is outside so:
   1.256 +        // - in cases where there is no setting of address on a Packet before invocation or no pathInfo/queryString
   1.257 +        //   this will just put back what it found in the requestContext - basically a noop.
   1.258 +        // - but when info is in the Packet this will update so it will get used later.
   1.259 +        // Remember - we are operating on a copied RequestContext at this point - not the sticky one in the Stub.
   1.260 +        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);
   1.261 +        // This is not necessary because a later step will copy the resolvedEndpoint put above into message.
   1.262 +        //message.endpointAddress = EndpointAddress.create(endpoint);
   1.263      }
   1.264  
   1.265      protected @NotNull String resolveURI(@NotNull URI endpointURI, @Nullable String pathInfo, @Nullable String queryString) {
   1.266 @@ -521,6 +556,7 @@
   1.267          public void do_run () {
   1.268              checkNullAllowed(param, rc, binding, mode);
   1.269              final Packet message = createPacket(param);
   1.270 +            message.setState(Packet.State.ClientRequest);
   1.271              message.nonNullAsyncHandlerGiven = this.nonNullAsyncHandlerGiven;
   1.272              resolveEndpointAddress(message, rc);
   1.273              setProperties(message,true);
   1.274 @@ -532,10 +568,10 @@
   1.275                SOAPVersion sv = DispatchImpl.this.getBinding().getSOAPVersion();
   1.276                action =
   1.277                  av != null && message.getMessage() != null ?
   1.278 -                  message.getMessage().getHeaders().getAction(av, sv) : null;
   1.279 +                  AddressingUtils.getAction(message.getMessage().getHeaders(), av, sv) : null;
   1.280                msgId =
   1.281                  av != null&& message.getMessage() != null ?
   1.282 -                  message.getMessage().getHeaders().getMessageID(av, sv) : null;
   1.283 +                  AddressingUtils.getMessageID(message.getMessage().getHeaders(), av, sv) : null;
   1.284                LOGGER.fine("In DispatchAsyncInvoker.do_run for async message with action: " + action + " and msg ID: " + msgId);
   1.285              }
   1.286  

mercurial