Java Code Examples for javax.xml.ws.handler.soap.SOAPMessageContext#get()

The following examples show how to use javax.xml.ws.handler.soap.SOAPMessageContext#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RequestContextHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
public boolean handleOutbound(SOAPMessageContext context) {
   try {
      SOAPMessage msg = context.getMessage();
      RequestContext reqContext = RequestContext.getInstance();
      reqContext.clear();
      String endPoint = (String)context.get("javax.xml.ws.service.endpoint.address");
      if (endPoint != null && !endPoint.isEmpty()) {
         reqContext.put("endpoint", endPoint);
      }

      this.addToRequestContext(msg, reqContext, "OUT");
   } catch (SOAPException var5) {
      LOG.error("SOAPException", var5.getMessage(), var5);
   } catch (IOException var6) {
      LOG.error("IOException", var6.getMessage(), var6);
   }

   return true;
}
 
Example 2
Source File: WsAddressingHandlerV200508.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
public boolean handleOutbound(SOAPMessageContext context) {
   Boolean wsAddressingUse = context.get("be.ehealth.technicalconnector.handler.WsAddressingHandlerV200508.use") == null ? Boolean.FALSE : (Boolean)context.get("be.ehealth.technicalconnector.handler.WsAddressingHandlerV200508.use");
   if (wsAddressingUse.booleanValue()) {
      try {
         WsAddressingHeader header = (WsAddressingHeader)context.get("be.ehealth.technicalconnector.handler.WsAddressingHandlerV200508");
         if (header == null) {
            LOG.warn("No WsAddressingHeader in the requestMap. Skipping the WsAddressingHandler.");
            return true;
         }

         SOAPHeader soapHeader = getSOAPHeader(context);
         this.processRequiredElements(header, soapHeader);
         this.processOptionalElements(header, soapHeader);
         context.getMessage().saveChanges();
      } catch (SOAPException var5) {
         LOG.error("Error while generating WS-Addressing header", var5);
      }
   } else {
      LOG.warn("WsAddressingHandler is configured but be.ehealth.technicalconnector.handler.WsAddressingHandlerV200508.useproperty was not present or set to FALSE.");
   }

   return true;
}
 
Example 3
Source File: WsAddressingHandlerV200508.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
public boolean handleOutbound(SOAPMessageContext context) {
   Boolean wsAddressingUse = context.get("be.ehealth.technicalconnector.handler.WsAddressingHandlerV200508.use") == null ? Boolean.FALSE : (Boolean)context.get("be.ehealth.technicalconnector.handler.WsAddressingHandlerV200508.use");
   if (wsAddressingUse) {
      try {
         WsAddressingHeader header = (WsAddressingHeader)context.get("be.ehealth.technicalconnector.handler.WsAddressingHandlerV200508");
         if (header == null) {
            LOG.warn("No WsAddressingHeader in the requestMap. Skipping the WsAddressingHandler.");
            return true;
         }

         SOAPHeader soapHeader = getSOAPHeader(context);
         this.processRequiredElements(header, soapHeader);
         this.processOptionalElements(header, soapHeader);
         context.getMessage().saveChanges();
      } catch (SOAPException var5) {
         LOG.error("Error while generating WS-Addressing header", var5);
      }
   } else {
      LOG.warn("WsAddressingHandler is configured but be.ehealth.technicalconnector.handler.WsAddressingHandlerV200508.useproperty was not present or set to FALSE.");
   }

   return true;
}
 
Example 4
Source File: MustUnderstandHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
public boolean handleMessage(SOAPMessageContext cxt) {
	Boolean outbound = (Boolean) cxt.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

	if (outbound.booleanValue()) {
		SOAPMessage message = cxt.getMessage();
		
		try {
			SOAPHeader header = message.getSOAPHeader();
			if(header != null) {
				Iterator<SOAPElement> it = header.getChildElements(WSSE);
				while(it.hasNext()) {
					SOAPElement el = (SOAPElement)it.next();
					el.removeAttributeNS(message.getSOAPPart().getEnvelope().getNamespaceURI(), "mustUnderstand");
					LOG.debug("Recipe hook: The mustunderstand in security header has succesfully been removed");
				}
				
				message.saveChanges();
			}
		} catch (SOAPException e) {
			throw SecurableSoapMessage.newSOAPFaultException("Recipe hook problem: " + e.getMessage(), e);
		}

	}

	return true;
}
 
Example 5
Source File: ReferenceParametersAddingHandler.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Override
public boolean handleMessage(SOAPMessageContext context) {
    // we are interested only in outbound messages here
    if (!(Boolean)context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)) {
        return true;
    }
    if (params == null) {
        return true;
    }
    try {
        SOAPFactory factory = SOAPFactory.newInstance();
        for (Object o : params.getAny()) {
            SOAPElement elm = factory.createElement((Element)o);
            context.getMessage().getSOAPHeader()
                    .addChildElement(SOAPFactory.newInstance().createElement(elm));
        }
    } catch (SOAPException e) {
        throw new RuntimeException(e);
    }
    return true;
}
 
Example 6
Source File: WsdlFirstServiceHandler.java    From dropwizard-jaxws with Apache License 2.0 5 votes vote down vote up
@Override
public boolean handleMessage(SOAPMessageContext context) {

    Boolean outbound = (Boolean)context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

    if (outbound) {
        log.info("WsdlFirstService server handler - outbound");
    }
    else {
        log.info("WsdlFirstService server handler - inbound");
    }

    return true;
}
 
Example 7
Source File: HubDecryptionHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public boolean handleMessage(SOAPMessageContext cxt) {
   if (cxt == null) {
      throw new IllegalArgumentException("The message cannot be handled since the SOAPMessageContext doesn't have a valid value");
   } else {
      Boolean outboundProperty = (Boolean)cxt.get("javax.xml.ws.handler.message.outbound");
      if (!outboundProperty.booleanValue()) {
         this.handleDecryption(cxt);
      }

      return true;
   }
}
 
Example 8
Source File: HubDecryptionHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public boolean handleMessage(SOAPMessageContext cxt) {
   if (cxt == null) {
      throw new IllegalArgumentException("The message cannot be handled since the SOAPMessageContext doesn't have a valid value");
   } else {
      Boolean outboundProperty = (Boolean)cxt.get("javax.xml.ws.handler.message.outbound");
      if (!outboundProperty) {
         this.handleDecryption(cxt);
      }

      return true;
   }
}
 
Example 9
Source File: HarFileHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public boolean handleFault(SOAPMessageContext ctx) {
   Boolean outbound = (Boolean)ctx.get("javax.xml.ws.handler.message.outbound");
   if (outbound) {
      return false;
   } else {
      this.handleMessage(ctx);
      return true;
   }
}
 
Example 10
Source File: ReferenceParametersAssertingHandler.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public boolean handleMessage(SOAPMessageContext context) {
    if ((Boolean)context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)) {
        return true;
    }
    if (params == null) {
        return true;
    }
    try {
        // every element in the ReferenceParametersType should be present somewhere in the headers
        for (Object exp : params.getAny()) {
            JAXBElement<?> expectedElement = (JAXBElement<?>)exp;
            boolean found = false;
            Element actualHeaderelement = DOMUtils.getFirstElement(context.getMessage().getSOAPHeader());
            while (actualHeaderelement != null) {
                if (expectedElement.getName().getLocalPart().equals(actualHeaderelement.getLocalName())
                        && expectedElement.getName().getNamespaceURI()
                        .equals(actualHeaderelement.getNamespaceURI())) {
                    found = true;
                    break;
                }
                actualHeaderelement = DOMUtils.getNextElement(actualHeaderelement);
            }
            if (!found) {
                throw new RuntimeException("Event sink should have received Reference parameter: "
                    + expectedElement.getName());
            }
        }
    } catch (SOAPException e) {
        throw new RuntimeException(e);
    }
    return true;
}
 
Example 11
Source File: JaxWSHookIT.java    From uavstack with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "unchecked", })
@Override
public boolean handleMessage(SOAPMessageContext context) {

    boolean isOut = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

    // outbound
    if (isOut == true) {
        Map<String, List<String>> headers = (Map<String, List<String>>) context
                .get(MessageContext.HTTP_REQUEST_HEADERS);

        List<String> ls = new ArrayList<String>();

        ls.add(MonitorServerUtil.getUAVClientSrc(appid));

        if (headers == null) {
            headers = new HashMap<String, List<String>>();
            context.put(MessageContext.HTTP_REQUEST_HEADERS, headers);
        }

        // when service use axis 1.4, SOAPAction header is necessary
        if (!headers.containsKey("SOAPAction")) {
            List<String> soapActionHeader = new ArrayList<String>();
            soapActionHeader.add("\"\"");
            headers.put("SOAPAction", soapActionHeader);
        }

        headers.put("UAV-Client-Src", ls);
        for (String key : this.headerMeta.keySet()) {
            headers.remove(key);
        }
        headers.putAll(this.headerMeta);
    }
    // inbound
    else {

        getTargetServer(context);
    }
    return true;
}
 
