wil*_*ard 5 java web-services jax-ws peoplesoft
所以这就是场景:我们有PeopleSoft,并希望从salesforce来回发送消息.不幸的是,PeopleSoft没有像wsimport这样的工具,它使用wsdl并为你生成类.有些东西会消耗wsdl,但它会生成存根消息对象.开发人员仍然必须编写代码来手动生成xml消息字符串.
我显然不想做所有这些.所以我知道java可以在PeopleSoft中调用.我也知道我可以使用生成的类发送消息,但我想使用PeopleSoft内置的消息监视功能.
所以我想到的一个可能的解决方案是:
我疯了还是可能的?
ps我是一个新手java开发人员
这是我的抓取xml的处理程序类,但需要一些方法来防止消息被发送出去.
public class LoggingHandler implements SOAPHandler<SOAPMessageContext> {
// change this to redirect output if desired
private static PrintStream out = System.out;
private String xmlOut = null;
public Set<QName> getHeaders() {
return null;
}
public boolean handleMessage(SOAPMessageContext smc) {
logToSystemOut(smc);
return true;
}
public boolean handleFault(SOAPMessageContext smc) {
logToSystemOut(smc);
return true;
}
// nothing to clean up
public void close(MessageContext messageContext) {
}
public String getXmlOut() {
return xmlOut;
}
/*
* Check the MESSAGE_OUTBOUND_PROPERTY in the context
* to see if this is an outgoing or incoming message.
* Write a brief message to the print stream and
* output the message. The writeTo() method can throw
* SOAPException or IOException
*/
private void logToSystemOut(SOAPMessageContext smc) {
Boolean outboundProperty = (Boolean)
smc.get (MessageContext.MESSAGE_OUTBOUND_PROPERTY);
SOAPMessage message = smc.getMessage();
try {
ByteArrayOutputStream baOut = new ByteArrayOutputStream();
message.writeTo(baOut);
xmlOut = new String(baOut.toByteArray());
} catch (Exception e) {
out.println("Exception in handler: " + e);
}
}
}
Run Code Online (Sandbox Code Playgroud)
解决方案之一可能是替换SocketFatoryJAX-WS。大致看起来会是这样的:
javax.net.SocketFactory socketFactory = new MySocketFactory();
Service service = Service.create(new URL(wsdl), new QName(namespace, servicename));
Dispatch<SOAPMessage> dispatch = service.createDispatch(methodToBeCalled, SOAPMessage.class, Service.Mode.MESSAGE);
dispatch.getRequestContext().put(com.sun.xml.ws.developer.JAXWSProperties.SSL_SOCKET_FACTORY, socketFactory);
// or ((BindingProvider) Service.getPort(SEIInterface.class)).getRequestContext().put(...);
Run Code Online (Sandbox Code Playgroud)
您MySocketFactory可以自由创建套接字,将消息通过管道传输到另一个通道。