在我的Java Web服务,我实现WebServiceProvider此类并试图获得原请求的客户端已经完成。问题是我在soap消息体内的xml标签中获取了不可读的字符,如<Applicant_Place_Born>Москва</Applicant_Place_Born>
,而不是普通的西里尔字母。所以我正在寻找如何解决这个问题的方法。可能我可以使用<Source>
泛型类型而不是<SOAPMessage>
,但我不知道如何将它转换为字节。
Q1:是否有可能得到的字节数组原(原始二进制数据),这样我可以手动将其解码客户端的请求?
Q2:是否有直接的方法通过为SOAP消息指定解码字符集来修复错误的字符?下面Mojibakes在SOAP消息
我当前的代码给出:
@WebServiceProvider(
portName="SoaprequestImplPort",
serviceName="services/soaprequest",
targetNamespace="http://tempuri.org/soaprequest",
wsdlLocation="/wsdl/SoaprequestImpl.wsdl"
)
@BindingType(value="http://schemas.xmlsoap.org/wsdl/soap/http")
@ServiceMode(value=javax.xml.ws.Service.Mode.MESSAGE)
public class SoaprequestImpl implements Provider<SOAPMessage> {
private static final String hResponse = "<soapenv:Envelope xmlns:soapenv=\\";
public SOAPMessage invoke(SOAPMessage req) {
getSOAPMessage(req);
SOAPMessage res = null;
try {
res = makeSOAPMessage(hResponse);
} catch (Exception e) {
System.out.println("Exception: occurred " + e);
}
return res;
}
private String getSOAPMessage(SOAPMessage msg) {
ByteArrayOutputStream baos = null;
try {
baos = new ByteArrayOutputStream();
msg.writeTo(baos);
OutputStream outputStream = new FileOutputStream ("/opt/data/tomcat/end.txt");
baos.writeTo(outputStream);
} catch(Exception e) {
e.printStackTrace();
}
return s;
}
private SOAPMessage makeSOAPMessage(String msg) {
try {
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage message = factory.createMessage();
message.getSOAPPart().setContent((Source)new StreamSource(new StringReader(msg)));
message.saveChanges();
return message;
} catch (Exception e) {
return null;
}
}
}
谢谢你的回答。我明白你的解释,这就是我所问的。我需要将字符串从UTF-8解码回客户端使用的原始编码。但是我不确切知道最初使用的编码以及如何在java代码中完成编码。 – griboedov