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

The following examples show how to use javax.xml.ws.handler.soap.SOAPMessageContext#getMessage() . 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: LoggingHandler.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected void logToSystemOut(SOAPMessageContext smc) {
    Boolean outboundProperty = (Boolean)smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

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

    SOAPMessage message = smc.getMessage();
    try {
        message.writeTo(out);
        //out.println();
    } catch (Exception e) {
        //out.println("Exception in handler: " + e);
        e.printStackTrace();
    }
}
 
Example 2
Source File: LoggingHandler.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected void logToSystemOut(SOAPMessageContext smc) {
    Boolean outboundProperty = (Boolean)smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

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

    SOAPMessage message = smc.getMessage();
    try {
        message.writeTo(out);
        //out.println();
    } catch (Exception e) {
        //out.println("Exception in handler: " + e);
        e.printStackTrace();
    }
}
 
Example 3
Source File: TestSOAPHandler.java    From cxf with Apache License 2.0 6 votes vote down vote up
public boolean handleFault(SOAPMessageContext ctx) {
    methodCalled("handleFault");
    printHandlerInfo("handleFault", isOutbound(ctx));

    if (isServerSideHandler()) {

        if (!"soapHandler4".equals(getHandlerId())) {
            return true;
        }

        try {
            SOAPMessage msg = ctx.getMessage();
            String fs = msg.getSOAPPart().getEnvelope().getBody().getFault().getFaultString();
            if ("soapHandler4HandleFaultThrowsRunException".equals(fs)) {
                throw new RuntimeException("soapHandler4 HandleFault throws RuntimeException");
            } else if ("soapHandler4HandleFaultThrowsSOAPFaultException".equals(fs)) {
                throw createSOAPFaultException("soapHandler4 HandleFault throws SOAPFaultException");
            }
        } catch (SOAPException e) {
            // do nothing
        }
    }

    return true;
}
 
Example 4
Source File: HarFileHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
public boolean handleOutbound(SOAPMessageContext context) {
   this.setHandler();
   SOAPMessage msg = context.getMessage();

   try {
      JsonObject request = new JsonObject();
      request.addProperty("method", "POST");
      request.addProperty("url", context.get("javax.xml.ws.service.endpoint.address").toString());
      request.addProperty("httpVersion", "HTTP/1.1");
      request.add("headers", this.handleHeaders(msg.getMimeHeaders()));
      request.add("queryString", new JsonArray());
      request.add("cookies", new JsonArray());
      request.addProperty("headersSize", -1);
      request.add("postData", this.getPostData(msg));
      request.addProperty("time", "1");
      request.addProperty("bodySize", -1);
      this.split = System.currentTimeMillis();
      this.getEntry().get("timings").getAsJsonObject().addProperty("send", this.split - this.start);
      this.getEntry().add("request", request);
   } catch (Exception var4) {
      LOG.error(var4.getMessage(), var4);
   }

   return true;
}
 
Example 5
Source File: TraceeClientHandler.java    From tracee with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected final void handleIncoming(final SOAPMessageContext context) {

		final SOAPMessage msg = context.getMessage();
		if (msg != null && traceeBackend.getConfiguration().shouldProcessContext(OutgoingRequest)) {

			try {
				final SOAPHeader header = msg.getSOAPHeader();

				if (header != null) {
					final Map<String, String> parsedContext = transportSerialization.parseSoapHeader(header);
					traceeBackend.putAll(traceeBackend.getConfiguration().filterDeniedParams(parsedContext, OutgoingRequest));
				}
			} catch (final SOAPException e) {
				logger.warn("Error during precessing of inbound soap header: " + e.getMessage());
				logger.debug("Detailed: Error during precessing of inbound soap header: {}", e.getMessage(), e);
			}
		}
	}
 
Example 6
Source File: HubDecryptionHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
private void handleDecryption(SOAPMessageContext cxt) {
   try {
      SOAPMessage soapMessage = cxt.getMessage();
      SOAPBody soapBody = soapMessage.getSOAPBody();
      if (soapBody == null) {
         SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
         soapBody = soapEnvelope.getBody();
      }

      FolderDecryptor.decryptFolder(soapBody, this.crypto);
      soapMessage.saveChanges();
   } catch (SOAPException var5) {
      LOG.error("SOAPException when handling the SOAP Body", var5);
   } catch (UnsealConnectorException var6) {
      LOG.error("UnsealConnectorException when handling the SOAP Message: " + var6.getMessage());
      throw new FolderDecryptionRuntimeException(var6.getMessage(), var6);
   } catch (TechnicalConnectorException var7) {
      LOG.error("TechnicalConnectorException when handling the SOAP Message: " + var7.getMessage());
   }

}
 
