标签: interceptor

如何拦截WCF中的反序列化后请求对象

我需要拦截所有Web服务的WCF请求.所有服务都遵循严格的模型,其中操作必须从我们的基本请求类型扩展单个请求.该基本请求类型包含我们需要各种系统级支持的属性,自定义日志记录是一个,但还有许多其他.我希望使用IDispatchMessageInspector,但我不知道如何从"消息"中获取请求对象,而无需从正文中重新创建副本.我需要这个是高效的,所以每个请求创建两个副本不会削减它.

我知道我可以使用System.Reflection.Emit创建代理,但是这将与服务激活和工厂混淆......我希望有更容易获得的东西,比如CXF拦截器为Java工作的方式.

无论如何我可以在调度到服务impl之前拦截服务器中的实际单个请求实例吗?

wcf request interceptor

3
推荐指数
1
解决办法
851
查看次数

如何使用org.w3c.dom.Node使用CXF拦截器修改Web服务请求

使用CXF拦截器我想将一些Node附加到发送到服务器的xml.我创建了一个拦截器(见下文),它将消息作为DOM节点接收,修改它并将其写回消息对象.

不幸的是,代码没有按预期工作 - 发送到服务器的XML不包含'magicWord'.恕我直言,我正在使用错误的阶段.

所以问题是:如何使用org.w3c.dom.Node语法修改传出的Web服务请求?

package dummy;

import org.apache.cxf.message.Message;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

class DummyInterceptor extends AbstractPhaseInterceptor {

    String magicWord = "abc";

    public DummyInterceptor() {
        super(Phase.PRE_PROTOCOL);
    }

    public void handleMessage(Message message) {
        Document document = (Document) message.getContent(Node.class);
        NodeList nodes = document.getElementsByTagName("wsse:Security");
        if (nodes.getLength() == 1) {
            Node wsseSecurityNode = nodes.item(0);
            wsseSecurityNode.appendChild(document.createTextNode(magicWord));
        }
        message.setContent(Node.class, document);
    }
}
Run Code Online (Sandbox Code Playgroud)

dom web-services cxf interceptor

3
推荐指数
1
解决办法
3814
查看次数

Spring Security过滤器具有多个URL拦截映射

我正在学习本教程:http: //www.mkyong.com/spring-security/spring-security-hello-world-example/

在里面 spring-security-xml

<http auto-config="true">
    <intercept-url pattern="/welcome*" access="ROLE_USER" />
</http>
Run Code Online (Sandbox Code Playgroud)

在web.xml中,我们必须定义实际的过滤器

<!-- Spring Security -->
<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>
              org.springframework.web.filter.DelegatingFilterProxy
            </filter-class>
</filter>

<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
Run Code Online (Sandbox Code Playgroud)

