Java Code Examples for org.apache.cxf.message.MessageUtils#isPartialResponse()
The following examples show how to use
org.apache.cxf.message.MessageUtils#isPartialResponse() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RMSoapOutInterceptor.java From cxf with Apache License 2.0 | 6 votes |
/** * Encode the current RM properties in protocol-specific headers. * * @param message the SOAP message. * @param rmps the current RM properties. */ public static void encode(SoapMessage message, RMProperties rmps) { if (null == rmps) { return; } LOG.log(Level.FINE, "encoding RMPs in SOAP headers"); try { AddressingProperties maps = RMContextUtils.retrieveMAPs(message, false, true); ProtocolVariation protocol = ProtocolVariation.findVariant(rmps.getNamespaceURI(), maps.getNamespaceURI()); List<Header> headers = message.getHeaders(); int startSize = headers.size(); protocol.getCodec().buildHeaders(rmps, headers); if (startSize != headers.size() && MessageUtils.isPartialResponse(message)) { // make sure the response is returned as HTTP 200 and not 202 message.put(Message.RESPONSE_CODE, HttpURLConnection.HTTP_OK); } } catch (JAXBException je) { LOG.log(Level.WARNING, "SOAP_HEADER_ENCODE_FAILURE_MSG", je); } }
Example 2
Source File: PolicyVerificationOutInterceptor.java From cxf with Apache License 2.0 | 5 votes |
/** * Checks if all assertions in the chosen alternative have been asserted. * Note that although the alternative was chosen in such a way that at least all * interceptors necessary to assert the assertions are present, it is not possible * to predict if these interceptors actually have asserted their assertions. * @param message * @throws PolicyException if none of the alternatives is supported */ protected void handle(Message message) { if (MessageUtils.isPartialResponse(message)) { LOG.fine("Not verifying policies on outbound partial response."); return; } AssertionInfoMap aim = message.get(AssertionInfoMap.class); if (null == aim) { return; } getTransportAssertions(message); EffectivePolicy policy = message.get(EffectivePolicy.class); if (policy == null) { return; } // CXF-1849 Log a message at FINE level if policy verification fails // on the outbound-server side of a response try { aim.checkEffectivePolicy(policy.getPolicy()); } catch (PolicyException e) { LOG.fine("An exception was thrown when verifying that the effective policy for " + "this request was satisfied. However, this exception will not result in " + "a fault. The exception raised is: " + e.toString()); return; } LOG.fine("Verified policies for outbound message."); }
Example 3
Source File: MAPAggregatorImpl.java From cxf with Apache License 2.0 | 5 votes |
/** * Check for NONE ReplyTo value in request-response MEP * @param message the current message * @param maps the incoming MAPs */ private void checkReplyTo(Message message, AddressingProperties maps) { // if ReplyTo address is none then 202 response status is expected // However returning a fault is more appropriate for request-response MEP if (!message.getExchange().isOneWay() && !MessageUtils.isPartialResponse(message) && ContextUtils.isNoneAddress(maps.getReplyTo())) { String reason = MessageFormat.format(BUNDLE.getString("REPLYTO_NOT_SUPPORTED_MSG"), maps.getReplyTo().getAddress().getValue()); throw new SoapFault(reason, new QName(Names.WSA_NAMESPACE_NAME, Names.WSA_NONE_ADDRESS)); } }
Example 4
Source File: LocalDestination.java From cxf with Apache License 2.0 | 5 votes |
@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); }
Example 5
Source File: AbstractHTTPDestination.java From cxf with Apache License 2.0 | 5 votes |
/** * 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; }
Example 6
Source File: MessageLossSimulator.java From cxf with Apache License 2.0 | 4 votes |
public void handleMessage(Message message) throws Fault { AddressingProperties maps = RMContextUtils.retrieveMAPs(message, false, true); String action = null; if (maps != null && null != maps.getAction()) { action = maps.getAction().getValue(); } if (RMContextUtils.isRMProtocolMessage(action)) { return; } if (MessageUtils.isPartialResponse(message)) { return; } if (Boolean.TRUE.equals(message.get(RMMessageConstants.RM_RETRANSMISSION))) { return; } if (mode == 1) { // never lose return; } else if (mode == -1) { // always lose } else { // alternatively lose synchronized (this) { appMessageCount++; if (0 != (appMessageCount % 2)) { return; } } } InterceptorChain chain = message.getInterceptorChain(); ListIterator<Interceptor<? extends Message>> it = chain.getIterator(); while (it.hasNext()) { PhaseInterceptor<?> pi = (PhaseInterceptor<? extends Message>)it.next(); if (MessageSenderInterceptor.class.getName().equals(pi.getId())) { chain.remove(pi); LOG.fine("Removed MessageSenderInterceptor from interceptor chain."); break; } } message.setContent(OutputStream.class, new WrappedOutputStream(message)); message.getInterceptorChain().add(new MessageLossEndingInterceptor(throwsException)); }
Example 7
Source File: PolicyVerificationInInterceptor.java From cxf with Apache License 2.0 | 4 votes |
/** * Determines the effective policy, and checks if one of its alternatives * is supported. * * @param message * @throws PolicyException if none of the alternatives is supported */ protected void handle(Message message) { AssertionInfoMap aim = message.get(AssertionInfoMap.class); if (null == aim) { return; } Exchange exchange = message.getExchange(); BindingOperationInfo boi = exchange.getBindingOperationInfo(); if (null == boi) { LOG.fine("No binding operation info."); return; } Endpoint e = exchange.getEndpoint(); if (null == e) { LOG.fine("No endpoint."); return; } Bus bus = exchange.getBus(); PolicyEngine pe = bus.getExtension(PolicyEngine.class); if (null == pe) { return; } if (MessageUtils.isPartialResponse(message)) { LOG.fine("Not verifying policies on inbound partial response."); return; } getTransportAssertions(message); EffectivePolicy effectivePolicy = message.get(EffectivePolicy.class); if (effectivePolicy == null) { EndpointInfo ei = e.getEndpointInfo(); if (MessageUtils.isRequestor(message)) { effectivePolicy = pe.getEffectiveClientResponsePolicy(ei, boi, message); } else { effectivePolicy = pe.getEffectiveServerRequestPolicy(ei, boi, message); } } try { List<List<Assertion>> usedAlternatives = aim.checkEffectivePolicy(effectivePolicy.getPolicy()); if (usedAlternatives != null && !usedAlternatives.isEmpty() && message.getExchange() != null) { message.getExchange().put("ws-policy.validated.alternatives", usedAlternatives); } } catch (PolicyException ex) { LOG.log(Level.SEVERE, "Inbound policy verification failed: " + ex.getMessage()); //To check if there is ws addressing policy violation and throw WSA specific //exception to pass jaxws2.2 tests if (ex.getMessage().indexOf("Addressing") > -1) { throw new Fault("A required header representing a Message Addressing Property " + "is not present", LOG) .setFaultCode(new QName("http://www.w3.org/2005/08/addressing", "MessageAddressingHeaderRequired")); } throw ex; } LOG.fine("Verified policies for inbound message."); }