Example 7
Source File: HarFileHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
public boolean handleOutbound(SOAPMessageContext context) {
   this.setHandler();
   SOAPMessage msg = context.getMessage();

   try {
      JsonObject request = new JsonObject();
      request.addProperty("method", "POST");
      request.addProperty("url", context.get("javax.xml.ws.service.endpoint.address").toString());
      request.addProperty("httpVersion", "HTTP/1.1");
      request.add("headers", this.handleHeaders(msg.getMimeHeaders()));
      request.add("queryString", new JsonArray());
      request.add("cookies", new JsonArray());
      request.addProperty("headersSize", -1);
      request.add("postData", this.getPostData(msg));
      request.addProperty("time", "1");
      request.addProperty("bodySize", -1);
      this.split = System.currentTimeMillis();
      this.getEntry().get("timings").getAsJsonObject().addProperty("send", this.split - this.start);
      this.getEntry().add("request", request);
   } catch (Exception var4) {
      LOG.error(var4.getMessage(), var4);
   }

   return true;
}
 
Example 8
Source File: SoapActionHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
public boolean handleOutbound(SOAPMessageContext context) {
   try {
      boolean hasSoapAction = false;
      if (context.containsKey("javax.xml.ws.soap.http.soapaction.use")) {
         hasSoapAction = (Boolean)context.get("javax.xml.ws.soap.http.soapaction.use");
      }

      if (hasSoapAction) {
         String soapAction = (String)context.get("javax.xml.ws.soap.http.soapaction.uri");
         LOG.debug("Adding SOAPAction to mimeheader");
         SOAPMessage msg = context.getMessage();
         String[] headers = msg.getMimeHeaders().getHeader("SOAPAction");
         if (headers != null) {
            LOG.warn("Removing SOAPAction with values: " + ArrayUtils.toString(headers));
            msg.getMimeHeaders().removeHeader("SOAPAction");
         }

         msg.getMimeHeaders().addHeader("SOAPAction", soapAction);
         msg.saveChanges();
      }

      return true;
   } catch (SOAPException var6) {
      throw SOAPFaultFactory.newSOAPFaultException("WSSecurity problem: [SOAPACTION]" + var6.getMessage(), var6);
   }
}
 
Example 9
Source File: HubDecryptionHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
private void handleDecryption(SOAPMessageContext cxt) {
   try {
      SOAPMessage soapMessage = cxt.getMessage();
      SOAPBody soapBody = soapMessage.getSOAPBody();
      if (soapBody == null) {
         SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
         soapBody = soapEnvelope.getBody();
      }

      FolderDecryptor.decryptFolder(soapBody, this.crypto);
      soapMessage.saveChanges();
   } catch (SOAPException var5) {
      LOG.error("SOAPException when handling the SOAP Body", var5);
      throw new RuntimeException(var5);
   } catch (UnsealConnectorException var6) {
      LOG.error("UnsealConnectorException when handling the SOAP Message: " + var6.getMessage());
      throw new FolderDecryptionRuntimeException(var6.getMessage(), var6);
   } catch (TechnicalConnectorException var7) {
      LOG.error("TechnicalConnectorException when handling the SOAP Message: " + var7.getMessage());
      throw new RuntimeException(var7);
   }
}
 
Example 10
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 11
Source File: LoggingHandler.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected void logToSystemOut(SOAPMessageContext smc) {
    Boolean outboundProperty = (Boolean)
        smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

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

    SOAPMessage message = smc.getMessage();
    try {
        message.writeTo(out);
        out.println();
    } catch (Exception e) {
        out.println("Exception in handler: " + e);
    }
}
 
Example 12
Source File: TraceeServerHandler.java    From tracee with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected final void handleOutgoing(SOAPMessageContext context) {
	final SOAPMessage msg = context.getMessage();
	try {
		if (msg != null && !traceeBackend.isEmpty() && traceeBackend.getConfiguration().shouldProcessContext(OutgoingResponse)) {

			// get or create header
			final SOAPHeader header = getOrCreateHeader(msg);

			final Map<String, String> filteredContext = traceeBackend.getConfiguration().filterDeniedParams(traceeBackend.copyToMap(), OutgoingResponse);
			transportSerialization.renderSoapHeader(filteredContext, header);

			msg.saveChanges();
			context.setMessage(msg);
		}

	} catch (final SOAPException e) {
		logger.error("TraceeServerHandler : Exception occurred during processing of outbound message.");
		logger.debug("Detailed: TraceeServerHandler : Exception occurred during processing of outbound message: {}", e.getMessage(), e);
	} finally {
		// must reset tracee context
		traceeBackend.clear();
	}
}
 
