简体   繁体   English

JAX-WS如何在未解组之前拦截HTTP字符串

[英]JAX-WS how to intercept HTTP string before it gets unmarshalled

I'm developing a java client in netbeans to consume some partner's business .net services. 我正在netbeans中开发一个Java客户端,以使用某些合作伙伴的业务.net服务。 One of the web methods returns forbidden characters as part of it response parameters, as shown below: 其中一种Web方法返回禁止的字符作为其响应参数的一部分,如下所示:

 <a:numeroDocumento>5016907031</a:numeroDocumento>
 <a:observaciones>&#x1B;R&#x7;&#x1B;t&#x3;&#x1B; &#x1B;3&#x1;&#x1B;!&#x1;&#x1D;!&#x1B;a        EMPRESA: CIRCULANTE S.A.        &#x1B;

the jaxb unmarshaller throws an error for the ? jaxb解组器为抛出错误? character present: 存在的字符:

mar 30, 2015 2:11:10 PM com.sun.xml.ws.security.message.stream.LazyStreamBasedMessage readMessage
GRAVE: WSSMSG0001: se ha producido un error al almacenar en el buffer el mensaje SOAP entrante. (error produced while trying to buffer the incoming SOAP message)
com.ctc.wstx.exc.WstxParsingException: Illegal character entity: expansion character (code 0x1b
at [row,col {unknown-source}]: [1,891]
    at com.ctc.wstx.sr.StreamScanner.constructWfcException(StreamScanner.java:606)
    at com.ctc.wstx.sr.StreamScanner.throwParseError(StreamScanner.java:479)

the technical support at the web service provider says they cannot change this output, even though I've told them these are not compilant with the XML standard, the instruct me to change these characters as shown in C# code: Web服务提供商的技术支持人员说,即使我告诉他们它们不符合XML标准,他们也不能更改此输出,请指示我更改这些字符,如C#代码所示:

string tirillaRecargaPromo = " R\a t    3  !  ! a         EMPRESA: EFECTIVO LTDA          a           NIT.: a *some parts deleted as not disclosable*                    a                                         a                                         a Aplica condiciones particulares con el  a         cliente beneficiario.           a   Conserve este recibo, es el unico     a soporte valido para atender cualquier   a              reclamacion.               a  Con la solicitud y aceptacion de mi    a    parte, de la prestacion de este      a  servicio, entiendase que manifiesto    a  verbalmente mi autorizacion para el    atratamiento de los datos personales que  avoluntariamente he entregado a Efectivo  a Ltda. Estos datos puede ser utilizados  a     unica y exclusivamente para la      a   prestacion del servicio convenido.    a   Linea de servicio al cliente: (1)     a                6510101                  a    servicioalcliente@efecty.com.co      a           www.efecty.com.co             a                                        ";
tirillaRecargaPromo = tirillaRecargaPromo.Substring(16);
tirillaRecargaPromo = tirillaRecargaPromo.Replace(" a", Convert.ToString((char)27) + Convert.ToString((char)97) + Convert.ToString((char)0) + Convert.ToString((char)10));

So I'm left only with trying to port this code to Java, and finding a way to intercept the HTTP response before it is processed. 因此,我只剩下尝试将此代码移植到Java,并找到一种在处理HTTP响应之前对其进行拦截的方法。 I've tried searching everywhere for two days, most answers to similar questions tell to use a Handler and HandlerChain but the same problem happens as basic XML proccessing is done before the MessageContext is sent to the handler. 我已经尝试在各处搜索了两天,大多数类似问题的答案都告诉您使用Handler和HandlerChain,但是在将MessageContext发送到处理程序之前完成基本的XML处理时,会发生相同的问题。 How can I replace these characters in a lower level in METRO2? 如何在METRO2的较低级别替换这些字符?

Any hints appreciated 任何提示表示赞赏

You could write a proxying servlet which takes its http POST input and uses something low level like HttpURLConnection to send to the underlying service provider, filtering its raw HTTP response as needed. 您可以编写一个代理servlet,该代理servlet接受其HTTP POST输入,并使用诸如HttpURLConnection类的低级内容发送给底层服务提供者,并根据需要过滤其原始HTTP响应。 You'd then set the endpoint of your java client to the servlet URL. 然后,将Java客户端的端点设置为servlet URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM