* This method is used to start the JAX-WS invocation of a target endpoint. It takes an
* InvocationContext, which must have a MessageContext specied for the request. Once the
* invocation is complete, the information will be stored
*/
public InvocationContext invoke(InvocationContext ic) {
MessageContext requestMsgCtx = ic.getRequestMessageContext();
String implClassName = getServiceImplClassName(requestMsgCtx);
Class implClass = loadServiceImplClass(implClassName,
requestMsgCtx.getClassLoader());
EndpointDescription endpointDesc = getEndpointDescription(requestMsgCtx, implClass);
requestMsgCtx.setEndpointDescription(endpointDesc);
/*
* TODO: review: make sure the handlers are set on the InvocationContext
* This implementation of the JAXWS runtime does not use Endpoint, which
* would normally be the place to initialize and store the handler list.
* In lieu of that, we will have to intialize and store them on the
* InvocationContext. also see the InvocationContextFactory. On the client
* side, the binding is not yet set when we call into that factory, so the
* handler list doesn't get set on the InvocationContext object there. Thus
* we gotta do it here.
*
* Since we're on the server, and there apparently is no Binding object
* anywhere to be found...
*/
if (ic.getHandlers() == null) {
ic.setHandlers(new HandlerResolverImpl(endpointDesc.getServiceDescription()).getHandlerChain(endpointDesc.getPortInfo()));
}
if (!bindingTypesMatch(requestMsgCtx, endpointDesc.getServiceDescription())) {
Protocol protocol = requestMsgCtx.getMessage().getProtocol();
// only if protocol is soap12 and MISmatches the endpoint do we halt processing
if (protocol.equals(Protocol.soap12)) {
ic.setResponseMessageContext(createMismatchFaultMsgCtx(requestMsgCtx,
"Incoming SOAP message protocol is version 1.2, but endpoint is configured for SOAP 1.1"));
return ic;
} else if (protocol.equals(Protocol.soap11)) {
// SOAP 1.1 message and SOAP 1.2 binding
// The canSupport flag indicates that we can support this scenario.
// Possible Examples of canSupport: JAXB impl binding, JAXB Provider
// Possible Example of !canSupport: Application handler usage, non-JAXB Provider
// Initially I vote to hard code this as false.
boolean canSupport = false;
if (canSupport) {
// TODO: Okay, but we need to scrub the Message create code to make sure that the response message
// is always built from the receiver protocol...not the binding protocol
} else {
ic.setResponseMessageContext(createMismatchFaultMsgCtx(requestMsgCtx,
"Incoming SOAP message protocol is version 1.1, but endpoint is configured for SOAP 1.2. This is not supported."));
return ic;
}
} else {
ic.setResponseMessageContext(createMismatchFaultMsgCtx(requestMsgCtx,
"Incoming message protocol does not match endpoint protocol."));
return ic;
}
}
MessageContext responseMsgContext = null;
try {
// Get the service instance. This will run the @PostConstruct code.
EndpointLifecycleManager elm = createEndpointlifecycleManager();
Object serviceInstance = elm.createServiceInstance(requestMsgCtx, implClass);
// The application handlers and dispatcher invoke will
// modify/destroy parts of the message. Make sure to save
// the request message if appropriate.
saveRequestMessage(requestMsgCtx);
// Invoke inbound application handlers. It's safe to use the first object on the iterator because there is
// always exactly one EndpointDescription on a server invoke
boolean success =
HandlerInvokerUtils.invokeInboundHandlers(requestMsgCtx.getMEPContext(),
ic.getHandlers(),
HandlerChainProcessor.MEP.REQUEST,
isOneWay(requestMsgCtx.getAxisMessageContext()));
if (success) {
// Dispatch to the
EndpointDispatcher dispatcher = getEndpointDispatcher(implClass, serviceInstance);
try {
responseMsgContext = dispatcher.invoke(requestMsgCtx);
} finally {
// Passed pivot point
requestMsgCtx.getMessage().setPostPivot();
}
// Invoke the outbound response handlers.
// If the message is one way, we should not invoke the response handlers. There is no response
// MessageContext since a one way invocation is considered to have a "void" return.
if (!isOneWay(requestMsgCtx.getAxisMessageContext())) {
responseMsgContext.setMEPContext(requestMsgCtx.getMEPContext());
HandlerInvokerUtils.invokeOutboundHandlers(responseMsgContext.getMEPContext(),
ic.getHandlers(),
HandlerChainProcessor.MEP.RESPONSE,
false);
}
} else
{ // the inbound handler chain must have had a problem, and we've reversed directions
responseMsgContext =
MessageContextUtils.createResponseMessageContext(requestMsgCtx);
// since we've reversed directions, the message has "become a response message" (section 9.3.2.1, footnote superscript 2)
responseMsgContext.setMessage(requestMsgCtx.getMessage());
}
} catch (Exception e) {
// TODO for now, throw it. We probably should try to make an XMLFault object and set it on the message
throw ExceptionFactory.makeWebServiceException(e);