Example 13
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);
   }

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

   return true;
}
 
Example 14
Source File: RequestContextHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public boolean handleInbound(SOAPMessageContext context) {
   try {
      SOAPMessage msg = context.getMessage();
      RequestContext reqContext = RequestContext.getInstance();
      this.addToRequestContext(msg, reqContext, "IN");
   } catch (SOAPException var4) {
      LOG.error("SOAPException", var4.getMessage(), var4);
   } catch (IOException var5) {
      LOG.error("IOException", var5.getMessage(), var5);
   }

   return true;
}
 
Example 15
Source File: RequestContextHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public boolean handleInbound(SOAPMessageContext context) {
   try {
      SOAPMessage msg = context.getMessage();
      RequestContext reqContext = RequestContext.getInstance();
      this.addToRequestContext(msg, reqContext, "IN");
   } catch (SOAPException var4) {
      LOG.error("SOAPException", var4.getMessage(), var4);
   } catch (IOException var5) {
      LOG.error("IOException", var5.getMessage(), var5);
   }

   return true;
}
 
Example 16
Source File: TestMustUnderstandHandler.java    From cxf with Apache License 2.0 5 votes vote down vote up
public boolean handleMessage(SOAPMessageContext ctx) {

        boolean continueProcessing = true;

        try {
            Object b = ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
            boolean outbound = (Boolean)b;
            SOAPMessage msg = ctx.getMessage();
            if (isServerSideHandler()) {
                if (outbound) {
                    QName qname = new QName("http://cxf.apache.org/mu", "MU");
                    SOAPPart soapPart = msg.getSOAPPart();
                    SOAPEnvelope envelope = soapPart.getEnvelope();
                    SOAPHeader header = envelope.getHeader();
                    if (header == null) {
                        header = envelope.addHeader();
                    }


                    SOAPHeaderElement headerElement
                        = header.addHeaderElement(envelope.createName("MU", "ns1", qname.getNamespaceURI()));

                    // QName soapMustUnderstand = new QName("http://schemas.xmlsoap.org/soap/envelope/",
                    // "mustUnderstand");
                    Name name = SOAPFactory.newInstance()
                        .createName("mustUnderstand", "soap", "http://schemas.xmlsoap.org/soap/envelope/");
                    headerElement.addAttribute(name, "1");
                } else {
                    getHandlerInfoList(ctx).add(getHandlerId());
                }
            }
        } catch (SOAPException e) {
            e.printStackTrace();
        }
        return continueProcessing;
    }
 
Example 17
Source File: LoggingHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public boolean handleInbound(SOAPMessageContext context) {
   SOAPMessage msg = context.getMessage();
   if (LOG.isInfoEnabled()) {
      String[] correlationIDs = msg.getMimeHeaders().getHeader("X-CorrelationID");
      if (ArrayUtils.isNotEmpty(correlationIDs)) {
         LOG.info("Retrieved response with X-CorrelationID [{}]", StringUtils.join(correlationIDs));
      }
   }

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

   return true;
}
 
Example 18
Source File: SoapFaultHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
/** {@inheritDoc} */
public boolean handleMessage(SOAPMessageContext c) {
	
	SOAPMessage msg = c.getMessage();

	try {
		if(getSoapFaultCode(msg) !=null){
			throw new IntegrationModuleEhealthException(I18nHelper.getLabel("error.ehealth.technical", new Object[]{getSoapFaultCode(msg)}));
		}
	} catch (SOAPException e) {
		LOG.error(e.getMessage(), e);
	}
	
	return true;
}
 
