Source:
<code>public String extractContentAsDocument(String version, String destination, String soapAction, String soapMessage) throws SOAPException, TransformerException, ParserConfigurationException, FileNotFoundException, UnsupportedEncodingException { MessageFactory messageFactory = null; if (version.equals(SOAP12)) { messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL); } else { messageFactory = MessageFactory.newInstance(); } SOAPMessage message = messageFactory.createMessage(); MimeHeaders mimeHeaders = message.getMimeHeaders(); <START> if (SOAP12.equals(version)) { <END> mimeHeaders.addHeader("Content-Type", "application/soap+_xml; charset=utf-8; action=\"" + soapAction+"\""); } else { mimeHeaders.setHeader("SOAPAction", soapAction); } SOAPPart soapPart = message.getSOAPPart(); String encoding = getEncoding(soapMessage); ByteArrayInputStream stream = new ByteArrayInputStream(soapMessage.getBytes(encoding)); StreamSource preppedMsgSrc = new StreamSource(stream); soapPart.setContent(preppedMsgSrc); message.saveChanges(); SOAPMessage reply = connection.call(message, destination); SOAPPart reSoapPart = reply.getSOAPPart(); if (reSoapPart != null && reSoapPart instanceof SOAPPartImpl) { ((SOAPPartImpl) reSoapPart).setSourceCharsetEncoding(encoding); } try { TransformerFactory tf = TransformerFactory.newInstance(); tf.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE); Transformer t = tf.newTransformer(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); t.transform(reSoapPart.getContent(), new StreamResult(bos)); return bos.toString(encoding); } catch (Exception e) { e.printStackTrace(); return null; } }</code><technical_language>duplicated code moved separate method</technical_language>

Target:
public String extractContentAsDocument(String version, String destination, String soapAction, String soapMessage) throws SOAPException, TransformerException, ParserConfigurationException, FileNotFoundException, UnsupportedEncodingException { MessageFactory messageFactory = null; if (version.equals(SOAP12)) { messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL); } else { messageFactory = MessageFactory.newInstance(); } SOAPMessage message = messageFactory.createMessage(); MimeHeaders mimeHeaders = message.getMimeHeaders(); setSoapAction(version, soapAction, mimeHeaders); SOAPPart soapPart = message.getSOAPPart(); String encoding = getEncoding(soapMessage); ByteArrayInputStream stream = new ByteArrayInputStream(soapMessage.getBytes(encoding)); StreamSource preppedMsgSrc = new StreamSource(stream); soapPart.setContent(preppedMsgSrc); message.saveChanges(); SOAPMessage reply = connection.call(message, destination); SOAPPart reSoapPart = reply.getSOAPPart(); if (reSoapPart != null && reSoapPart instanceof SOAPPartImpl) { ((SOAPPartImpl) reSoapPart).setSourceCharsetEncoding(encoding); } try { TransformerFactory tf = TransformerFactory.newInstance(); tf.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE); Transformer t = tf.newTransformer(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); t.transform(reSoapPart.getContent(), new StreamResult(bos)); return bos.toString(encoding); } catch (Exception e) { e.printStackTrace(); return null; } }