private void logMessage(String method, MessageContext context) { FileOutputStream fout = createFile(); if(fout==null) return; LogOutputStream out = new LogOutputStream(fout, true); try { out.println("<" + method + ">"); //Uncomment this statement to log the SOAP messages. out.println(logSOAPMessage(context)); out.println("</" + method + ">"); } catch (Exception ex) { ex.printStackTrace(System.out); throw new JAXRPCException("LoggingHandler: Unable to log the message in " + method + " - {" + ex.getClass().getName() + "}" + ex.getMessage()); } finally { out.flush(); out.close(); } }
public Serializer getSerializerAs(String mechanismType) throws JAXRPCException { if (javaType == String.class) { return new StringSerializer(javaType, xmlType); } return super.getSerializerAs(mechanismType); }
public FileOutputStream createFile() { FileOutputStream fout = null; try { String logfile = System.getProperty("jplag.client.logfile"); if(logfile==null || logfile.length()==0) return null; fout = new FileOutputStream(logfile, true); //append } catch (IOException ex) { ex.printStackTrace(System.out); throw new JAXRPCException("Unable to initialize the log file: " + ex.getClass().getName() + " - " + ex.getMessage()); } return fout; }
@Override public Serializer getSerializerAs(String mechanismType) throws JAXRPCException { if (javaType == String.class) { return new StringSerializer(javaType, xmlType); } return super.getSerializerAs(mechanismType); }
public boolean handleRequest(MessageContext mc) { mc.setProperty(ALLOW_FORM_OPTIMIZATION, Boolean.TRUE); try { return processMessage(mc, true); } catch (WSSecurityException e) { if (doDebug) { log.debug(e.getMessage(), e); } throw new JAXRPCException(e); } }
public boolean handleResponse(MessageContext mc) { mc.setProperty(ALLOW_FORM_OPTIMIZATION, Boolean.TRUE); try { return processMessage(mc, false); } catch (WSSecurityException e) { if (doDebug) { log.debug(e.getMessage(), e); } throw new JAXRPCException(e); } }
/** * Switch for transferring control to doReceiver and doSender */ public boolean processMessage(MessageContext mc, boolean isRequestMessage) throws WSSecurityException { RequestData reqData = new RequestData(); reqData.setMsgContext(mc); doDebug = log.isDebugEnabled(); String deployment = null; String handleFlow = null; if ((deployment = (String) getOption(DEPLOYMENT)) == null) { deployment = (String) mc.getProperty(DEPLOYMENT); } if (deployment == null) { throw new JAXRPCException("WSS4JHandler.processMessage: No deployment defined"); } if ((handleFlow = (String) getOption(FLOW)) == null) { handleFlow = (String) mc.getProperty(FLOW); } if (handleFlow == null) { handleFlow = ""; } // call doSender if we are - // (handling request and client-side deployment) or (handling response and server-side deployment). // call doReceiver if we are - // (handling request and server-side deployment) or (handling response and client-side deployment). boolean needsHandling = ( isRequestMessage && !handleFlow.equals(RESPONSE_ONLY)) || (!isRequestMessage && !handleFlow.equals(REQUEST_ONLY)); try { if (deployment.equals(CLIENT_DEPLOYMENT) ^ isRequestMessage) { if (needsHandling) { return doReceiver(mc, reqData, isRequestMessage); } } else { if (needsHandling) { return doSender(mc, reqData, isRequestMessage); } } } finally { reqData.clear(); reqData = null; } return true; }
/** * Utility method to convert SOAPMessage to org.w3c.dom.Document */ public static Document messageToDocument(SOAPMessage message) { try { Source content = message.getSOAPPart().getContent(); DocumentBuilderFactory dbf = org.apache.ws.security.util.XMLUtils.getSecuredDocumentBuilder(); DocumentBuilder builder = dbf.newDocumentBuilder(); return builder.parse(org.apache.ws.security.util.XMLUtils.sourceToInputSource(content)); } catch (Exception ex) { if (doDebug) { log.debug(ex.getMessage(), ex); } throw new JAXRPCException("messageToDocument: cannot convert SOAPMessage into Document", ex); } }
@SuppressWarnings({"unchecked"}) public HandlerChainImpl(List<HandlerInfo> handlerInfos, String[] roles) { this.roles = roles; for (int i = 0; i < handlerInfos.size(); i++) { HandlerInfo handlerInfo = handlerInfos.get(i); try { Handler handler = (Handler) handlerInfo.getHandlerClass().newInstance(); handler.init(handlerInfo); add(handler); } catch (Exception e) { throw new JAXRPCException("Unable to initialize handler class: " + handlerInfo.getHandlerClass().getName(), e); } } }