Java 类javax.xml.rpc.handler.soap.SOAPMessageContext 实例源码

项目:jplag    文件:LoggingHandler.java   
private String logSOAPMessage(MessageContext context) {
        StringBuffer stringBuffer = new StringBuffer();
        SOAPMessageContext smc = (SOAPMessageContext) context;
        SOAPMessage soapMessage = smc.getMessage();
/*      try
        {
            SOAPBody soapBody = soapMessage.getSOAPBody();
            NodeList list=soapBody.getElementsByTagName("inputZipFile");
        }
        catch(Exception e)
        {
            // ignore filtering
        }*/

        ByteArrayOutputStream bout= new ByteArrayOutputStream();
        try {
            soapMessage.writeTo(bout);
        } catch(Exception e) {
            e.printStackTrace(System.out);
        }
        stringBuffer.append(bout.toString() + "\n");

        return stringBuffer.toString();
    }
项目:jplag    文件:JPlagClientAccessHandler.java   
/**
 * Adds an "Access" element to the SOAP header
 */
public boolean handleRequest(MessageContext msgct) {
    if (msgct instanceof SOAPMessageContext) {
        SOAPMessageContext smsgct = (SOAPMessageContext) msgct;
        try {
            SOAPMessage msg = smsgct.getMessage();
            SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
            SOAPHeader header = msg.getSOAPHeader();

            if (header == null)
                header = envelope.addHeader(); // add an header if non exists

            SOAPHeaderElement accessElement = header.addHeaderElement(envelope.createName("Access", "ns0", JPLAG_TYPES_NS));
            SOAPElement usernameelem = accessElement.addChildElement("username");
            usernameelem.addTextNode(username);
            SOAPElement passwordelem = accessElement.addChildElement("password");
            passwordelem.addTextNode(password);
            SOAPElement compatelem = accessElement.addChildElement("compatLevel");
            compatelem.addTextNode(compatibilityLevel + "");
        } catch (SOAPException x) {
            System.out.println("Unable to create access SOAP header!");
            x.printStackTrace();
        }
    }
    return true;
}
项目:tomee    文件:HandlerChainImpl.java   
public MessageSnapshot(MessageContext soapMessage) {
    SOAPMessage message = ((SOAPMessageContext) soapMessage).getMessage();
    if (message == null || message.getSOAPPart() == null) {
        operationName = null;
        parameterNames = null;
    } else {
        SOAPBody body = getBody(message);

        SOAPElement operation = ((SOAPElement) body.getChildElements().next());
        this.operationName = operation.getElementName().toString();

        this.parameterNames = new ArrayList<String>();
        for (Iterator i = operation.getChildElements(); i.hasNext(); ) {
            SOAPElement parameter = (SOAPElement) i.next();
            String element = parameter.getElementName().toString();
            parameterNames.add(element);
        }
    }
}
项目:jplag    文件:JPlagClientAccessHandler.java   
/**
 * Adds an "Access" element to the SOAP header
 */
public boolean handleRequest(MessageContext msgct) {
    if(msgct instanceof SOAPMessageContext) {
        SOAPMessageContext smsgct=(SOAPMessageContext) msgct;
        try {
            SOAPMessage msg=smsgct.getMessage();
            SOAPEnvelope envelope=msg.getSOAPPart().getEnvelope();
            SOAPHeader header=msg.getSOAPHeader();

            if(header==null)
                header=envelope.addHeader(); // add an header if non exists

            SOAPHeaderElement accessElement=header.addHeaderElement(
                    envelope.createName("Access","ns0",
                            "http://www.ipd.uni-karlsruhe.de/jplag/types"));
            SOAPElement usernameelem=accessElement.addChildElement(
                       "username");
            usernameelem.addTextNode(username);
            SOAPElement passwordelem=accessElement.addChildElement(
                       "password");
            passwordelem.addTextNode(password);
               SOAPElement compatelem=accessElement.addChildElement(
                       "compatLevel");
               compatelem.addTextNode(compatibilityLevel+"");
        } catch (SOAPException x) {
            System.out.println("Unable to create access SOAP header!");
            x.printStackTrace();
        }
    }
    return true;
}
项目:jplag    文件:JPlagServerAccessHandler.java   
/**
 * Extracts the username out of the header of a SOAP message
 */
