/** * Write the SOAP 1.2. envelope element * * @throws XMLStreamException If an error occurs when writing to {@link OutputStream} If an error occurs when * writing to {@link OutputStream} * @throws EncodingException If an encoding error occurs */ protected void writeSoapEnvelope() throws XMLStreamException, EncodingException { start(SoapConstants.SOAP_12_ENVELOPE); namespace(W3CConstants.NS_XLINK_PREFIX, W3CConstants.NS_XLINK); namespace(SoapConstants.NS_SOAP_PREFIX, SoapConstants.NS_SOAP_12); schemaLocation(getSchemaLocation()); // writeSoapHeader() writeSoapBody(); end(SoapConstants.SOAP_12_ENVELOPE); }
@Override public void write() throws EncodingException, XMLStreamException { start(); writeSoapEnvelope(); end(); finish(); }
/** * Encode and write SOAP 1.2 fault element to SOAP 1.2 body element * * @param fault Service internal SOAP fault representation * * @throws EncodingException If an encoding error occurs * @throws XMLStreamException If an error occurs when writing to {@link OutputStream} */ protected void writeSoapFault(SoapFault fault) throws EncodingException, XMLStreamException { Encoder<XmlObject, SoapFault> encoder = getEncoder(SoapConstants.NS_SOAP_12, fault); String soapFault = encoder.encode(fault).xmlText(getXmlOptions()); rawText(stripXmlDeclaration(soapFault)); }
/** * Write the SOAP 1.2 body element * * @throws XMLStreamException If an error occurs when writing to {@link OutputStream} * @throws EncodingException If an encoding error occurs */ protected void writeSoapBody() throws XMLStreamException, EncodingException { start(SoapConstants.SOAP_12_BODY); SoapResponse response = getElement(); if (response != null) { if (response.isSetSoapFault()) { writeSoapFault(response.getSoapFault()); } else if (response.hasException()) { writeSoapFaultFromException(response.getException()); } else if (response.isSetBodyContent()) { writeBodyContent(response.getBodyContent()); } } end(SoapConstants.SOAP_12_BODY); }
/** * Encode and write the {@link OwsServiceResponse} to stream * * @param bodyResponse The service internal response to encode and write * * @throws XMLStreamException If an error occurs when writing to {@link OutputStream} * @throws EncodingException If an encoding error occurs */ @SuppressWarnings({ "rawtypes", "unchecked" }) protected void writeBodyContent(OwsServiceResponse bodyResponse) throws XMLStreamException, EncodingException { Encoder<Object, OwsServiceResponse> encoder = getEncoder( new OperationResponseEncoderKey( new OwsOperationKey(bodyResponse), MediaTypes.APPLICATION_XML)); if (encoder instanceof StreamingEncoder<?, ?>) { EncodingContext ctx = getContext() .with(XmlBeansEncodingFlags.DOCUMENT) .without(XmlBeansEncodingFlags.PROPERTY_TYPE) .without(XmlBeansEncodingFlags.TYPE) .with(StreamingEncoderFlags.EMBEDDED, true); ((StreamingEncoder) encoder).encode(bodyResponse, getOutputStream(), ctx); } else { String soapBodyContent = ((XmlObject) encoder.encode(bodyResponse)).xmlText(getXmlOptions()); rawText(stripXmlDeclaration(soapBodyContent)); } }
protected Set<SchemaLocation> getSchemaLocation() throws EncodingException, XMLStreamException { SoapResponse response = getElement(); Set<SchemaLocation> schemaLocations = Sets.newHashSet(); schemaLocations.add(SoapConstants.SOAP_12_SCHEMA_LOCATION); if (response.isSetBodyContent()) { Encoder<Object, OwsServiceResponse> encoder = getEncoder(response.getBodyContent()); if (encoder != null && encoder instanceof SchemaAwareEncoder) { schemaLocations.addAll(((SchemaAwareEncoder<?, ?>) encoder).getSchemaLocations()); } } return schemaLocations; }
protected Encoder<Object, OwsServiceResponse> getEncoder(OwsServiceResponse abstractServiceResponse) throws NoEncoderForKeyException { return getEncoder(new OperationResponseEncoderKey(new OwsOperationKey(abstractServiceResponse), MediaTypes.APPLICATION_XML)); }
/** * Write the SOAP 1.2 body element * * @throws XMLStreamException If an error occurs when writing to {@link OutputStream} * @throws EncodingException If an encoding error occurs */ protected void writeSoapBody() throws XMLStreamException, EncodingException { start(SoapConstants.SOAP_12_BODY); SoapResponse response = getElement(); if (response != null) { if (response.isSetSoapFault()) { writeSoapFault(response.getSoapFault()); } else if (response.hasException()) { writeSoapFaultFromException(response.getException()); } else if (response.isSetBodyContent()) { writeBodyContent(response.getBodyContent()); } } end(SoapConstants.SOAP_12_BODY); }
/** * Encode and write the {@link OwsServiceResponse} to stream * * @param bodyResponse The service internal response to encode and write * * @throws XMLStreamException If an error occurs when writing to {@link OutputStream} * @throws EncodingException If an encoding error occurs */ @SuppressWarnings({ "rawtypes", "unchecked" }) protected void writeBodyContent(OwsServiceResponse bodyResponse) throws XMLStreamException, EncodingException { Encoder<Object, OwsServiceResponse> encoder = getEncoder( new OperationResponseEncoderKey( new OwsOperationKey(bodyResponse), MediaTypes.APPLICATION_XML)); if (encoder instanceof StreamingEncoder<?, ?>) { EncodingContext ctx = getContext() .with(XmlBeansEncodingFlags.DOCUMENT) .without(XmlBeansEncodingFlags.PROPERTY_TYPE) .without(XmlBeansEncodingFlags.TYPE) .with(StreamingEncoderFlags.EMBEDDED, true); ((StreamingEncoder) encoder).encode(bodyResponse, getOutputStream(), ctx); } else { String soapBodyContent = ((XmlObject) encoder.encode(bodyResponse)).xmlText(getXmlOptions()); rawText(stripXmlDeclaration(soapBodyContent)); } }
protected Set<SchemaLocation> getSchemaLocation() throws EncodingException, XMLStreamException { SoapResponse response = getElement(); Set<SchemaLocation> schemaLocations = Sets.newHashSet(); schemaLocations.add(SoapConstants.SOAP_12_SCHEMA_LOCATION); if (response.isSetBodyContent()) { Encoder<Object, OwsServiceResponse> encoder = getEncoder(response.getBodyContent()); if (encoder != null && encoder instanceof SchemaAwareEncoder) { schemaLocations.addAll(((SchemaAwareEncoder<?, ?>) encoder).getSchemaLocations()); } } return schemaLocations; }
protected Encoder<Object, OwsServiceResponse> getEncoder(OwsServiceResponse abstractServiceResponse) throws NoEncoderForKeyException { return getEncoder(new OperationResponseEncoderKey(new OwsOperationKey(abstractServiceResponse), MediaTypes.APPLICATION_XML)); }
/** * Write the SOAP 1.2. envelope element * * @throws XMLStreamException If an error occurs when writing to {@link OutputStream} If an error occurs when * writing to {@link OutputStream} * @throws EncodingException If an encoding error occurs */ protected void writeSoapEnvelope() throws XMLStreamException, EncodingException { start(SoapConstants.SOAP_12_ENVELOPE); namespace(W3CConstants.NS_XLINK_PREFIX, W3CConstants.NS_XLINK); namespace(SoapConstants.NS_SOAP_PREFIX, SoapConstants.NS_SOAP_12); schemaLocation(getSchemaLocation()); // writeSoapHeader() writeSoapBody(); end(SoapConstants.SOAP_12_ENVELOPE); }
/** * Encode and write {@link OwsExceptionReport} element to SOAP 1.2 body element * * @param exception Service internal {@link OwsExceptionReport} * * @throws EncodingException If an encoding error occurs * @throws XMLStreamException If an error occurs when writing to {@link OutputStream} */ protected void writeSoapFaultFromException(OwsExceptionReport exception) throws EncodingException, XMLStreamException { Encoder<XmlObject, OwsExceptionReport> encoder = getEncoder(SoapConstants.NS_SOAP_12, exception); String soapFault = encoder.encode(exception).xmlText(getXmlOptions()); rawText(stripXmlDeclaration(soapFault)); }
@Override public void write() throws EncodingException, XMLStreamException { start(); writeSoapEnvelope(); end(); finish(); }
/** * Encode and write SOAP 1.2 fault element to SOAP 1.2 body element * * @param fault Service internal SOAP fault representation * * @throws EncodingException If an encoding error occurs * @throws XMLStreamException If an error occurs when writing to {@link OutputStream} */ protected void writeSoapFault(SoapFault fault) throws EncodingException, XMLStreamException { Encoder<XmlObject, SoapFault> encoder = getEncoder(SoapConstants.NS_SOAP_12, fault); String soapFault = encoder.encode(fault).xmlText(getXmlOptions()); rawText(stripXmlDeclaration(soapFault)); }
/** * Encode and write {@link OwsExceptionReport} element to SOAP 1.2 body element * * @param exception Service internal {@link OwsExceptionReport} * * @throws EncodingException If an encoding error occurs * @throws XMLStreamException If an error occurs when writing to {@link OutputStream} */ protected void writeSoapFaultFromException(OwsExceptionReport exception) throws EncodingException, XMLStreamException { Encoder<XmlObject, OwsExceptionReport> encoder = getEncoder(SoapConstants.NS_SOAP_12, exception); String soapFault = encoder.encode(exception).xmlText(getXmlOptions()); rawText(stripXmlDeclaration(soapFault)); }