Example usage for javax.xml.soap SOAPMessage getProperty

List of usage examples for javax.xml.soap SOAPMessage getProperty

Introduction

In this page you can find the example usage for javax.xml.soap SOAPMessage getProperty.

Prototype

public Object getProperty(String property) throws SOAPException 

Source Link

Document

Retrieves value of the specified property.

Usage

From source file:com.googlecode.ddom.saaj.SOAPMessageTest.java

@Validated
@Test/*from   ww w . jav a 2  s . c om*/
public void testGetSetCharacterSetEncoding() throws Exception {
    SOAPMessage message = getFactory().createMessage();
    String encoding = "ISO-8859-15";
    message.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, encoding);
    assertEquals(encoding, message.getProperty(SOAPMessage.CHARACTER_SET_ENCODING));
}

From source file:eu.domibus.ebms3.receiver.MSHWebservice.java

@Override
@Transactional/*from   ww  w.ja v a2s  .  c om*/
public SOAPMessage invoke(final SOAPMessage request) {
    SOAPMessage responseMessage = null;

    String pmodeKey = null;
    try {
        //FIXME: use a consistent way of property exchange between JAXWS and CXF message model. This: PropertyExchangeInterceptor
        pmodeKey = (String) request.getProperty(MSHDispatcher.PMODE_KEY_CONTEXT_PROPERTY);
    } catch (SOAPException e) {
        //this error should never occur because pmode handling is done inside the in-interceptorchain
        LOG.error("Cannot find PModeKey property for incoming Message");
        assert false;
    }

    LegConfiguration legConfiguration = pModeProvider.getLegConfiguration(pmodeKey);
    String messageId = "";
    try (StringWriter sw = new StringWriter()) {
        if (MSHWebservice.LOG.isDebugEnabled()) {

            this.transformerFactory.newTransformer().transform(new DOMSource(request.getSOAPPart()),
                    new StreamResult(sw));

            MSHWebservice.LOG.debug(sw.toString());
            MSHWebservice.LOG.debug("received attachments:");
            Iterator i = request.getAttachments();
            while (i.hasNext()) {
                MSHWebservice.LOG.debug(i.next());
            }
        }
        Messaging messaging = this.getMessaging(request);
        checkCharset(messaging);

        boolean messageExists = legConfiguration.getReceptionAwareness().getDuplicateDetection()
                && this.checkDuplicate(messaging);
        if (!messageExists && !(eu.domibus.common.configuration.model.Service.PING_SERVICE
                .equals(legConfiguration.getService().getValue())
                && Action.PING_ACTION.equals(legConfiguration.getAction().getValue()))) { // ping messages are not stored/delivered
            messageId = this.persistReceivedMessage(request, legConfiguration, pmodeKey, messaging);
        }
        responseMessage = this.generateReceipt(request, legConfiguration, messageExists);

        if (!messageExists) {
            this.notifyBackends(messageId, legConfiguration);
        }

    } catch (TransformerException | SOAPException | JAXBException | IOException e) {
        throw new RuntimeException(e);
    } catch (EbMS3Exception e) {
        throw new WebServiceException(e);
    }

    return responseMessage;
}

From source file:de.drv.dsrv.spoc.web.webservice.spring.SpocMessageDispatcherServlet.java

private void createExtraErrorAndWriteResponse(final HttpServletResponse httpServletResponse,
        final String errorText)
        throws SOAPException, JAXBException, DatatypeConfigurationException, IOException {

    final MessageFactory factory = MessageFactory.newInstance();
    final SOAPMessage message = factory.createMessage();
    final SOAPBody body = message.getSOAPBody();

    final SOAPFault fault = body.addFault();
    final QName faultName = new QName(SOAPConstants.URI_NS_SOAP_ENVELOPE, FaultCode.CLIENT.toString());
    fault.setFaultCode(faultName);//w  ww . j a v  a 2 s . c o m
    fault.setFaultString(this.soapFaultString);

    final Detail detail = fault.addDetail();

    final ExtraJaxbMarshaller extraJaxbMarshaller = new ExtraJaxbMarshaller();
    final ExtraErrorReasonType reason = ExtraErrorReasonType.INVALID_REQUEST;
    final ExtraErrorType extraError = ExtraHelper.generateError(reason, this.extraErrorCode, errorText);
    extraJaxbMarshaller.marshalExtraError(extraError, detail);

    // Schreibt die SOAPMessage in einen String.
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    message.writeTo(out);
    // Das Encoding, in dem sich die Message rausschreibt, kann man als
    // Property abfragen.
    final Object encodingProperty = message.getProperty(SOAPMessage.CHARACTER_SET_ENCODING);
    String soapMessageEncoding = "UTF-8";
    if (encodingProperty != null) {
        soapMessageEncoding = encodingProperty.toString();
    }
    final String errorXml = out.toString(soapMessageEncoding);

    httpServletResponse.setStatus(HttpServletResponse.SC_OK);
    httpServletResponse.setContentType("text/xml");
    httpServletResponse.getWriter().write(errorXml);
    httpServletResponse.getWriter().flush();
    httpServletResponse.getWriter().close();
}