protected void handleResponseInternal() throws IOException { Exchange exchange = outMessage.getExchange(); int responseCode = doProcessResponseCode(); inMessage.setExchange(exchange); updateResponseHeaders(inMessage); inMessage.put(Message.RESPONSE_CODE, responseCode); if (MessageUtils.getContextualBoolean(outMessage, SET_HTTP_RESPONSE_MESSAGE, false)) { inMessage.put(HTTP_RESPONSE_MESSAGE, getResponseMessage()); in = getPartialResponse(); if (in == null || !MessageUtils.getContextualBoolean(outMessage, Message.PROCESS_ONEWAY_RESPONSE, false)) { Endpoint ep = exchange.getEndpoint(); if (null != ep && null != ep.getEndpointInfo() && null == ep.getEndpointInfo(). getProperty("org.apache.cxf.ws.addressing.MAPAggregator.decoupledDestination")) { ClientCallback cc = exchange.remove(ClientCallback.class); if (null != cc) { cc.handleResponse(null, null); exchange.put("IN_CHAIN_COMPLETE", Boolean.TRUE); exchange.setInMessage(inMessage); return;
public void setPayload(Source s) { Message message = msgContext.getWrappedMessage(); Service.Mode mode = (Service.Mode)msgContext.getWrappedMessage() .getContextualProperty(Service.Mode.class.getName()); SOAPMessage m = message.getContent(SOAPMessage.class); if (m != null && !MessageUtils.isOutbound(message)) { try { SAAJUtils.getBody(m).removeContents(); message.setContent(XMLStreamReader.class, r); } catch (Exception e) { throw new Fault(e); s = new DOMSource(msg.getSOAPPart()); } catch (Exception e) { throw new Fault(e); } else if (message instanceof XMLMessage && message.getContent(DataSource.class) != null) { throw new Fault( new org.apache.cxf.common.i18n.Message( "GETPAYLOAD_OF_DATASOURCE_NOT_VALID_XMLHTTPBINDING", LOG));
/** * Determines if the current message has no response content. * The message has no response content if either: * - the request is oneway and the current message is no partial * response or an empty partial response. * - the request is not oneway but the current message is an empty partial * response. * @param message * @return */ private boolean hasNoResponseContent(Message message) { final boolean ow = isOneWay(message); final boolean pr = MessageUtils.isPartialResponse(message); final boolean epr = MessageUtils.isEmptyPartialResponse(message); //REVISIT may need to provide an option to choose other behavior? // old behavior not suppressing any responses => ow && !pr // suppress empty responses for oneway calls => ow && (!pr || epr) // suppress additionally empty responses for decoupled twoway calls => return (ow && !pr) || epr; }
public void handleMessage(Message message) { if (!isHttpVerbSupported(message)) { return; } if (contextPropertyName != null && !MessageUtils.getContextualBoolean(message.getExchange().getInMessage(), contextPropertyName, false)) { return; } if (skipOnFault && null != message.getContent(Exception.class) || MessageUtils.getContextualBoolean(message, TRANSFORM_SKIP, false)) { return; } XMLStreamWriter writer = message.getContent(XMLStreamWriter.class); OutputStream out = message.getContent(OutputStream.class); XMLStreamWriter transformWriter = createTransformWriterIfNeeded(writer, out); if (transformWriter != null) { message.setContent(XMLStreamWriter.class, transformWriter); message.put(AbstractOutDatabindingInterceptor.DISABLE_OUTPUTSTREAM_OPTIMIZATION, Boolean.TRUE); if (MessageUtils.isRequestor(message)) { message.removeContent(OutputStream.class); message.put(OUTPUT_STREAM_HOLDER, out); message.getInterceptorChain().add(ENDING); } } }
@Override public void close(Message message) throws IOException { // set the pseudo status code if not set (REVISIT add this method in MessageUtils to be reused elsewhere?) Integer i = (Integer)message.get(Message.RESPONSE_CODE); if (i == null) { int code = ((message.getExchange().isOneWay() && !MessageUtils.isPartialResponse(message)) || MessageUtils.isEmptyPartialResponse(message)) ? 202 : 200; message.put(Message.RESPONSE_CODE, code); } if (Boolean.TRUE.equals(message.getExchange().get(LocalConduit.DIRECT_DISPATCH))) { final Exchange exchange = (Exchange)message.getExchange().get(LocalConduit.IN_EXCHANGE); MessageImpl copy = new MessageImpl(); copy.putAll(message); message.getContent(OutputStream.class).close(); CachedOutputStream stream = message.getContent(CachedOutputStream.class); message.setContent(OutputStream.class, stream); MessageImpl.copyContent(message, copy); copy.setContent(InputStream.class, stream.getInputStream()); stream.releaseTempFileHold(); if (exchange != null && exchange.getInMessage() == null) { exchange.setInMessage(copy); } conduit.getMessageObserver().onMessage(copy); return; } super.close(message); }
boolean writeAtts = MessageUtils.isTrue(message.getContextualProperty(WRITE_ATTACHMENTS)) || (message.getAttachments() != null && !message.getAttachments().isEmpty()); serializer.writeProlog(); } catch (IOException e) { throw new Fault(new org.apache.cxf.common.i18n.Message("WRITE_ATTACHMENTS", BUNDLE), e); message.setContent(AttachmentSerializer.class, serializer); message.getInterceptorChain().add(ending);
public void handleMessage(Message message) throws Fault { if (message.getExchange().get(Throwable.class) != null) { return; OutputStream os = message.getContent(OutputStream.class); String encoding = getEncoding(message); message.setContent(XMLStreamWriter.class, newXMLStreamWriter); } catch (Exception e) { throwFault(e.getMessage(), e); message.put(StaxOutInterceptor.FORCE_START_DOCUMENT, Boolean.TRUE); if (MessageUtils.getContextualBoolean(message, StaxOutInterceptor.FORCE_START_DOCUMENT, false)) { try { newXMLStreamWriter.writeStartDocument(encoding, "1.0"); } catch (XMLStreamException e) { throw new Fault(e); message.removeContent(OutputStream.class); message.getInterceptorChain().add(ending);
public void handleMessage(Message message) throws Fault { String method = (String)message.get(Message.HTTP_REQUEST_METHOD); if (LOG.isLoggable(Level.FINE)) { LOG.fine("Invoking HTTP method " + method); if (MessageUtils.getContextualBoolean(message, URIMAPPING_SKIP, false)) { return; LOG.fine("URIMappingInterceptor get operation: " + opName); BindingOperationInfo op = ServiceModelUtil.getOperation(message.getExchange(), opName); || !opName.equals(op.getName().getLocalPart())) { if (!Boolean.TRUE.equals(message.getContextualProperty(NO_VALIDATE_PARTS))) { throw new Fault(new org.apache.cxf.common.i18n.Message("NO_OPERATION_PATH", LOG, opName, message.get(Message.PATH_INFO))); message.getExchange().put(BindingOperationInfo.class, op); message.getExchange().put(BindingOperationInfo.class, op); MessageContentsList params = getParameters(message, op); message.setContent(List.class, params);
public void handleMessage(Message message) { OutputStream out = message.getContent(OutputStream.class); XMLStreamWriter writer = message.getContent(XMLStreamWriter.class); if (out == null || writer != null) { return; Object o = message.getContextualProperty(FI_ENABLED); if (!req) { if (message.getExchange().getInMessage() != null) { String s = (String)message.getExchange().getInMessage().get(Message.ACCEPT_CONTENT_TYPE); if (s != null && s.contains("fastinfoset")) { o = Boolean.TRUE; || MessageUtils.isTrue(o)) { StAXDocumentSerializer serializer = getOutput(message, out); message.setContent(XMLStreamWriter.class, serializer); serializer.writeStartDocument(); } catch (XMLStreamException e) { throw new Fault(e); message.getInterceptorChain().add(ENDING);
public void handleMessage(Message msg) { Fault fault = (Fault) msg.getContent(Exception.class); if (fault.getDetail() != null && !MessageUtils.getContextualBoolean(msg, DISABLE_FAULT_MAPPING, false)) { processFaultDetail(fault, msg); setStackTrace(fault, msg); } FaultMode faultMode = FaultMode.UNCHECKED_APPLICATION_FAULT; // Check if the raised exception is declared in the WSDL or by the JAX-RS resource Method m = msg.getExchange().get(Method.class); if (m != null) { Exception e = msg.getContent(Exception.class); for (Class<?> cl : m.getExceptionTypes()) { if (cl.isInstance(e)) { faultMode = FaultMode.CHECKED_APPLICATION_FAULT; break; } } } msg.getExchange().put(FaultMode.class, faultMode); }
@SuppressWarnings("resource") public void handleMessage(Message message) { OutputStream os = message.getContent(OutputStream.class); XMLStreamWriter xwriter = message.getContent(XMLStreamWriter.class); Writer writer = null; if (os == null) { writer = message.getContent(Writer.class); if (MessageUtils.getContextualBoolean(message, FORCE_START_DOCUMENT, false)) { xwriter.writeStartDocument(encoding, "1.0"); message.removeContent(OutputStream.class); throw new Fault(new org.apache.cxf.common.i18n.Message("STREAM_CREATE_EXC", BUNDLE), e); message.setContent(XMLStreamWriter.class, xwriter); message.getInterceptorChain().add(ENDING);
public void handleMessage(Message message) throws Fault { Document doc = (Document)message.get(WSDLGetInterceptor.DOCUMENT_HOLDER); if (doc == null) { return; } message.remove(WSDLGetInterceptor.DOCUMENT_HOLDER); XMLStreamWriter writer = message.getContent(XMLStreamWriter.class); if (writer == null) { return; } message.put(Message.CONTENT_TYPE, "text/xml"); try { StaxUtils.writeDocument(doc, writer, !MessageUtils.getContextualBoolean(message, StaxOutInterceptor.FORCE_START_DOCUMENT, false), true); } catch (XMLStreamException e) { throw new Fault(e); } } }
super.handleFault(message); Object mapProp = message.getContextualProperty("map.cxf.interceptor.fault"); if (MessageUtils.isTrue(mapProp)) { Throwable ex = message.getContent(Exception.class); if (ex instanceof Fault) { ex = ((Fault)ex).getCause(); message.removeContent(Exception.class); message.getInterceptorChain().setFaultObserver(null); if (message.getContextualProperty(FaultListener.class.getName()) == null) { message.put(FaultListener.class.getName(), new NoOpFaultListener()); Iterator<Interceptor<? extends Message>> iterator = message.getInterceptorChain().iterator(); while (iterator.hasNext()) { Interceptor<? extends Message> inInterceptor = iterator.next(); Object rootInstance = message.getExchange().remove(JAXRSUtils.ROOT_INSTANCE); Object rootProvider = message.getExchange().remove(JAXRSUtils.ROOT_PROVIDER); if (rootInstance != null && rootProvider != null) { try { ClassResourceInfo cri = (ClassResourceInfo)message.getExchange().get(JAXRSUtils.ROOT_RESOURCE_CLASS); if (cri != null) { cri.clearThreadLocalProxies();
protected void handle(Message msg) { if (!MessageUtils.isRequestor(msg)) { LOG.fine("Not a requestor."); return; Exchange exchange = msg.getExchange(); assert null != exchange; Endpoint e = exchange.getEndpoint(); if (null == e) { LOG.fine("No endpoint."); return; EndpointInfo ei = e.getEndpointInfo(); Bus bus = exchange.getBus(); PolicyEngine pe = bus.getExtension(PolicyEngine.class); if (null == pe) { Conduit conduit = exchange.getConduit(msg); LOG.fine("conduit: " + conduit); Policy p = (Policy)msg.getContextualProperty(PolicyConstants.POLICY_OVERRIDE); if (p != null) { EndpointPolicyImpl endpi = new EndpointPolicyImpl(p); msg.getInterceptorChain().add(i); LOG.log(Level.FINE, "Added interceptor of type {0}", i.getClass().getSimpleName());
private Object createMetricsContextForOperation(Message message, BindingOperationInfo boi) { Object o = boi.getProperty(MetricsContext.class.getName()); if (o == null) { List<MetricsContext> contexts = new ArrayList<>(); for (MetricsProvider p : getMetricProviders(message.getExchange().getBus())) { MetricsContext c = p.createOperationContext(message.getExchange().getEndpoint(), boi, MessageUtils.isRequestor(message), (String)message.getContextualProperty(MetricsProvider.CLIENT_ID)); if (c != null) { contexts.add(c); } if (c instanceof Closeable) { message.getExchange().getEndpoint().addCleanupHook((Closeable)c); } } if (contexts.size() == 1) { o = contexts.get(0); } else { o = contexts; } boi.setProperty(MetricsContext.class.getName(), o); } return o; }
boolean isRequestor = MessageUtils.isRequestor(message); boolean isFault = MessageUtils.isFault(message); boolean isOutbound = MessageUtils.isOutbound(message); isFault = (message.getExchange().get("org.apache.cxf.resource.operation.name") == null); if (!isFault) { Integer responseCode = (Integer) message.get(Message.RESPONSE_CODE); if (null != responseCode) { isFault = (responseCode >= 400);
BindingOperationInfo bop = ex.getBindingOperationInfo(); Method ret = bop.getProperty(ASYNC_METHOD, Method.class); if (ret == null) { JaxwsServerHandler h = ex.get(JaxwsServerHandler.class); if (h != null) { return ret; ContinuationProvider cp = ex.getInMessage().get(ContinuationProvider.class); .getContextualBoolean(ex.getInMessage(), PARTIAL_RESPONSE_SENT_PROPERTY, false); if ((cp == null) && uam.always() || decoupledEndpoints) { JaxwsServerHandler handler = new JaxwsServerHandler(null);
private Object createEndpointMetrics(Message m) { final Endpoint ep = m.getExchange().getEndpoint(); Object o = ep.get(MetricsContext.class.getName()); if (o == null) { List<MetricsContext> contexts = new ArrayList<>(); for (MetricsProvider p : getMetricProviders(m.getExchange().getBus())) { MetricsContext c = p.createEndpointContext(ep, MessageUtils.isRequestor(m), (String)m.getContextualProperty(MetricsProvider.CLIENT_ID)); if (c != null) { contexts.add(c); } if (c instanceof Closeable) { ep.addCleanupHook((Closeable)c); } } if (contexts.size() == 1) { o = contexts.get(0); } else { o = contexts; } ep.put(MetricsContext.class.getName(), o); } return o; }
Message getEffectiveMessage() { boolean isRequestor = MessageUtils.isRequestor(message); boolean isOutbound = MessageUtils.isOutbound(message); if (isRequestor) { return isOutbound ? message : message.getExchange().getOutMessage(); } return isOutbound ? message.getExchange().getInMessage() : message; }
o = createHttpHeaders(contextMessage, clazz); } else if (SecurityContext.class.isAssignableFrom(clazz)) { SecurityContext customContext = contextMessage.get(SecurityContext.class); o = customContext == null ? new SecurityContextImpl(contextMessage) : customContext; } else if (MessageContext.class.isAssignableFrom(clazz)) { o = new ResourceInfoImpl(contextMessage); } else if (ResourceContext.class.isAssignableFrom(clazz)) { o = new ResourceContextImpl(contextMessage, contextMessage.getExchange().get(OperationResourceInfo.class)); } else if (Request.class.isAssignableFrom(clazz)) { o = new RequestImpl(contextMessage); } else if (Application.class.isAssignableFrom(clazz)) { ProviderInfo<?> providerInfo = (ProviderInfo<?>)contextMessage.getExchange().getEndpoint().get(Application.class.getName()); o = providerInfo == null ? null : providerInfo.getProvider(); } else if (contextMessage != null) { if (o == null && contextMessage != null && !MessageUtils.isRequestor(contextMessage)) { o = HttpUtils.createServletResourceValue(contextMessage, clazz);