public static String extractUsername(SOAPMessageContext smsg) {
    try {
        SOAPHeader header = smsg.getMessage().getSOAPHeader();
        if (header != null) {
            @SuppressWarnings("unchecked")
            Iterator<SOAPHeaderElement> headers = header.examineAllHeaderElements();
            while (headers.hasNext()) {
                SOAPHeaderElement he = headers.next();

                if (he.getElementName().getLocalName().equals("Access")) {
                    @SuppressWarnings("unchecked")
                    Iterator<SOAPElement> elements = he.getChildElements();
                    while (elements.hasNext()) {
                        SOAPElement e = elements.next();
                        String name = e.getElementName().getLocalName();
                        if (name.equals("username"))
                            return e.getValue();
                    }
                }
            }
        }
    } catch (SOAPException x) {
        x.printStackTrace();
    }
    return null;
}
项目:jplag    文件:JPlagServerAccessHandler.java   
/**
 * Manually builds up a JPlagException SOAP message and replaces the
 * original one with it
 */
public void replaceByJPlagException(SOAPMessageContext smsg, String desc, String rep) {
    try {
        SOAPMessage msg = smsg.getMessage();
        SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();

        /*
         * Remove old header andy body
         */

        SOAPHeader oldheader = envelope.getHeader();
        if (oldheader != null)
            oldheader.detachNode();
        SOAPBody oldbody = envelope.getBody();
        if (oldbody != null)
            oldbody.detachNode();

        SOAPBody sb = envelope.addBody();
        SOAPFault sf = sb.addFault(envelope.createName("Server", "env", SOAPConstants.URI_NS_SOAP_ENVELOPE),
                "jplagWebService.server.JPlagException");
        Detail detail = sf.addDetail();
        DetailEntry de = detail.addDetailEntry(envelope.createName("JPlagException", "ns0", JPLAG_WEBSERVICE_BASE_URL + "types"));

        SOAPElement e = de.addChildElement("exceptionType");
        e.addTextNode("accessException");

        e = de.addChildElement("description");
        e.addTextNode(desc);

        e = de.addChildElement("repair");
        e.addTextNode(rep);
    } catch (SOAPException x) {
        x.printStackTrace();
    }
}
项目:tomee    文件:HandlerChainImpl.java   
private void saveChanges(MessageContext context) {
    try {
        SOAPMessage message = ((SOAPMessageContext) context).getMessage();
        if (message != null) {
            message.saveChanges();
        }
    } catch (SOAPException e) {
        throw new ServerRuntimeException("Unable to save changes to SOAPMessage : " + e.toString());
    }
}
项目:tomee    文件:HandlerChainImpl.java   
private boolean equals(SOAPMessageContext soapMessage) {
    SOAPMessage message = soapMessage.getMessage();

    if (operationName == null) {
        return message == null || message.getSOAPPart() == null;
    }

    SOAPBody body = getBody(message);

    // Handlers can't change the operation
    SOAPElement operation = ((SOAPElement) body.getChildElements().next());
    if (!this.operationName.equals(operation.getElementName().toString())) {
        return false;
    }

    Iterator parameters = operation.getChildElements();
    for (Iterator i = parameterNames.iterator(); i.hasNext(); ) {
        // Handlers can't remove parameters
        if (!parameters.hasNext()) {
            return false;
        }

        String original = (String) i.next();
        SOAPElement parameter = (SOAPElement) parameters.next();
        // Handlers can't change parameter types
        if (parameter == null || !original.equals(parameter.getElementName().toString())) {
            return false;
        }
    }

    // Handlers can't add parameters
    return !parameters.hasNext();
}
项目:jplag    文件:JPlagTypImpl.java   
private String getUsername() {
    SOAPMessageContext smc = (SOAPMessageContext) servletEndpointContext.getMessageContext();
    return JPlagServerAccessHandler.extractUsername(smc);
}
项目:tomee    文件:HandlerChainImpl.java   
public boolean equals(Object obj) {
    return (obj instanceof SOAPMessageContext) && equals((SOAPMessageContext) obj);
}
项目:labviewer    文件:StudyConsumerImpl.java   
/**
 * Will try to locate a pre-existent {@link ApplicationContext}; if failed,
 * will create it explicitly.
 * 
 * @see http://jira.semanticbits.com/browse/CAAERS-4291
 */
