最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

java - JAX-WS interceptor is not being triggerd - Stack Overflow

matteradmin6PV0评论

The problem is that after adding JAX-WS to my project, specifically to the file that will be generated, I tested the generated file, but nothing related to the interceptor appeared. It seems like I didn’t add it at all, as no issues were shown, and the interceptor doesn’t work.

here is the generated file which it suppose it has the interceptor

package Services;

import javax.annotation.Resource;
import javax.jws.*;
import javax.xml.ws.*;
import javax.xml.ws.soap.SOAPBinding;
@HandlerChain(file = "C:/WEBLOGIC/wsbank/TPS/WEB-INF/src/Services/handler.xml")
@WebService(serviceName = "Virement")
public class Virement {

    @Resource
    private WebServiceContext wsCtx;

    @WebMethod
    public String WS43(
        @WebParam(name = "NumeroDocument") Long numeroDocument,
        @WebParam(name = "TypeDocument") Long typeDocument,
        @WebParam(name = "RIBBeneficiaire") String ribBeneficiaire,
        @WebParam(name = "Description") String description,
        @WebParam(name = "RIBDonneurOrdre") String ribDonneurOrdre,
        @WebParam(name = "Devise") String devise,
        @WebParam(name = "Montant") Long montant
    ) {
        WS43ImplGen ws43ImplGen = new WS43ImplGen();
        //return ws43ImplGen.Execute_WS43(
           // numeroDocument, typeDocument, ribBeneficiaire, description,
           // ribDonneurOrdre, devise, montant, wsCtxr
        return "test";
       
    }
}

here is the handler chain xml file

<handler-chain xmlns=";>
    <handler>
        <handler-class>Services.ParameterValidationHandler</handler-class>
    </handler>
</handler-chain>

here is the code logic of the interceptor

package Services;

import java.util.Collections;

import javax.xml.namespace.QName;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.handler.Handler;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.soap.SOAPHandler;
import javax.xml.ws.handler.soap.SOAPMessageContext;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPBody;
import java.util.Set;

public class ParameterValidationHandler implements SOAPHandler<SOAPMessageContext> {



    @Override
    public boolean handleMessage(SOAPMessageContext context) {
        System.out.println("done");
        Boolean isOutbound = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

        if (isOutbound) {
            System.out.println("Outbound message - Skipping validation.");
        } else {
            System.out.println("Inbound message - Validating parameters...");

            // Get the SOAP message
            SOAPMessage message = context.getMessage();
            try {
                SOAPHeader header = message.getSOAPHeader();
                SOAPBody body = message.getSOAPBody();

                // Example of accessing the SOAP message parts, you can validate parameters here
                System.out.println("SOAP Header: " + header);
                System.out.println("SOAP Body: " + body);

                // Add your parameter validation logic here
                // For example, checking certain elements in the body
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        // Return true to continue processing, false to block the message
        return true;
    }

    @Override
    public boolean handleFault(SOAPMessageContext context) {
        System.out.println("Handling SOAP fault...");
        return true;  // You can handle faults here if necessary
    }

    @Override
    public void close(MessageContext context) {
        // Cleanup if needed
    }

    @Override
    public Set<QName> getHeaders() {
        // TODO Implement this method
        return Collections.emptySet();
    }
}

So here’s the problem, i need your help guys, because I’m going insane and thanks in advance for your help !

Post a comment

comment list (0)

  1. No comments so far