List of usage examples for javax.xml.ws.handler.soap SOAPMessageContext put
V put(K key, V value);
From source file:be.fedict.hsm.ws.impl.JAASSOAPHandler.java
private void login(SOAPMessageContext context) throws LoginException, CertificateEncodingException { X509Certificate certificate = WSSecuritySOAPHandler.getAuthenticatedCertificate(context); byte[] encodedCertificate = certificate.getEncoded(); NamePasswordCallbackHandler usernamePasswordHandler = new NamePasswordCallbackHandler(encodedCertificate); LoginContext loginContext = new LoginContext(ApplicationClientSecurityDomain.NAME, usernamePasswordHandler); context.put(LOGIN_CONTEXT_ATTRIBUTE, loginContext); loginContext.login();// www .ja v a 2s .c o m }
From source file:be.fedict.eid.idp.protocol.ws_federation.sts.WSSecuritySoapHandler.java
private void handleInboundMessage(SOAPMessageContext context) throws SOAPException { SOAPMessage soapMessage = context.getMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); SOAPEnvelope soapEnvelope = soapPart.getEnvelope(); SOAPHeader soapHeader = soapEnvelope.getHeader(); if (null == soapHeader) { return;/* w w w . j av a 2 s.co m*/ } Iterator<SOAPHeaderElement> headerIterator = soapHeader.examineAllHeaderElements(); while (headerIterator.hasNext()) { SOAPHeaderElement soapHeaderElement = headerIterator.next(); if (false == WSTrustConstants.WS_SECURITY_NAMESPACE.equals(soapHeaderElement.getNamespaceURI())) { continue; } if (false == "Security".equals(soapHeaderElement.getLocalName())) { continue; } Iterator<SOAPElement> securityElementIterator = soapHeaderElement.getChildElements(); while (securityElementIterator.hasNext()) { SOAPElement securityElement = securityElementIterator.next(); if (false == WSTrustConstants.SAML2_NAMESPACE.equals(securityElement.getNamespaceURI())) { continue; } if (false == "Assertion".equals(securityElement.getLocalName())) { continue; } LOG.debug("putting SAML token on JAX-WS context"); context.put(SAML_TOKEN_CONTEXT_ATTRIBUTE, securityElement); context.setScope(SAML_TOKEN_CONTEXT_ATTRIBUTE, Scope.APPLICATION); } } }
From source file:be.agiv.security.handler.WSAddressingHandler.java
private void handleOutboundMessage(SOAPMessageContext context) throws SOAPException { LOG.debug("adding WS-Addressing headers"); SOAPEnvelope envelope = context.getMessage().getSOAPPart().getEnvelope(); SOAPHeader header = envelope.getHeader(); if (null == header) { header = envelope.addHeader();/*w ww.j a va 2 s. c om*/ } String wsuPrefix = null; String wsAddrPrefix = null; Iterator namespacePrefixesIter = envelope.getNamespacePrefixes(); while (namespacePrefixesIter.hasNext()) { String namespacePrefix = (String) namespacePrefixesIter.next(); String namespace = envelope.getNamespaceURI(namespacePrefix); if (WSConstants.WS_ADDR_NAMESPACE.equals(namespace)) { wsAddrPrefix = namespacePrefix; } else if (WSConstants.WS_SECURITY_UTILITY_NAMESPACE.equals(namespace)) { wsuPrefix = namespacePrefix; } } if (null == wsAddrPrefix) { wsAddrPrefix = getUniquePrefix("a", envelope); envelope.addNamespaceDeclaration(wsAddrPrefix, WSConstants.WS_ADDR_NAMESPACE); } if (null == wsuPrefix) { /* * Using "wsu" is very important for the IP-STS X509 credential. * Apparently the STS refuses when the namespace prefix of the * wsu:Id on the WS-Addressing To element is different from the * wsu:Id prefix on the WS-Security timestamp. */ wsuPrefix = "wsu"; envelope.addNamespaceDeclaration(wsuPrefix, WSConstants.WS_SECURITY_UTILITY_NAMESPACE); } SOAPFactory factory = SOAPFactory.newInstance(); SOAPHeaderElement actionHeaderElement = header .addHeaderElement(new QName(WSConstants.WS_ADDR_NAMESPACE, "Action", wsAddrPrefix)); actionHeaderElement.setMustUnderstand(true); actionHeaderElement.addTextNode(this.action); SOAPHeaderElement messageIdElement = header .addHeaderElement(new QName(WSConstants.WS_ADDR_NAMESPACE, "MessageID", wsAddrPrefix)); String messageId = "urn:uuid:" + UUID.randomUUID().toString(); context.put(MESSAGE_ID_CONTEXT_ATTRIBUTE, messageId); messageIdElement.addTextNode(messageId); SOAPHeaderElement replyToElement = header .addHeaderElement(new QName(WSConstants.WS_ADDR_NAMESPACE, "ReplyTo", wsAddrPrefix)); SOAPElement addressElement = factory.createElement("Address", wsAddrPrefix, WSConstants.WS_ADDR_NAMESPACE); addressElement.addTextNode("http://www.w3.org/2005/08/addressing/anonymous"); replyToElement.addChildElement(addressElement); SOAPHeaderElement toElement = header .addHeaderElement(new QName(WSConstants.WS_ADDR_NAMESPACE, "To", wsAddrPrefix)); toElement.setMustUnderstand(true); toElement.addTextNode(this.to); String toIdentifier = "to-id-" + UUID.randomUUID().toString(); toElement.addAttribute(new QName(WSConstants.WS_SECURITY_UTILITY_NAMESPACE, "Id", wsuPrefix), toIdentifier); try { toElement.setIdAttributeNS(WSConstants.WS_SECURITY_UTILITY_NAMESPACE, "Id", true); } catch (UnsupportedOperationException e) { // Axis2 has missing implementation of setIdAttributeNS LOG.error("error setting Id attribute: " + e.getMessage()); } context.put(TO_ID_CONTEXT_ATTRIBUTE, toIdentifier); }
From source file:com.qubit.solution.fenixedu.bennu.webservices.services.server.BennuWebServiceHandler.java
@Override public boolean handleMessage(SOAPMessageContext context) { Boolean isRequest = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); //for response message only, true for outbound messages, false for inbound if (!isRequest) { try {/*from w w w . j ava 2 s . com*/ WebServiceServerConfiguration configuration = getWebServiceServerConfiguration( ((com.sun.xml.ws.api.server.WSEndpoint) context.get("com.sun.xml.ws.api.server.WSEndpoint")) .getImplementationClass().getName()); SOAPMessage soapMsg = context.getMessage(); SOAPEnvelope soapEnv = soapMsg.getSOAPPart().getEnvelope(); SOAPHeader soapHeader = soapEnv.getHeader(); if (!configuration.isActive()) { generateSOAPErrorMessage(soapMsg, "Sorry webservice is disabled at application level!"); } if (configuration.isAuthenticatioNeeded()) { if (configuration.isUsingWSSecurity()) { if (soapHeader == null) { generateSOAPErrorMessage(soapMsg, "No header in message, unabled to validate security credentials"); } String username = null; String password = null; String nonce = null; String created = null; Iterator<SOAPElement> childElements = soapHeader.getChildElements(QNAME_WSSE_SECURITY); if (childElements.hasNext()) { SOAPElement securityElement = childElements.next(); Iterator<SOAPElement> usernameTokens = securityElement .getChildElements(QNAME_WSSE_USERNAME_TOKEN); if (usernameTokens.hasNext()) { SOAPElement usernameToken = usernameTokens.next(); username = ((SOAPElement) usernameToken.getChildElements(QNAME_WSSE_USERNAME) .next()).getValue(); password = ((SOAPElement) usernameToken.getChildElements(QNAME_WSSE_PASSWORD) .next()).getValue(); nonce = ((SOAPElement) usernameToken.getChildElements(QNAME_WSSE_NONCE).next()) .getValue(); created = ((SOAPElement) usernameToken.getChildElements(QNAME_WSSE_CREATED).next()) .getValue(); } } if (username == null || password == null || nonce == null || created == null) { generateSOAPErrorMessage(soapMsg, "Missing information, unabled to validate security credentials"); } SecurityHeader securityHeader = new SecurityHeader(configuration, username, password, nonce, created); if (!securityHeader.isValid()) { generateSOAPErrorMessage(soapMsg, "Invalid credentials"); } else { context.put(BennuWebService.SECURITY_HEADER, securityHeader); context.setScope(BennuWebService.SECURITY_HEADER, Scope.APPLICATION); } } else { com.sun.xml.ws.transport.Headers httpHeader = (Headers) context .get(MessageContext.HTTP_REQUEST_HEADERS); String username = null; String password = null; List<String> list = httpHeader.get("authorization"); if (list != null) { for (String value : list) { if (value.startsWith("Basic")) { String[] split = value.split(" "); try { String decoded = new String(Base64.decodeBase64(split[1]), "UTF-8"); String[] split2 = decoded.split(":"); if (split2.length == 2) { username = split2[0]; password = split2[1]; } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } } } if (username == null || password == null) { generateSOAPErrorMessage(soapMsg, "Missing information, unabled to validate security credentials"); } if (!configuration.validate(username, password)) { generateSOAPErrorMessage(soapMsg, "Invalid credentials"); } } } } catch (SOAPException e) { System.err.println(e); } } //continue other handler chain return true; }
From source file:be.fedict.hsm.ws.impl.WSSecuritySOAPHandler.java
private void handleInboundMessage(SOAPMessageContext context) throws WSSecurityException, SOAPException { LOG.debug("checking WS-Security header"); SOAPMessage soapMessage = context.getMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); WSSecurityEngine secEngine = new WSSecurityEngine(); Crypto crypto = new WSSecurityCrypto(); WSSConfig wssConfig = new WSSConfig(); wssConfig.setWsiBSPCompliant(true);/*from www . j a v a 2 s . c om*/ secEngine.setWssConfig(wssConfig); List<WSSecurityEngineResult> results = secEngine.processSecurityHeader(soapPart, null, null, crypto); if (null == results) { this.securityAuditGeneratorBean.webServiceAuthenticationError(); throw new SecurityException("no WS-Security results"); } WSSecurityEngineResult timeStampActionResult = WSSecurityUtil.fetchActionResult(results, WSConstants.TS); if (null == timeStampActionResult) { this.securityAuditGeneratorBean.webServiceAuthenticationError(); throw new SecurityException("no WS-Security timestamp result"); } Timestamp receivedTimestamp = (Timestamp) timeStampActionResult.get(WSSecurityEngineResult.TAG_TIMESTAMP); if (null == receivedTimestamp) { this.securityAuditGeneratorBean.webServiceAuthenticationError(); throw new SecurityException("no WS-Security timestamp"); } LOG.debug("WS-Security timestamp created: " + receivedTimestamp.getCreated()); LOG.debug("WS-Security timestamp expires: " + receivedTimestamp.getExpires()); String timeStampIdRef = "#" + receivedTimestamp.getID(); WSSecurityEngineResult bstActionResult = WSSecurityUtil.fetchActionResult(results, WSConstants.BST); if (null == bstActionResult) { this.securityAuditGeneratorBean.webServiceAuthenticationError(); throw new SecurityException("no WS-Security BinarySecurityToken"); } BinarySecurity binarySecurityToken = (BinarySecurity) bstActionResult .get(WSSecurityEngineResult.TAG_BINARY_SECURITY_TOKEN); WSSecurityEngineResult signActionResult = WSSecurityUtil.fetchActionResult(results, WSConstants.SIGN); if (null == signActionResult) { this.securityAuditGeneratorBean.webServiceAuthenticationError(); throw new SecurityException("no valid XML signature"); } String signatureMethod = (String) signActionResult.get(WSSecurityEngineResult.TAG_SIGNATURE_METHOD); LOG.debug("signature method: " + signatureMethod); if (false == "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256".equals(signatureMethod)) { this.securityAuditGeneratorBean.webServiceAuthenticationError(); throw new SecurityException("signature algo should be RSA-SHA256"); } X509Certificate certificate = (X509Certificate) signActionResult .get(WSSecurityEngineResult.TAG_X509_CERTIFICATE); LOG.debug("certificate subject: " + certificate.getSubjectX500Principal()); List<WSDataRef> wsDataRefs = (List<WSDataRef>) signActionResult .get(WSSecurityEngineResult.TAG_DATA_REF_URIS); SOAPEnvelope soapEnvelope = soapPart.getEnvelope(); SOAPBody soapBody = soapEnvelope.getBody(); String bodyIdRef = "#" + soapBody.getAttributeNS(WSU_NAMESPACE, "Id"); String bstIdRef = "#" + binarySecurityToken.getID(); boolean timestampDigested = false; boolean bodyDigested = false; boolean tokenDigested = false; for (WSDataRef wsDataRef : wsDataRefs) { String wsuId = wsDataRef.getWsuId(); LOG.debug("signed wsu:Id: " + wsuId); LOG.debug("digest algorithm: " + wsDataRef.getDigestAlgorithm()); if (false == "http://www.w3.org/2001/04/xmlenc#sha256".equals(wsDataRef.getDigestAlgorithm())) { this.securityAuditGeneratorBean.webServiceAuthenticationError(certificate); throw new SecurityException("digest algorithm should be SHA256"); } if (timeStampIdRef.equals(wsuId)) { timestampDigested = true; } else if (bodyIdRef.equals(wsuId)) { bodyDigested = true; } else if (bstIdRef.equals(wsuId)) { tokenDigested = true; } } if (false == timestampDigested) { this.securityAuditGeneratorBean.webServiceAuthenticationError(certificate); throw new SecurityException("timestamp not digested"); } if (false == bodyDigested) { this.securityAuditGeneratorBean.webServiceAuthenticationError(certificate); throw new SecurityException("SOAP Body not digested"); } if (false == tokenDigested) { this.securityAuditGeneratorBean.webServiceAuthenticationError(certificate); throw new SecurityException("BinarySecurityToken not digested"); } context.put(X509_ATTRIBUTE, certificate); }
From source file:org.apache.axis2.jaxws.context.utils.ContextUtils.java
private static void setProperty(SOAPMessageContext context, String name, Object value, boolean logMessage) { context.put(name, value); context.setScope(name, Scope.APPLICATION); if (logMessage && log.isDebugEnabled()) { log.debug(name + " :" + value); }/* ww w . j av a2 s . com*/ }
From source file:org.apache.juddi.xlt.util.LoggingHandler.java
private void registerMessage(SOAPMessageContext context) { RequestData reqData = new RequestData(getOperationName(context)); reqData.setBytesSent(0);/*from w ww . j av a 2s . c om*/ context.put(XLT_REQUEST_DATA, reqData); context.setScope(XLT_REQUEST_DATA, MessageContext.Scope.HANDLER); }
From source file:org.nuxeo.ecm.core.opencmis.bindings.NuxeoCmisAuthHandler.java
@Override public boolean handleMessage(SOAPMessageContext context) { boolean res = super.handleMessage(context); HttpServletRequest request = (HttpServletRequest) context.get(MessageContext.SERVLET_REQUEST); request.setAttribute(CmisWebServicesServlet.CMIS_VERSION, CmisVersion.CMIS_1_1); @SuppressWarnings("unchecked") Map<String, String> callContextMap = (Map<String, String>) context.get(AbstractService.CALL_CONTEXT_MAP); if (callContextMap != null) { // login to Nuxeo String username = callContextMap.get(CallContext.USERNAME); String password = callContextMap.get(CallContext.PASSWORD); try {//from www. j a va 2s .co m LoginContext loginContext = getLoginProvider().login(username, password); // store in message context, for later logout context.put(NUXEO_LOGIN_CONTEXT, loginContext); context.setScope(NUXEO_LOGIN_CONTEXT, Scope.APPLICATION); } catch (LoginException e) { throw new RuntimeException("Login failed for user '" + username + "'", e); } } return res; }
From source file:org.wso2.carbon.device.mgt.mobile.windows.api.services.enrollment.util.MessageHandler.java
/** * This method adds Timestamp for SOAP header, and adds Content-length for HTTP header for * avoiding HTTP chunking./*from w w w. j a v a 2 s . c o m*/ * * @param context - Context of the SOAP Message */ @Override public boolean handleMessage(SOAPMessageContext context) { Boolean outBoundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); if (outBoundProperty) { SOAPMessage message = context.getMessage(); SOAPHeader header = null; SOAPEnvelope envelope = null; try { header = message.getSOAPHeader(); envelope = message.getSOAPPart().getEnvelope(); } catch (SOAPException e) { Response.serverError().entity("SOAP message content cannot be read.").build(); } try { if ((header == null) && (envelope != null)) { header = envelope.addHeader(); } } catch (SOAPException e) { Response.serverError().entity("SOAP header cannot be added.").build(); } SOAPFactory soapFactory = null; try { soapFactory = SOAPFactory.newInstance(); } catch (SOAPException e) { Response.serverError().entity("Cannot get an instance of SOAP factory.").build(); } QName qNamesSecurity = new QName(PluginConstants.WS_SECURITY_TARGET_NAMESPACE, PluginConstants.CertificateEnrolment.SECURITY); SOAPHeaderElement Security = null; Name attributeName = null; try { if (header != null) { Security = header.addHeaderElement(qNamesSecurity); } if (soapFactory != null) { attributeName = soapFactory.createName(PluginConstants.CertificateEnrolment.TIMESTAMP_ID, PluginConstants.CertificateEnrolment.TIMESTAMP_U, PluginConstants.CertificateEnrolment.WSS_SECURITY_UTILITY); } } catch (SOAPException e) { Response.serverError().entity("Security header cannot be added.").build(); } QName qNameTimestamp = new QName(PluginConstants.CertificateEnrolment.WSS_SECURITY_UTILITY, PluginConstants.CertificateEnrolment.TIMESTAMP); SOAPHeaderElement timestamp = null; try { if (header != null) { timestamp = header.addHeaderElement(qNameTimestamp); timestamp.addAttribute(attributeName, PluginConstants.CertificateEnrolment.TIMESTAMP_0); } } catch (SOAPException e) { Response.serverError().entity("Exception while adding timestamp header.").build(); } DateTime dateTime = new DateTime(); DateTime expiredDateTime = dateTime.plusMinutes(VALIDITY_TIME); String createdISOTime = dateTime.toString(ISODateTimeFormat.dateTime()); String expiredISOTime = expiredDateTime.toString(ISODateTimeFormat.dateTime()); createdISOTime = createdISOTime.substring(TIMESTAMP_BEGIN_INDEX, createdISOTime.length() - TIMESTAMP_END_INDEX); createdISOTime = createdISOTime + TIME_ZONE; expiredISOTime = expiredISOTime.substring(TIMESTAMP_BEGIN_INDEX, expiredISOTime.length() - TIMESTAMP_END_INDEX); expiredISOTime = expiredISOTime + TIME_ZONE; QName qNameCreated = new QName(PluginConstants.CertificateEnrolment.WSS_SECURITY_UTILITY, PluginConstants.CertificateEnrolment.CREATED); SOAPHeaderElement SOAPHeaderCreated = null; try { if (header != null) { SOAPHeaderCreated = header.addHeaderElement(qNameCreated); SOAPHeaderCreated.addTextNode(createdISOTime); } } catch (SOAPException e) { Response.serverError().entity("Exception while creating SOAP header.").build(); } QName qNameExpires = new QName(PluginConstants.CertificateEnrolment.WSS_SECURITY_UTILITY, PluginConstants.CertificateEnrolment.EXPIRES); SOAPHeaderElement SOAPHeaderExpires = null; ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); String messageString = null; try { if (header != null) { SOAPHeaderExpires = header.addHeaderElement(qNameExpires); SOAPHeaderExpires.addTextNode(expiredISOTime); } if ((timestamp != null) && (Security != null)) { timestamp.addChildElement(SOAPHeaderCreated); timestamp.addChildElement(SOAPHeaderExpires); Security.addChildElement(timestamp); } message.saveChanges(); message.writeTo(outputStream); messageString = new String(outputStream.toByteArray(), PluginConstants.CertificateEnrolment.UTF_8); } catch (SOAPException e) { Response.serverError().entity("Exception while creating timestamp SOAP header.").build(); } catch (IOException e) { Response.serverError().entity("Exception while writing message to output stream.").build(); } Map<String, List<String>> headers = (Map<String, List<String>>) context .get(MessageContext.HTTP_REQUEST_HEADERS); headers = new HashMap<String, List<String>>(); if (messageString != null) { headers.put(PluginConstants.CONTENT_LENGTH, Arrays.asList(String.valueOf(messageString.length()))); } context.put(MessageContext.HTTP_REQUEST_HEADERS, headers); } return true; }
From source file:org.wso2.carbon.mdm.mobileservices.windowspc.services.wstep.util.MessageHandler.java
/** * This method adds Timestamp for SOAP header, and adds Content-length for HTTP header for * avoiding HTTP chunking.// ww w . j a v a 2s .c om * * @param context */ @Override public boolean handleMessage(SOAPMessageContext context) { Boolean outBoundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); if (outBoundProperty) { SOAPMessage message = context.getMessage(); SOAPHeader header = null; SOAPEnvelope envelope = null; try { header = message.getSOAPHeader(); envelope = message.getSOAPPart().getEnvelope(); } catch (SOAPException e) { Response.serverError().build(); } if (header == null) { try { header = envelope.addHeader(); } catch (SOAPException e) { Response.serverError().build(); } } SOAPFactory soapFactory = null; try { soapFactory = SOAPFactory.newInstance(); } catch (SOAPException e) { Response.serverError().build(); } QName qNamesSecurity = new QName(Constants.CertificateEnrollment.WS_SECURITY_TARGET_NAMESPACE, Constants.CertificateEnrollment.SECURITY); SOAPHeaderElement Security = null; try { Security = header.addHeaderElement(qNamesSecurity); } catch (SOAPException e) { Response.serverError().build(); } Name attributeName = null; try { attributeName = soapFactory.createName(Constants.CertificateEnrollment.TIMESTAMP_ID, Constants.CertificateEnrollment.TIMESTAMP_U, Constants.CertificateEnrollment.WSS_SECURITY_UTILITY); } catch (SOAPException e) { Response.serverError().build(); } QName qNameTimestamp = new QName(Constants.CertificateEnrollment.WSS_SECURITY_UTILITY, Constants.CertificateEnrollment.TIMESTAMP); SOAPHeaderElement timestamp = null; try { timestamp = header.addHeaderElement(qNameTimestamp); timestamp.addAttribute(attributeName, Constants.CertificateEnrollment.TIMESTAMP_0); } catch (SOAPException e) { Response.serverError().build(); } DateTime dateTime = new DateTime(); DateTime expiredDateTime = dateTime.plusMinutes(5); String createdISOTime = dateTime.toString(ISODateTimeFormat.dateTime()); String expiredISOTime = expiredDateTime.toString(ISODateTimeFormat.dateTime()); createdISOTime = createdISOTime.substring(0, createdISOTime.length() - 6); createdISOTime = createdISOTime + "Z"; expiredISOTime = expiredISOTime.substring(0, expiredISOTime.length() - 6); expiredISOTime = expiredISOTime + "Z"; QName qNameCreated = new QName(Constants.CertificateEnrollment.WSS_SECURITY_UTILITY, Constants.CertificateEnrollment.CREATED); SOAPHeaderElement SOAPHeaderCreated = null; try { SOAPHeaderCreated = header.addHeaderElement(qNameCreated); SOAPHeaderCreated.addTextNode(createdISOTime); } catch (SOAPException e) { Response.serverError().build(); } QName qNameExpires = new QName(Constants.CertificateEnrollment.WSS_SECURITY_UTILITY, Constants.CertificateEnrollment.EXPIRES); SOAPHeaderElement SOAPHeaderExpires = null; try { SOAPHeaderExpires = header.addHeaderElement(qNameExpires); SOAPHeaderExpires.addTextNode(expiredISOTime); } catch (SOAPException e) { Response.serverError().build(); } try { timestamp.addChildElement(SOAPHeaderCreated); timestamp.addChildElement(SOAPHeaderExpires); Security.addChildElement(timestamp); } catch (SOAPException e) { Response.serverError().build(); } try { message.saveChanges(); } catch (SOAPException e) { Response.serverError().build(); } ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { message.writeTo(outputStream); } catch (IOException e) { Response.serverError().build(); } catch (SOAPException e) { Response.serverError().build(); } String messageString = null; try { messageString = new String(outputStream.toByteArray(), Constants.CertificateEnrollment.UTF_8); } catch (UnsupportedEncodingException e) { Response.serverError().build(); } Map<String, List<String>> headers = (Map<String, List<String>>) context .get(MessageContext.HTTP_REQUEST_HEADERS); headers = new HashMap<String, List<String>>(); headers.put(Constants.CertificateEnrollment.CONTENT_LENGTH, Arrays.asList(String.valueOf(messageString.length()))); context.put(MessageContext.HTTP_REQUEST_HEADERS, headers); } return true; }