Apache CXF wsdl2java 도구를 사용하여 웹 서비스 클라이언트를 얻었습니다. 그것은 잘 작동하지만 한 가지 방법으로 특수 문자가 포함 된 문자열을 보내야합니다. 생성 된 클라이언트는 이스케이프 문자를 사용합니다. 나는 그것을 원하지 않는다. 문자열을 "< [! CDATA []]>"블록 안에 넣고 싶습니다. 나는 코드에 수동으로 "< [! CDATA []]"를 추가 할 수있다. 문제는 없지만, 나는 어떻게 cachracter가 도망 치는지를 모른다. 그런 문제가 있습니까? 가장 간단한 방법으로 그것을 고치는 방법?Apache CXF wsdl2java 클라이언트 - 이스케이프 문자 대신 CDATA에있는 문자열
[편집] :
내가 쓴 인터셉터 : 다니엘 Kulp 대답 후 나는 이런 짓을
public class CDATAInterceptor extends AbstractPhaseInterceptor<Message> {
public CDATAInterceptor(String phase) {
super(phase);
}
public void handleMessage(Message message) {
XMLStreamWriter writer = (XMLStreamWriter) message.getContent(XMLStreamWriter.class);
if (writer != null && !(writer instanceof MyXmlWriter)) {
message.setContent(XMLStreamWriter.class, new MyXmlWriter(writer));
}
}
}
난 그냥 경우에 가능한 모든 단계 (에 추가 한 - 아마 넣어한다 MARSHAL 또는 PRE_MARSHAL).
MyService service = new MyService(new URL(http://my_url_adress?wsdl));
proxy = service.getMyServiceSoap12();
Client client = ClientProxy.getClient(proxy);
client.getOutInterceptors().add(new CDATAInterceptor(Phase.INVOKE));
client.getOutInterceptors().add(new CDATAInterceptor(Phase.MARSHAL));
client.getOutInterceptors().add(new CDATAInterceptor(Phase.MARSHAL_ENDING));
client.getOutInterceptors().add(new CDATAInterceptor(Phase.POST_INVOKE));
client.getOutInterceptors().add(new CDATAInterceptor(Phase.POST_LOGICAL));
client.getOutInterceptors().add(new CDATAInterceptor(Phase.POST_LOGICAL_ENDING));
...
여기 MyXmlWriter 클래스 코드입니다 :이 작동하지 않습니다
public class MyXmlWriter implements XMLStreamWriter {
protected XMLStreamWriter originalXmlWriter;
public MyXmlWriter(XMLStreamWriter originalXmlWriter) {
this.originalXmlWriter = originalXmlWriter;
}
public void writeStartElement(String localName) throws XMLStreamException {
this.originalXmlWriter.writeStartElement(localName);
}
public void writeStartElement(String namespaceURI, String localName) throws XMLStreamException {
this.originalXmlWriter.writeStartElement(namespaceURI, localName);
}
public void writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
this.originalXmlWriter.writeStartElement(prefix, localName, namespaceURI);
}
public void writeEmptyElement(String namespaceURI, String localName) throws XMLStreamException {
this.originalXmlWriter.writeEmptyElement(namespaceURI, localName);
}
public void writeEmptyElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
this.originalXmlWriter.writeEmptyElement(prefix, localName, namespaceURI);
}
public void writeEmptyElement(String localName) throws XMLStreamException {
this.originalXmlWriter.writeEmptyElement(localName);
}
public void writeEndElement() throws XMLStreamException {
this.originalXmlWriter.writeEndElement();
}
public void writeEndDocument() throws XMLStreamException {
this.originalXmlWriter.writeEndDocument();
}
public void close() throws XMLStreamException {
this.originalXmlWriter.close();
}
public void flush() throws XMLStreamException {
this.originalXmlWriter.flush();
}
public void writeAttribute(String localName, String value) throws XMLStreamException {
this.originalXmlWriter.writeAttribute(localName, value);
}
public void writeAttribute(String prefix, String namespaceURI, String localName, String value) throws XMLStreamException {
this.originalXmlWriter.writeAttribute(prefix, namespaceURI, localName, value);
}
public void writeAttribute(String namespaceURI, String localName, String value) throws XMLStreamException {
this.originalXmlWriter.writeAttribute(namespaceURI, localName, value);
}
public void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException {
this.originalXmlWriter.writeNamespace(prefix, namespaceURI);
}
public void writeDefaultNamespace(String namespaceURI) throws XMLStreamException {
this.originalXmlWriter.writeDefaultNamespace(namespaceURI);
}
public void writeComment(String data) throws XMLStreamException {
this.originalXmlWriter.writeComment(data);
}
public void writeProcessingInstruction(String target) throws XMLStreamException {
this.originalXmlWriter.writeProcessingInstruction(target);
}
public void writeProcessingInstruction(String target, String data) throws XMLStreamException {
this.originalXmlWriter.writeProcessingInstruction(target, data);
}
public void writeCData(String data) throws XMLStreamException {
this.originalXmlWriter.writeCData(data);
}
public void writeDTD(String dtd) throws XMLStreamException {
this.originalXmlWriter.writeDTD(dtd);
}
public void writeEntityRef(String name) throws XMLStreamException {
this.originalXmlWriter.writeEntityRef(name);
}
public void writeStartDocument() throws XMLStreamException {
this.originalXmlWriter.writeStartDocument();
}
public void writeStartDocument(String version) throws XMLStreamException {
this.originalXmlWriter.writeStartDocument(version);
}
public void writeStartDocument(String encoding, String version) throws XMLStreamException {
this.originalXmlWriter.writeStartDocument(encoding, version);
}
public void writeCharacters(String text) throws XMLStreamException {
this.originalXmlWriter.writeCData(text);
}
public void writeCharacters(char[] text, int start, int len) throws XMLStreamException {
this.originalXmlWriter.writeCData(String.copyValueOf(text, len, len));
}
public String getPrefix(String uri) throws XMLStreamException {
return this.originalXmlWriter.getPrefix(uri);
}
public void setPrefix(String prefix, String uri) throws XMLStreamException {
this.originalXmlWriter.setPrefix(prefix, uri);
}
public void setDefaultNamespace(String uri) throws XMLStreamException {
this.originalXmlWriter.setDefaultNamespace(uri);
}
public void setNamespaceContext(NamespaceContext context) throws XMLStreamException {
this.originalXmlWriter.setNamespaceContext(context);
}
public NamespaceContext getNamespaceContext() {
return this.originalXmlWriter.getNamespaceContext();
}
public Object getProperty(String name) throws IllegalArgumentException {
return this.originalXmlWriter.getProperty(name);
}
}
여기에 내가 인터셉터를 추가하는 방법 코드입니다. 어떻게 작동하는지 확인하기 위해 디버깅 중이며 거의 사용되지 않은 MyXmlWriter.writeCharacters (...) 메서드가 있음을 알 수 있습니다. 출력 메시지에는 여전히 CDATA 내부에있는 것이 아니라 이스케이프 문자가 있습니다.
[Edit2가] : 난 그냥 라인을 추가 할 필요가 있음을 발견
message.put("disable.outputstream.optimization", Boolean.TRUE);
소스 : http://cxf.547215.n5.nabble.com/CXF-jaxb-send-string-as-CData-td5524523.html 유일한 방법은 메시지에서 XMLStreamWriter에 잡아 것 인터셉터를 작성하는 것입니다
정말 고마워요. 너는 내 일요일 오후를 구했다. –