Example 19
Source File: HarFileHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public boolean handleInbound(SOAPMessageContext context) {
   this.setHandler();
   SOAPMessage msg = context.getMessage();

   try {
      String soapenv = this.getEnvelope(msg);
      JsonObject response = new JsonObject();
      response.addProperty("status", 200);
      response.addProperty("statusText", "OK");
      response.addProperty("httpVersion", "HTTP/1.1");
      response.add("headers", this.handleHeaders(msg.getMimeHeaders()));
      response.add("cookies", new JsonArray());
      JsonObject content = new JsonObject();
      content.addProperty("size", soapenv.getBytes().length);
      response.addProperty("headersSize", -1);
      response.addProperty("bodySize", -1);
      response.addProperty("redirectURL", "");
      content.addProperty("mimeType", "text/xml; charset=utf-8");
      if (msg.getMimeHeaders() != null) {
         String[] header = msg.getMimeHeaders().getHeader("Content-Type");
         if (header != null && header.length > 0) {
            content.addProperty("mimeType", header[0]);
         }
      }

      content.addProperty("text", soapenv);
      response.add("content", content);
      this.getEntry().add("response", response);
      this.getEntry().get("timings").getAsJsonObject().addProperty("wait", this.recieved - this.split);
      long end = System.currentTimeMillis();
      this.getEntry().get("timings").getAsJsonObject().addProperty("receive", end - this.recieved);
      this.getEntry().addProperty("time", end - this.start);
      this.saveHar();
   } catch (Exception var8) {
      LOG.error(var8.getMessage(), var8);
   }

   return true;
}
 
Example 20
Source File: TestSOAPHandler.java    From cxf with Apache License 2.0 4 votes vote down vote up
private boolean getReturnValue(boolean outbound, SOAPMessageContext ctx) {
    boolean ret = true;
    try {
        SOAPMessage msg = ctx.getMessage();
        SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();

        if (body.getFirstChild().getFirstChild() == null) {
            return true;
        }

        Node commandNode = body.getFirstChild().getFirstChild().getFirstChild();
        String arg = commandNode.getNodeValue();
        String namespace = body.getFirstChild().getFirstChild().getNamespaceURI();

        StringTokenizer strtok = new StringTokenizer(arg, " ");
        String hid = "";
        String direction = "";
        String command = "";
        if (strtok.countTokens() >= 3) {
            hid = strtok.nextToken();
            direction = strtok.nextToken();
            command = strtok.nextToken();
        }

        if (!getHandlerId().equals(hid)) {
            return true;
        }

        if ("stop".equals(command)) {
            if (!outbound && "inbound".equals(direction)) {
                 // remove the incoming request body.
                Document doc = body.getOwnerDocument();
                // build the SOAP response for this message
                //
                Node wrapper = doc.createElementNS(namespace, "pingResponse");
                wrapper.setPrefix("ns4");
                body.removeChild(body.getFirstChild());
                body.appendChild(wrapper);

                for (String info : getHandlerInfoList(ctx)) {
                    // copy the previously invoked handler list into the response.
                    // Ignore this handler's information as it will be added again later.
                    //
                    if (!info.contains(getHandlerId())) {
                        Node newEl = doc.createElementNS(namespace, "HandlersInfo");
                        newEl.setPrefix("ns4");
                        newEl.appendChild(doc.createTextNode(info));
                        wrapper.appendChild(newEl);
                    }
                }
                ret = false;
            } else if (outbound && "outbound".equals(direction)) {
                ret = false;
            }
        } else if ("throw".equals(command)) {
            String exceptionType = null;
            String exceptionText = "HandleMessage throws exception";
            if (strtok.hasMoreTokens()) {
                exceptionType = strtok.nextToken();
            }
            if (strtok.hasMoreTokens()) {
                exceptionText = strtok.nextToken();
            }
            if (exceptionType != null && !outbound && "inbound".equals(direction)) {
                if ("RuntimeException".equals(exceptionType)) {
                    throw new RuntimeException(exceptionText);
                } else if ("ProtocolException".equals(exceptionType)) {
                    throw new ProtocolException(exceptionText);
                } else if ("SOAPFaultException".equals(exceptionType)) {
                    throw createSOAPFaultException(exceptionText);
                } else if ("SOAPFaultExceptionWDetail".equals(exceptionType)) {
                    throw createSOAPFaultExceptionWithDetail(exceptionText);
                }
            } else if (exceptionType != null && outbound && "outbound".equals(direction)) {
                if ("RuntimeException".equals(exceptionType)) {
                    throw new RuntimeException(exceptionText);
                } else if ("ProtocolException".equals(exceptionType)) {
                    throw new ProtocolException(exceptionText);
                } else if ("SOAPFaultException".equals(exceptionType)) {
                    throw createSOAPFaultException(exceptionText);
                } else if ("SOAPFaultExceptionWDetail".equals(exceptionType)) {
                    throw createSOAPFaultExceptionWithDetail(exceptionText);
                }
            }

        }

    } catch (SOAPException e) {
        e.printStackTrace();
    }

    return ret;
}