Example 12
Source File: SchemaValidatorHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
private boolean isXOPEnabled(SOAPMessageContext context) {
   boolean xopEnabled = false;
   if (context.containsKey("http://www.w3.org/2004/08/soap/features/http-optimization")) {
      xopEnabled = (Boolean) context.get("http://www.w3.org/2004/08/soap/features/http-optimization");
   }

   return xopEnabled;
}
 
Example 13
Source File: LoggingHandler.java    From juddi with Apache License 2.0 5 votes vote down vote up
private String getOperationName(SOAPMessageContext context)
{
    // service is optional :-(
    QName service = (QName) context.get(MessageContext.WSDL_SERVICE);
    if (service == null)
    {
        service = new QName("<unknown>");
    }

    // operation is optional :-(
    QName operation = (QName) context.get(MessageContext.WSDL_OPERATION);
    if (operation == null)
    {
        // operation = new QName("<unknown>");

        try
        {
            operation = new QName(context.getMessage().getSOAPBody().getFirstChild().getLocalName());
        }
        catch (SOAPException ex)
        {
            throw new RuntimeException("", ex);
        }
    }

    return service.getLocalPart() + "." + operation.getLocalPart();
}
 
Example 14
Source File: LoggingHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public boolean handleOutbound(SOAPMessageContext context) {
   SOAPMessage msg = context.getMessage();
   if (msg != null && LOG.isInfoEnabled()) {
      String endPoint = (String)context.get("javax.xml.ws.service.endpoint.address");
      String soapAction = ArrayUtils.toString(msg.getMimeHeaders().getHeader("SOAPAction"));
      LOG.info("Invoking webservice on url: [" + endPoint + "] with SOAPAction(s) " + soapAction);
      msg.getMimeHeaders().getHeader("X-CorrelationID");
   }

   if (LOG.isDebugEnabled()) {
      dumpMessage(msg, "OUT", LOG);
   }

   return true;
}
 
Example 15
Source File: VersionHandler.java    From development with Apache License 2.0 5 votes vote down vote up
/**
 * The method is invoked for normal processing of outbound messages.
 * 
 * @param context
 *            the message context.
 * @return An indication of whether handler processing should continue for
 *         the current message. Return <code>true</code> to continue
 *         processing.
 * 
 * @throws Exception
 *             Causes the JAX-WS runtime to cease fault message processing.
 **/
