是否可以使用jax-ws生成xml,但不能将其发送出去 [英] Is it possible to use jax-ws to generate xml, but NOT send it out

查看:146
本文介绍了是否可以使用jax-ws生成xml,但不能将其发送出去的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以这就是场景:
我们有PeopleSoft并希望从salesforce来回发送消息。不幸的是,PeopleSoft没有像wsimport这样的工具,它使用wsdl并为你生成类。有些东西会消耗wsdl,但它会生成存根消息对象。开发人员仍然必须编写代码来手动生成xml消息字符串。

So here's the scenario: We have PeopleSoft and want to send messages back and forth from salesforce. Unfortunately PeopleSoft doesn't have a tool like wsimport which consumes a wsdl and generates classes for you. There is something that consumes wsdl's, but all it does it generate stub message objects. A developer would still have to write the code to manually generate the xml message string.

我显然不想做所有这些。所以我知道java可以在PeopleSoft中调用。我也知道我可以使用生成的类发送消息,但我想使用PeopleSoft内置的消息监视功能。

I obviously don't want to do all of that. So I know that java can be called from within PeopleSoft. I also know I could send messages just using the generated classes, but I would like to use the message monitoring features built in to PeopleSoft.

所以我可能的解决方案想到意志:

So a possible solution that I am thinking of will:


  1. 在java中调用webservice方法(不发送消息)

  2. 抓住xml

  3. 通过peoplesoft机制发送xml

  4. 抓住响应xml

  5. 传递响应xml回到响应java类

  6. 使用java类来获取xml中的值

  1. call the webservice method in java (without sending out the message)
  2. Grab the xml
  3. send the xml via peoplesoft mechanisms
  4. grab the response xml
  5. pass the response xml back into the response java class
  6. Use java classes to grab values within the xml

Am我疯了还是可能?

Am I crazy or is this possible?

ps我是一个新手java开发人员

p.s. i am a newbie java developer

这是我的抓取xml的处理程序类,但需要一些方法来阻止消息被发送出去。

Here's my handler class to grab the xml, but need some way to preventing message being sent out.

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);
    }
}

}


推荐答案

在Java Web服务JAX-WS中有一种系统的方法。只需使用SOAP Handler应用拦截器模式。处理程序类将拦截handleMessage(SOAPMessageContext mc)方法中的消息,对SOAP Envelope的XML主体执行任何操作。并停止SOAPMessage的进一步处理。

There is a systematic way of doing so in Java web services, JAX-WS. Just apply interceptor pattern using SOAP Handler. The handler class will intercept the message in handleMessage(SOAPMessageContext mc) method, do whatever you want to do with XML body of SOAP Envelope. and stop SOAPMessage further processing.

然后,您可以根据需要处理XML(例如通过peoplesoft机制发送)。当来自peoplesoft的响应回来时,绕过出站处理程序链...(我真的必须通过传递链看看如何)。我只想推动这个想法,你必须做POC。我从来没有这样做过,否则我会分享代码。但这绝对可行。

Then, you can treat the XML as you like (e.g. sending via peoplesoft mechanism). And when response come back from peoplesoft, bypass the outbound handler chain ... (I really have to look how to by pass a chain). I am just rolling the idea, you have to make POC. I never did so, otherwise I would have share code. But this is absolutely doable.

这篇关于是否可以使用jax-ws生成xml,但不能将其发送出去的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