return new byte[0];
}
public void writeTo(MessageContext outMsgCtxt, OMOutputFormat omOutputFormat, OutputStream outputStream, boolean b) throws AxisFault {
String charSetEncoding = (String) outMsgCtxt.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
JsonWriter jsonWriter;
String msg;
try {
jsonWriter = new JsonWriter(new OutputStreamWriter(outputStream, charSetEncoding));
Object retObj = outMsgCtxt.getProperty(JsonConstant.RETURN_OBJECT);
if (outMsgCtxt.isProcessingFault()) {
OMElement element = outMsgCtxt.getEnvelope().getBody().getFirstElement();
try {
jsonWriter.beginObject();
jsonWriter.name(element.getLocalName());
jsonWriter.beginObject();
Iterator childrenIterator = element.getChildElements();
while (childrenIterator.hasNext()) {
Object next = childrenIterator.next();
OMElement omElement = (OMElement) next;
jsonWriter.name(omElement.getLocalName());
jsonWriter.value(omElement.getText());
}
jsonWriter.endObject();
jsonWriter.endObject();
jsonWriter.flush();
jsonWriter.close();
} catch (IOException e) {
throw new AxisFault("Error while processing fault code in JsonWriter");
}
} else if (retObj == null) {
OMElement element = outMsgCtxt.getEnvelope().getBody().getFirstElement();
QName elementQname = outMsgCtxt.getAxisOperation().getMessage
(WSDLConstants.MESSAGE_LABEL_OUT_VALUE).getElementQName();
ArrayList<XmlSchema> schemas = outMsgCtxt.getAxisService().getSchema();
GsonXMLStreamWriter xmlsw = new GsonXMLStreamWriter(jsonWriter,
elementQname,
schemas,
outMsgCtxt.getConfigurationContext());
try {
xmlsw.writeStartDocument();
if (b) {
element.serialize(xmlsw);
} else {
element.serializeAndConsume(xmlsw);
}
xmlsw.writeEndDocument();
} catch (XMLStreamException e) {
throw new AxisFault("Error while writing to the output stream using JsonWriter", e);
}
} else {
try {
Gson gson = new Gson();
jsonWriter.beginObject();
jsonWriter.name(JsonConstant.RESPONSE);
Type returnType = (Type) outMsgCtxt.getProperty(JsonConstant.RETURN_TYPE);
gson.toJson(retObj, returnType, jsonWriter);
jsonWriter.endObject();
jsonWriter.flush();
} catch (IOException e) {
msg = "Exception occur while writting to JsonWriter at the JsonFormatter ";
log.error(msg, e);
throw AxisFault.makeFault(e);