SOAP调用程序未被调用

时间:2017-03-03 06:57:41

标签: java soap

我有以下Web服务。

@WebService(targetNamespace="T24WebServicesImpl")
@XmlSeeAlso( { 
       MYCUSTOMERType.class,
		Object[].class } )
@HandlerChain(file = "./handler-chain.xml")	
public class T24WebServicesImpl extends TwsController {

	@WebMethod
	public void myCustomer(
		.......
	}

}

handler-chain.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxrs:handler-chains xmlns:javaee="http://java.sun.com/xml/ns/javaee"
	xmlns:xsd="http://www.w3.org/2001/XMLSchema">
	<jaxrs:handler-chain>
		<jaxrs:handler>
			<jaxrs:handler-class>com.temenos.tws.Handler</jaxrs:handler-class>
		</jaxrs:handler>
	</jaxrs:handler-chain>
</jaxrs:handler-chains>

执行服务时,不会调用Handler类。请提示为什么?

2 个答案:

答案 0 :(得分:0)

尝试像这样的处理程序定义:

<?xml version="1.0" encoding="UTF-8"?>
<handler-chains xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
  http://java.sun.com/xml/ns/javaee/javaee_web_services_metadata_handler_2_0.xsd">
    <handler-chain>
        <handler>
            <handler-name>Handler</handler-name>
            <handler-class>com.temenos.tws.Handler</handler-class>
        </handler>
    </handler-chain>
</handler-chains>

您使用的是xml前缀&#34; jaxrs&#34;但是你将xml定义绑定到前缀&#34; javaee&#34;。因此,要么像xmlns:jaxrs="http://java.sun.com/xml/ns/javaee"那样更改绑定,要么省略上面代码中显示的命名空间。

答案 1 :(得分:0)

&#13;
&#13;
public class Handler implements SOAPHandler<SOAPMessageContext> {

	private byte[] secretBytes;

	/* Getter and Setter methods */
	public Handler() {
	}

	@Override
	public void close(MessageContext mCtx) {
	}

	@Override
	public Set<QName> getHeaders() {
		return null;
	}

	@Override
	public boolean handleFault(SOAPMessageContext mCtx) {
		return true;
	}

	@Override
	public boolean handleMessage(SOAPMessageContext mCtx) {
		
		System.out.println("Server : handleMessage()......");
		Boolean isRequest = (Boolean) mCtx
				.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
		// for response message only, true for outbound messages, false for
		// inbound
		if (isRequest) {

			try {
				SOAPMessage soapMsg = mCtx.getMessage();
				SOAPPart sp = soapMsg.getSOAPPart();
				sp.getEnvelope().removeNamespaceDeclaration("soap");
				SOAPBody body = soapMsg.getSOAPBody();

				SOAPBodyElement bodyElement = body.addBodyElement(new QName("",
						"javaee"));
				// Test adding a node, restore Arraylist code back
				soapMsg.writeTo(System.out);
				Node testNode = (Node) body.getFirstChild();
				append(testNode, "CustomerName", "Jon Doe");
				
				soapMsg.writeTo(System.out);
				System.out.println("Server : After append()......");
				
				return true; 
			} catch (Exception ex) {

			}
		}
		return true;
	}

	private void append(Node addNode, String string, String string2) {
		Element element = addNode.getOwnerDocument().createElement(string);
		element.setTextContent(string2);
		addNode.appendChild(element);
	//	firstChild.

	}
}
&#13;
&#13;
&#13;