本文整理汇总了Java中javax.xml.ws.handler.soap.SOAPMessageContext类的典型用法代码示例。如果您正苦于以下问题:Java SOAPMessageContext类的具体用法?Java SOAPMessageContext怎么用?Java SOAPMessageContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SOAPMessageContext类属于javax.xml.ws.handler.soap包,在下文中一共展示了SOAPMessageContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleMessage
import javax.xml.ws.handler.soap.SOAPMessageContext; //导入依赖的package包/类
@Override
public boolean handleMessage(SOAPMessageContext context) {
Boolean request = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (!request) {
try {
SOAPMessage msg = context.getMessage();
SOAPEnvelope env = msg.getSOAPPart().getEnvelope();
SOAPHeader header = env.getHeader();
if (header == null) {
header = env.addHeader();
return false;
}
Node node = (Node) header.getElementsByTagName("token").item(0);
String token = node.getChildNodes().item(0).getNodeValue();
if (token != null && token.equals("Kalango Lab")) {
System.out.println("Token válido");
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
return true;
}
示例2: handleInbound
import javax.xml.ws.handler.soap.SOAPMessageContext; //导入依赖的package包/类
@Override
protected boolean handleInbound(SOAPMessageContext msgContext)
{
SOAPMessage soapMessage = msgContext.getMessage();
Iterator<?> it = soapMessage.getAttachments();
while(it.hasNext())
{
try
{
AttachmentPart attachment = (AttachmentPart)it.next();
System.out.println("Recv " + attachment.getContentType() + " attachment:");
System.out.println("'"+attachment.getContent()+"'");
return true;
}
catch (SOAPException e)
{
throw new RuntimeException("Failed to access attachment data");
}
}
throw new IllegalStateException("Missing attachment on the client side");
}
示例3: modifyAssertion
import javax.xml.ws.handler.soap.SOAPMessageContext; //导入依赖的package包/类
private void modifyAssertion(SOAPMessageContext context) throws Exception {
if (isOutboundMessage(context).booleanValue()) {
Document messageDoc = context.getMessage().getSOAPBody()
.getOwnerDocument();
String tagName = getModifyTagName(messageDoc);
if (tagName != null && tagName.length() != 0) {
NodeList nodes = messageDoc.getElementsByTagName(tagName);
if (nodes.getLength() == 0) {
throw new Exception("Can not modify SAML assertion.");
}
Node node = nodes.item(0);
removeLastCharacter(node);
}
}
}
示例4: exec
import javax.xml.ws.handler.soap.SOAPMessageContext; //导入依赖的package包/类
@Override
public void exec(SOAPMessageContext context, ModificationDetail detail)
throws SOAPException {
UpdateFieldDetail upd_detail = (UpdateFieldDetail) detail;
if (!detail.getType().equals(ModificationType.UPDATEFIELD)) {
return;
}
if (detail.getPart().equals(ModificationPart.EXCEPTION)
|| detail.getPart().equals(ModificationPart.METHOD)) {
return;
}
if (detail.getPart().equals(ModificationPart.RETURNVALUE)) {
updateForResponse(context, upd_detail);
}
if (detail.getPart().equals(ModificationPart.PARAMETER)) {
updateForRequest(context, upd_detail);
}
}
示例5: exec
import javax.xml.ws.handler.soap.SOAPMessageContext; //导入依赖的package包/类
@Override
public void exec(SOAPMessageContext soapMessageContext,
ModificationDetail detail) throws SOAPException {
if (detail instanceof UpdateDetail) {
UpdateDetail upd_detail = (UpdateDetail) detail;
if (ModificationPart.PARAMETER.equals(upd_detail.getPart())) {
renameParameter(soapMessageContext, upd_detail.getOldVariable()
.getVariableName(), upd_detail.getVariable()
.getVariableName());
} else if (ModificationPart.METHOD.equals(upd_detail.getPart())) {
if (upd_detail.isRequest()) {
renameMethod(soapMessageContext,
METHODPREFIX + upd_detail.getOldMethodName(),
METHODPREFIX + upd_detail.getNewMethodName());
} else {
renameMethod(soapMessageContext,
METHODPREFIX + upd_detail.getOldMethodName()
+ RESPONSESUFFIX,
METHODPREFIX + upd_detail.getNewMethodName()
+ RESPONSESUFFIX);
}
}
}
}
示例6: renameParameter
import javax.xml.ws.handler.soap.SOAPMessageContext; //导入依赖的package包/类
private void renameParameter(SOAPMessageContext context, String oldName,
String newName) throws SOAPException {
NodeList nodelist = context.getMessage().getSOAPBody()
.getElementsByTagName(oldName);
Node node;
if (null != nodelist) {
int size = nodelist.getLength();
for (int j = 0; j < size; j++) {
node = nodelist.item(0);
if (null != node) {
Element newNode = node.getOwnerDocument().createElement(
newName);
NodeList list = node.getChildNodes();
int childrenSize = list.getLength();
for (int i = 0; i < childrenSize; i++) {
newNode.appendChild(list.item(0));
}
node.getParentNode().replaceChild(newNode, node);
}
}
}
}
示例7: logToSystemOut
import javax.xml.ws.handler.soap.SOAPMessageContext; //导入依赖的package包/类
private void logToSystemOut(SOAPMessageContext smc) {
if (LOGGER.isDebugEnabled()) {
StringBuilder sb = new StringBuilder();
Boolean outboundProperty = (Boolean)smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (outboundProperty.booleanValue())
sb.append("Missatge SOAP enviat: ");
else
sb.append("Missatge SOAP rebut: ");
SOAPMessage message = smc.getMessage();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
message.writeTo(baos);
sb.append(baos.toString());
} catch (Exception ex) {
sb.append("Error al processar el missatge XML: " + ex.getMessage());
}
LOGGER.debug(sb.toString());
}
}
示例8: handleMessage
import javax.xml.ws.handler.soap.SOAPMessageContext; //导入依赖的package包/类
@Override
public boolean handleMessage(SOAPMessageContext c) {
SOAPMessage msg = c.getMessage();
boolean request = ((Boolean) c.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY));
try {
if (request) { // This is a request message.
// Write the message to the output stream
log.debug("Request:\n"
+ Util.documentToString(msg.getSOAPBody().getOwnerDocument()));
}
else { // This is the response message
log.debug("Response:\n"
+ Util.documentToString(msg.getSOAPBody().getOwnerDocument()));
}
}
catch (Exception e) {
log.error(e);
}
return Boolean.TRUE;
}
示例9: handleMessage
import javax.xml.ws.handler.soap.SOAPMessageContext; //导入依赖的package包/类
@Override
public boolean handleMessage(SOAPMessageContext context) {
Boolean isRequest = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (!isRequest) { // only incoming messages
try {
SOAPMessage soapMsg = context.getMessage();
SOAPEnvelope soapEnv = soapMsg.getSOAPPart().getEnvelope();
SOAPBody soapBody = soapEnv.getBody();
if (soapBody != null) {
// Should have a SOAPBody and a listall response...
NodeList nodeList = soapBody.getElementsByTagNameNS(EVENTDEF_NS, EVENTDEF_LIST_ALL_RESPONSE);
if (nodeList.getLength() > 0) { // check for listAllResponse
// tag first!
nodeList = soapBody.getElementsByTagNameNS(EVENTDEF_NS, EVENTDEF_ELEMENT);
recursiveRenamespace(nodeList); // renamespace...
soapMsg.saveChanges();
}
}
} catch (Exception e) {
catchMessages(e);
}
}
return true;
}
示例10: handleMessage
import javax.xml.ws.handler.soap.SOAPMessageContext; //导入依赖的package包/类
@Override
public boolean handleMessage(SOAPMessageContext context) {
Boolean isRequest = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (!isRequest) { // only incoming messages
try {
SOAPMessage soapMsg = context.getMessage();
SOAPEnvelope soapEnv = soapMsg.getSOAPPart().getEnvelope();
SOAPBody soapBody = soapEnv.getBody();
if (soapBody != null) {
// Should have a SOAPBody and a listall response...
NodeList nodeList = soapBody.getElementsByTagNameNS(STUDIES_NS, STUDY_LIST_ALL_RESPONSE);
if (nodeList.getLength() > 0) { // check for listAllResponse
// tag first!
nodeList = soapBody.getElementsByTagNameNS(STUDIES_NS, STUDIES_ELEMENT);
recursiveRenamespace(nodeList); // renamespace...
soapMsg.saveChanges();
}
}
} catch (Exception e) {
catchMessages(e);
}
}
return true;
}
示例11: handleMessage
import javax.xml.ws.handler.soap.SOAPMessageContext; //导入依赖的package包/类
public boolean handleMessage(SOAPMessageContext messagecontext) {
Boolean outbound = (Boolean) messagecontext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (outbound) {
try {
SOAPMessage soapMessage = messagecontext.getMessage();
SOAPBody soapBody = soapMessage.getSOAPBody();
Node firstChild = soapBody.getFirstChild();
String timeStamp = getTimestamp();
String signature = getSignature(firstChild.getLocalName(), timeStamp, secretBytes);
appendTextElement(firstChild, "Signature", signature);
appendTextElement(firstChild, "Timestamp", timeStamp);
} catch(SOAPException se) {
throw new RuntimeException("SOAPException was thrown.", se);
}
}
return true;
}
示例12: handleInbound
import javax.xml.ws.handler.soap.SOAPMessageContext; //导入依赖的package包/类
@Override
protected boolean handleInbound(SOAPMessageContext msgContext)
{
log.info("handleInbound");
try
{
SOAPMessage soapMessage = msgContext.getMessage();
SOAPBody soapBody = soapMessage.getSOAPBody();
SOAPBodyElement soapBodyElement = (SOAPBodyElement)soapBody.getChildElements().next();
SOAPElement soapElement = (SOAPElement)soapBodyElement.getChildElements().next();
String value = soapElement.getValue();
soapElement.setValue(value + "|RoutIn");
}
catch (SOAPException e)
{
throw new WebServiceException(e);
}
return true;
}
示例13: handleOutbound
import javax.xml.ws.handler.soap.SOAPMessageContext; //导入依赖的package包/类
@Override
protected boolean handleOutbound(SOAPMessageContext msgContext)
{
log.info("handleOutbound");
try
{
SOAPMessage soapMessage = msgContext.getMessage();
SOAPBody soapBody = soapMessage.getSOAPBody();
SOAPBodyElement soapBodyElement = (SOAPBodyElement)soapBody.getChildElements().next();
SOAPElement soapElement = (SOAPElement)soapBodyElement.getChildElements().next();
String value = soapElement.getValue();
soapElement.setValue(value + "|CustomOut");
}
catch (SOAPException e)
{
throw new WebServiceException(e);
}
return true;
}
示例14: verifyXOPPackage
import javax.xml.ws.handler.soap.SOAPMessageContext; //导入依赖的package包/类
private boolean verifyXOPPackage(MessageContext context)
{
try
{
SOAPMessageContext msgContext = (SOAPMessageContext)context;
SOAPMessage soapMsg = msgContext.getMessage();
SOAPEnvelope soapEnv = soapMsg.getSOAPPart().getEnvelope();
SOAPBody body = soapEnv.getBody();
boolean found = scanNodes(body.getChildNodes());
if(found) throw new IllegalStateException("XOP request not properly inlined");
}
catch (SOAPException ex)
{
throw new WebServiceException(ex);
}
return true;
}
示例15: logMessage
import javax.xml.ws.handler.soap.SOAPMessageContext; //导入依赖的package包/类
private void logMessage(SOAPMessageContext context) {
Boolean outboundProperty = (Boolean) context
.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
LOG.debug("outbound message: " + outboundProperty);
SOAPMessage soapMessage = context.getMessage();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
soapMessage.writeTo(outputStream);
} catch (Exception e) {
LOG.error("SOAP error: " + e.getMessage());
}
String message = outputStream.toString();
LOG.debug("SOAP message: " + message);
if (false == outboundProperty) {
@SuppressWarnings("unchecked")
Map<String, DataHandler> inboundMessageAttachments = (Map<String, DataHandler>) context
.get(MessageContext.INBOUND_MESSAGE_ATTACHMENTS);
Set<String> attachmentContentIds = inboundMessageAttachments
.keySet();
LOG.debug("attachment content ids: " + attachmentContentIds);
}
}