@Override
public boolean handleMessage(SOAPMessageContext context) {
    Boolean request_p = (Boolean) context
            .get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    if (request_p.booleanValue()) {
        try {
            SOAPMessage msg = context.getMessage();
            SOAPEnvelope env = msg.getSOAPPart().getEnvelope();
            SOAPHeader hdr = env.getHeader();
            if (hdr == null) {
                hdr = env.addHeader();
            }
            QName qname_user = new QName("http://com/auth/", "auth");
            SOAPHeaderElement helem_user = hdr.addHeaderElement(qname_user);
            helem_user.setActor(VERSION);
            if (version == null || version.trim().length() == 0) {
                helem_user.addTextNode(apiVersionInfo.getProperty(VERSION));
            } else {
                helem_user.addTextNode(version);
            }

            msg.saveChanges();
            message = soapMessage2String(msg);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return true;
}
 
Example 16
Source File: VersionHandlerCtmg.java    From development with Apache License 2.0 5 votes vote down vote up
/**
 * The method is invoked for normal processing of outbound messages.
 * 
 * @param context
 *            the message context.
 * @return An indication of whether handler processing should continue for
 *         the current message. Return <code>true</code> to continue
 *         processing.
 * 
 * @throws Exception
 *             Causes the JAX-WS runtime to cease fault message processing.
 **/
@Override
public boolean handleMessage(SOAPMessageContext context) {
    Boolean request_p = (Boolean) context
            .get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    if (request_p.booleanValue()) {
        try {
            SOAPMessage msg = context.getMessage();
            SOAPEnvelope env = msg.getSOAPPart().getEnvelope();
            SOAPHeader hdr = env.getHeader();
            if (hdr == null) {
                hdr = env.addHeader();
            }
            QName qname_user = new QName("http://com/auth/", "auth");
            SOAPHeaderElement helem_user = hdr.addHeaderElement(qname_user);
            helem_user.setActor(VERSION);
            if (version != null && version.trim().length() != 0) {
                helem_user.addTextNode(version);
            }

            msg.saveChanges();
            message = soapMessage2String(msg);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return true;
}
 
Example 17
Source File: Handler1.java    From training with MIT License 5 votes vote down vote up
public boolean handleMessage(SOAPMessageContext messageContext) {
	Boolean outboundProperty = (Boolean) messageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

	if (outboundProperty.booleanValue()) {
		System.out.println("\nOutbound message:");
	} else {
		System.out.println("\nInbound message:");
	}

	System.out.println("** Response: " + messageContext.getMessage().toString());
	return true;
}
 
Example 18
Source File: LoginHandler.java    From development with Apache License 2.0 4 votes vote down vote up
protected void addPrincipal(SOAPMessageContext context, String userKey) {
    Subject sub = (Subject) context.get(MessageConstants.AUTH_SUBJECT);
    sub.getPrincipals().add(new PrincipalImpl(userKey));
}
 
Example 19
Source File: SimpleSecurityHandler.java    From onvif with Apache License 2.0 4 votes vote down vote up
@Override
public boolean handleMessage(final SOAPMessageContext msgCtx) {
  // System.out.println("SimpleSecurityHandler");

  // Indicator telling us which direction this message is going in
  final Boolean outInd = (Boolean) msgCtx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

  // Handler must only add security headers to outbound messages
  if (outInd.booleanValue()) {
    try {
      // Create the xml
      SOAPMessage soapMessage = msgCtx.getMessage();
      SOAPEnvelope envelope = soapMessage.getSOAPPart().getEnvelope();
      SOAPHeader header = envelope.getHeader();
      if (header == null) header = envelope.addHeader();

      SOAPPart sp = soapMessage.getSOAPPart();
      SOAPEnvelope se = sp.getEnvelope();
      se.addNamespaceDeclaration(WSSE_PREFIX, WSSE_NS);
      se.addNamespaceDeclaration(WSU_PREFIX, WSU_NS);

      SOAPElement securityElem = header.addChildElement(WSSE_LN, WSSE_PREFIX);
      // securityElem.setAttribute("SOAP-ENV:mustUnderstand", "1");

      SOAPElement usernameTokenElem =
          securityElem.addChildElement(USERNAME_TOKEN_LN, WSSE_PREFIX);

      SOAPElement usernameElem = usernameTokenElem.addChildElement(USERNAME_LN, WSSE_PREFIX);
      usernameElem.setTextContent(username);

      SOAPElement passwordElem = usernameTokenElem.addChildElement(PASSWORD_LN, WSSE_PREFIX);
      passwordElem.setAttribute(PASSWORD_TYPE_ATTR, PASSWORD_DIGEST);
      passwordElem.setTextContent(encryptPassword(password));

      SOAPElement nonceElem = usernameTokenElem.addChildElement(NONCE_LN, WSSE_PREFIX);
      nonceElem.setAttribute("EncodingType", BASE64_ENCODING);
      nonceElem.setTextContent(Base64.encodeBase64String(nonce.getBytes()));

      SOAPElement createdElem = usernameTokenElem.addChildElement(CREATED_LN, WSU_PREFIX);
      createdElem.setTextContent(getLastUTCTime());
    } catch (final Exception e) {
      e.printStackTrace();
      return false;
    }
  }
  return true;
}
 
Example 20
Source File: WssHelper.java    From vsphere-automation-sdk-java with MIT License 2 votes vote down vote up
/**
 * Returns true if the {@link SOAPMessageContext} is part of the request
 *
 * @param smc
 * @return
 */
public static boolean isOutgoingMessage(SOAPMessageContext smc) {
    Boolean outboundProperty = (Boolean) smc.get(
        MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    return outboundProperty.booleanValue();
}