所以我没有得到这个,我们将截取映射到2个地方的2个网址.去/welcome*/*.为什么我们需要这两个?我在这里错过了什么吗?

java spring spring-security interceptor

3
推荐指数
1
解决办法
5572
查看次数

Spring ClientInterceptor 在响应中显示空的 SOAP 标头

我有一个 SOAP 服务,我需要与之交谈。第一个 SOAP 请求在 SOAP 标头中接收带有sessionID元素的响应,我需要在最终发布命令中发送该元素。

为了获取这个 sessionID 值,我计划使用ClientInterceptor。在我的WebServiceGatewaySupport实现中,我注册了我的拦截器:

this.setInterceptors(new ClientInterceptor[] { new MyWebServiceClientInterceptor() });
Run Code Online (Sandbox Code Playgroud)

我的拦截器:

public class MyWebServiceClientInterceptor implements ClientInterceptor {

    public final QName SessionID_QNAME = new QName("http://xml.example.com/ws/session", "sessionID");

    public boolean handleFault(MessageContext context) throws WebServiceClientException {
        logger.info("Handle Fault");
        return true;
    }       

    public boolean handleResponse(MessageContext context) throws WebServiceClientException {
        logger.info("Handle Response");
        SoapMessage soapMessage = (SoapMessage) context.getRequest();
        SoapHeader soapHeader = soapMessage.getSoapHeader();

        logger.info("Response Header: " + soapHeader.getName());
        Iterator<SoapHeaderElement> qn = soapHeader.examineAllHeaderElements();
        while (qn.hasNext()) {
            SoapElement …
Run Code Online (Sandbox Code Playgroud)

java spring soap web-services interceptor

3
推荐指数
1
解决办法
5688
查看次数

Angular JS解决循环依赖

我尝试在http拦截器中执行http.post调用,但是我得到了一个

Circular dependency found: $http <- Ace <- authInterceptor <- $http <- $templateRequest <- $compile
Run Code Online (Sandbox Code Playgroud)

我明白为什么,但我不知道如何解决它...仍然新的角度和有点混乱的时候,我希望你可以帮助我:) Heres是我的代码:

var app = angular.module('AceAngularApi', []);

app.service('Ace', ['$http', '$q', '$injector', '$window', function($http, $q, $injector, $window) {

    var user = null;

    var getCurrentUser = function() {
        var url = "http://localhost:8080/api/currentuser";

        var response = $http.post(url, {}).then(function(response) {});
        return response;
    };
    return {
        getCurrentUser: getCurrentUser,
    }
}]);

app.factory('authInterceptor', ['$rootScope', '$q', '$window', '$injector', 'Ace',
    function($rootScope, $q, $window, $injector, Ace) {
        return {
            request: function(config) {
                config.headers = config.headers …
Run Code Online (Sandbox Code Playgroud)

javascript interceptor angularjs

3
推荐指数
1
解决办法
1550
查看次数

离开方法时使用拦截器

在我的Java EE程序中,我想使用Interceptor进行日志记录。当我输入一个方法时它很容易使用:

注释:

@Inherited
@InterceptorBinding
@Retention(RUNTIME)
@Target({ METHOD, TYPE })
public @interface Logged {

}
Run Code Online (Sandbox Code Playgroud)

拦截器:

@Logged
@Interceptor
public class LoggedInterceptor implements Serializable {

    private static final long serialVersionUID = 1L;

    @Inject
    private Logger logger;

    @AroundInvoke
    public Object logMethodEntry(InvocationContext invocationContext) throws Exception {

        logger.info("Entering method: "
            + invocationContext.getMethod().getName() + " in class "
            + invocationContext.getMethod().getDeclaringClass().getName());

        return invocationContext.proceed();

    }
}
Run Code Online (Sandbox Code Playgroud)

我的班级使用拦截器:

public class MyClass {

    @Logged
    public void MyMethod() {
        // do something
    }

}
Run Code Online (Sandbox Code Playgroud)

但是现在我想在离开MyMethod …

java interceptor jakarta-ee

3
推荐指数
1
解决办法
3278
查看次数

无法读取HTTP消息:org.springframework.http.converter.HttpMessageNotReadableException:缺少必需的请求正文

我有和拦截器,由于某些原因,我必须阅读包含在HttpServletRequest这里的POSTED日期:

    InputStream inputStream = request.getInputStream();
    if (inputStream != null) {
        bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        char[] charBuffer = new char[128];
        int bytesRead = -1;
        while ((bytesRead = bufferedReader.read(charBuffer)) > 0) {
            stringBuilder.append(charBuffer, 0, bytesRead);
        }
    } else {
        stringBuilder.append("");
    }
Run Code Online (Sandbox Code Playgroud)

在这个动作之后我得到了400个关于ajax的错误请求无法读取HTTP消息: org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing

spring interceptor

3
推荐指数
1
解决办法
3万
查看次数

Angularjs +拦截器+仅为http请求添加查询参数(不是html,js,css文件)

我正在使用angularjs,在后端我检查每个api身份验证.每个请求都应该检查参数access_token.

$provide.factory('MyHttpInterceptor', function($q, $location, $localStorage) {
    return {
        request : function(config) {
            config.params = config.params || {};
            if ($localStorage.access_token) {
                config.params.access_token = $localStorage.access_token;
            }
            return config || $q.when(config);
        },
    };
});

// Add the interceptor to the $httpProvider.
$httpProvider.interceptors.push('MyHttpInterceptor'); 
Run Code Online (Sandbox Code Playgroud)

我用这个代码.它工作得很好,但我在开发工具(网络)中看到html,css,js文件也添加了参数.喜欢.

http://localhost/webapp/views/template/left-menu.html?access_token=xxxxxxxxxxxxxxxxx
http://localhost/webapp/css/index.css?access_token=xxxxxxxxxxxxxxxxx
Run Code Online (Sandbox Code Playgroud)

但我不喜欢将access_token发送到所有http请求(html,css,js).

我喜欢发送带有前缀api的access_token

http://localhost:9090/api/user/get?access_token=xxxxxxxxxxxxxxxxxxxxxx

//I think the solution is find the http url and grep the text api, if found means add the parameter. Don't konw this is good approach.

Please me the good approach.
Run Code Online (Sandbox Code Playgroud)

我只期望只有后端api请求.另外,我不希望每个严格的http请求添加参数.

可以在config中添加常见的一个位置吗?

factory http interceptor angularjs

3
推荐指数
1
解决办法
4529
查看次数

从cxf消息获取Http请求主体

我正在尝试编写一个cxf拦截器,它将所有来自我的应用程序的传入请求转发到另一个应用程序。但是对于POST请求,我无法获取请求的正文。

我正在使用的代码如下所示:

String body = message.getContent(String.class);
Run Code Online (Sandbox Code Playgroud)

但是,主体为null。我调查了cxf代码,看起来您必须指定确切的类(例如:ArrayList)来获取主体。我的应用程序具有多个此类消息类。我想知道是否有一种方法可以避免为每个POJO类编写多个检查并在一个检查中完成if

java web-services cxf interceptor

3
推荐指数
1
解决办法
6055
查看次数

SAP HYBRIS [Y]:如何创建自定义拦截器

我是Sap Hybris的初学者.我想创建自定义拦截器.有人可以向我解释一个更好理解的基本例子.

java sap interceptor hybris

3
推荐指数
1
解决办法
889
查看次数