Home > Back-end >  The realization of the CXF interceptors as webservice return message is too long to get the data
The realization of the CXF interceptors as webservice return message is too long to get the data

Time:09-20

Implementation of OutInterceptor blocker code of the following as webservice return message is too long, cause data can't wrote back flow, can't get back a message, the final XML=IOUtils. ToString (in); Null, greatly help solve ah,,,
//interface to return information
OutputStream OS=message. GetContent (OutputStream. Class);
Cs=new CachedStream CachedStream ();
Message. SetContent (OutputStream class, cs);
Message. GetInterceptorChain (.) doIntercept (message);
CachedOutputStream csnew=(CachedOutputStream) message
GetContent (OutputStream. Class);
InputStream in=csnew. GetInputStream ();
//get back a message
XML=IOUtils. ToString (in);
//parsing return message
The Document Document=DocumentHelper. ParseText (XML);

CodePudding user response:

Now found that, based on the realization of the CXF web service interface returns a string is too long, can cause OutInterceptor SoapMessage buf flow of interceptor is null, if you want to analysis a Message in the interceptor, will obviously have a question, the specific reason is not found, through the analysis of the source Message. GetContent (Class Format) method to get information, but the parameters for (XMLStreamReader. Class, XMLStreamWriter. Class InputStream. Class, OutputStream. Class, List the class, the Exception. Class, Node. The class, DelegatingInputStream. Class), because the stream is null, so the message. The getContent (OutputStream. Class) doesn't work, back to obtain the return value is obtained through the List by webService (now), so my solution is the message. The getContent (List. Class); Access to the List, through the reflection to get a message:
List the List=message. GetContent (List. Class);
For (Object o: list) {
System. The out. Println ("=========="+ o.g etClass ());
The Class oas=o.g etClass ();
The Field [] the fs=oas. GetDeclaredFields ();
For (int I=0; I & lt; Fs. Length; I++) {
The Field f=fs [I];
F.s etAccessible (true);
The Object val=f.g et (o);
}

CodePudding user response:


@ Override
Public void handleMessage (Message Message) throws Fault {
Try {
OutputStream OS=message. GetContent (OutputStream. Class);
ByteArrayOutputStream cs=new ByteArrayOutputStream ();
Message. SetContent (OutputStream class, cs);
Message. GetInterceptorChain (.) doIntercept (message);
ByteArrayOutputStream csnew=(ByteArrayOutputStream) message. GetContent (OutputStream. Class);
ByteArrayInputStream bis=new ByteArrayInputStream (csnew toByteArray ());
String json=IOUtils. ToString (bis);
InterfaceAccessLog InterfaceAccessLog=InterfaceAccessLogHolder. GetInterfaceAccessLog ();
InterfaceAccessLog. SetResponse (changeJsonstr (json));
InterfaceAccessLog. SetUpdatetime (new Date ());
Service. InsertInterfaceAccessLog (interfaceAccessLog);
IOUtils. Copy (new ByteArrayInputStream (json. GetBytes (" utf-8 ")), OS).
Cs. The close ();
OS. The flush ();
Message. SetContent (OutputStream class, OS);
} the catch (IOException e) {
e.printStackTrace();
}
}

The perfect solution
  • Related