javax (jws) WebService, get String of the input parameters (Password: value)

0

Hello!

I have a set of services in Java, that I call them by SOAP and I want to register the input parameters. For example:

@WebMethod(operationName = "getObject")
public MyObject getObject(
        @WebParam(name = "param1") final Short param1,
        @WebParam(name = "param2") final Short param2,
        @WebParam(name = "param3") final Short param3,
        @WebParam(name = "param4") final Short param4,
        @WebParam(name = "param5") final Short param5,
        @WebParam(name = "param6") final Short param6,
        @WebParam(name = "param7") final Integer param7,
        @WebParam(name = "param8") final String param8,
        @WebParam(name = "param9") final Date param9,
        @WebParam(name = "param10") final Date param10,
        @WebParam(name = "param11") final Date param11,
        @WebParam(name = "param12") final Date param12)

Once in the function I do this to collect and save in a log file what I have entered:

logTracking.request("param1: " + param1 + " - param2: " + param2
                + " - param3: " + param3 + " - param4: " + param4
                + " - param5: " + param5 + " - param6: " + param6
                + " - param7: " + param7 + " - param8: " + param8
                + " - param9: " + param9 + " - param10: " + param10
                + " - param11: " + param11 + " - param12: " + param12);

We have many methods and do in each of these, is cumbersome, and every time you add or remove some parameter you have to change the log. (Obviously the parameters have a more appropriate name, I put it as an example.)

Is there any way to collect this in a single string and thus save it in the log in String format? I have seen something of WebServiceContext , I have tried something and it has not worked for me, it always comes empty or zero values: link

Thank you very much.

    
asked by Alber Developer 16.03.2018 в 09:42
source

1 answer

0

One option would be Handler s, which is the equivalent in JAX-WS at HttpFilter ; small modules that run before or after the main logic.

public class SOAPLogger implements SOAPHandler<SOAPMessageContext>{
  @Override
  public boolean handleMessage(SOAPMessageContext context) {
      SOAPMessage soapMessage = context.getMessage();
      ...
  }
}

From here you can play with soapMessage to extract the SOAP (or if you prefer, take a more detailed tour of the content of the request). For example, with getSOAPBody , getSOAPPart , etc.

The handlers go in handler "chains", which are declared in a file:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<javaee:handler-chains
   xmlns:javaee="http://java.sun.com/xml/ns/javaee"
   xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <javaee:handler-chain>
      <javaee:handler>
         <javaee:handler-class>miPackage.SOAPLogger</javaee:handler-class>
     </javaee:handler>
   </javaee:handler-chain>
</javaee:handler-chains>

To indicate that a WS uses a handler chain , you use @HandlerChain

@WebService
@HandlerChain(file="handler-chain.xml")
public class MiWebService{

   @WebMethod(operationName = "getObject")
   public MyObject getObject(

More information: link

Another option, much simpler but much less flexible, is to use the system of logs that the platform can offer. For example in WildFly, in the file logging.properties :
logger.org.apache.cxf.services.MiWebService.level=INFO
logger.org.apache.cxf.services.MiWebService.useParentHandlers=true
    
answered by 16.03.2018 в 12:48