private synchronized void initialize() {
    if (this.consumer == null) {
        ApplicationContext ctx = null;
        String exp = ContainerConfig.getConfig().getOption(
                SPRING_CLASSPATH_EXPRESSION,
                DEFAULT_SPRING_CLASSPATH_EXPRESSION);
        String bean = ContainerConfig.getConfig().getOption(
                STUDY_CONSUMER_BEAN_NAME, DEFAULT_STUDY_CONSUMER_BEAN_NAME);

        // see http://jira.semanticbits.com/browse/CAAERS-4291
        // let's see if ApplicationContext is already available as a
        // WebApplicationContext
        // if so, use it; otherwise, fall back to standard approach for
        // backward compatibility.
        SOAPMessageContext messageContext = MessageContext
                .getCurrentContext();
        if (messageContext != null) {
            HttpServlet srv = (HttpServlet) messageContext
                    .getProperty(HTTPConstants.MC_HTTP_SERVLET);
            if (srv != null) {
                ServletContext servletContext = srv.getServletContext();
                ctx = WebApplicationContextUtils
                        .getWebApplicationContext(servletContext);
            }
        }

        if (ctx == null) {
            System.out
                    .println("StudyConsumerImpl: unable to find pre-existing spring context in servlet context; falling back to direct context creation.");
            if (this.getClass().getClassLoader().getResourceAsStream(
                    DEFAULT_APPCONTEXT_XML_PATH) == null) {
                System.out
                        .println("no "
                                + DEFAULT_APPCONTEXT_XML_PATH
                                + " in calsspath. Loading echo study service impl...");
                this.consumer = new EchoStudyServiceImpl();

            } else {
                System.out.println("Creating spring context explicitly...");
                ctx = new ClassPathXmlApplicationContext(exp);
            }
        }

        if (ctx != null)
            this.consumer = (StudyConsumerI) ctx.getBean(bean);

    }
}
项目:labviewer    文件:RegistrationConsumerImpl.java   
/**
 * Will try to locate a pre-existent {@link ApplicationContext}; if failed, will create it explicitly.
 * @see http://jira.semanticbits.com/browse/CAAERS-4291
 */
private synchronized void initialize() {
    if (this.consumer == null) {
        ApplicationContext ctx = null;
        String exp = ContainerConfig.getConfig().getOption(
                SPRING_CLASSPATH_EXPRESSION,
                DEFAULT_SPRING_CLASSPATH_EXPRESSION);
        String bean = ContainerConfig.getConfig().getOption(
                REGISTRATION_CONSUMER_BEAN_NAME,
                DEFAULT_REGISTRATION_CONSUMER_BEAN_NAME);

        // see http://jira.semanticbits.com/browse/CAAERS-4291
        // let's see if ApplicationContext is already available as a
        // WebApplicationContext
        // if so, use it; otherwise, fall back to standard approach for
        // backward compatibility.
        SOAPMessageContext messageContext = MessageContext
                .getCurrentContext();
        if (messageContext != null) {
            HttpServlet srv = (HttpServlet) messageContext
                    .getProperty(HTTPConstants.MC_HTTP_SERVLET);
            if (srv != null) {
                ServletContext servletContext = srv.getServletContext();
                ctx = WebApplicationContextUtils
                        .getWebApplicationContext(servletContext);
            }
        }

        if (ctx == null) {
            System.out
                    .println("RegistrationConsumerImpl: unable to find pre-existing spring context in servlet context; falling back to direct context creation.");
            if (this.getClass().getClassLoader().getResourceAsStream(
                    DEFAULT_APPCONTEXT_XML_PATH) == null) {
                System.out
                        .println("Registration Consumer Implementation not found. Loading the default echo implementation.");
                this.consumer = new EchoRegistrationConsumer();
            } else {
                System.out.println("Creating spring context explicitly...");
                ctx = new ClassPathXmlApplicationContext(exp);
            }
        }

        if (ctx != null)
            this.consumer = (RegistrationConsumerI) ctx.getBean(bean);

    }
}