简体   繁体   English

如何获取传入请求SOAP的IP地址

[英]How to get IP address of incoming request SOAP

I have the following classes, how I can get the IP address of the incoming request source? 我有以下课程,如何获取传入请求源的IP地址? I have checked several solutions on the internet but could not find some suitable one, if you need more information about the project structure I can add, thanks 我已经在互联网上检查了几种解决方案,但是找不到一些合适的解决方案,如果您需要有关我可以添加的项目结构的更多信息,谢谢

@EnableWs
@Configuration
public class WebServiceConfig extends WsConfigurerAdapter {

    @Bean
    public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
        MessageDispatcherServlet servlet = new MessageDispatcherServlet();
        servlet.setApplicationContext(applicationContext);
        servlet.setTransformWsdlLocations(true);
        return new ServletRegistrationBean(servlet, "/ws/*");
    }

    @Bean(name = "doSomething")
    public DefaultWsdl11Definition defaultValidateWsdl11Definition(XsdSchema validateSchema) {
        DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
        wsdl11Definition.setPortTypeName("ValidatePort");
        wsdl11Definition.setLocationUri("/ws");
        wsdl11Definition.setTargetNamespace("http://www.org.com/validate");
        wsdl11Definition.setSchema(validateSchema);
        return wsdl11Definition;
    }

    @Bean(name = "doSecond")
    public DefaultWsdl11Definition defaultActionWsdl11Definition(XsdSchema actionSchema) {
        DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
        wsdl11Definition.setPortTypeName("ActionPort");
        wsdl11Definition.setLocationUri("/ws");
        wsdl11Definition.setTargetNamespace("http://www.org.com/action");
        wsdl11Definition.setSchema(actionSchema);
        return wsdl11Definition;
    }

    @Bean
    public XsdSchema validateSchema() {
        return new SimpleXsdSchema(new ClassPathResource("doSomething.xsd"));
    }

    @Bean
    public XsdSchema actionSchema() {
        return new SimpleXsdSchema(new ClassPathResource("doSecond.xsd"));
    }

}
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    xmlns:tns="http://www.org.com/doSomething" 
    targetNamespace="http://www.org.com/doSomething" elementFormDefault="qualified">

    <xs:element name="getActionRequest">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="Username" type="xs:string"/>
                <xs:element name="Password" type="xs:string"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

    <xs:element name="getDoSomethingResponse">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="Code" type="xs:string"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

</xs:schema>

As inidicated by Tibrogargan, it should be in the headers. 正如Tibrogargan所暗示的那样,它应该在标题中。 You could get your Request injected like this 您可以像这样注入您的Request

@Autowired
private HttpServletRequest request;

and get the IP address like this 并获得这样的IP地址

protected String getIpAddress() {
    String ipAddress = request.getHeader("X-FORWARDED-FOR");
    if (ipAddress == null) {
        ipAddress = request.getRemoteAddr();
    }
    return ipAddress;
}

You may have a chance to get IP address of the original sender with the X-FORWARDED-FOR header if not obscured by a proxy. 如果代理没有掩盖,您可能有机会使用X-FORWARDED-FOR标头获得原始发件人的IP地址。 Otherwise the getRemoteAddr() should do it. 否则, getRemoteAddr()应该这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM