You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在WSO2中获取发送方服务端口号?已获IP但system.port.no返回空值

How to Retrieve the Sender's Port Number

Hey there! Let's tackle this port number issue you're facing. It looks like you're working with a WSO2-based environment (given the get-property syntax you're using), and the system.port.no property isn't working because it's not designed to fetch the sender (client) port—it typically refers to the server's own listening port, and returns empty if it's not explicitly configured in your system settings.

Here are a few reliable methods to get the sender's port:

Method 1: Use the Built-in Transport Property

For HTTP/HTTPS requests, the easiest way is to use the axis2.REMOTE_PORT property, which is automatically populated by the Axis2 transport layer with the port number of the client that sent the request. Here's how to configure it:

<property expression="get-property('axis2.REMOTE_PORT')" name="SenderPort" scope="default" type="STRING"/>

Method 2: Parse the Port from the Host Header

If axis2.REMOTE_PORT doesn't work for your specific scenario, you can extract the port from the request's Host header. The Host header usually follows the format [IP/Domain]:[Port]; if no port is specified, it defaults to 80 for HTTP or 443 for HTTPS. Use this configuration:

<!-- First get the Host header value -->
<property expression="get-property('TRANSPORT_HEADERS', 'Host')" name="HostHeader" scope="default" type="STRING"/>
<!-- Extract the port part after the colon -->
<property expression="fn:substring-after($ctx:HostHeader, ':')" name="SenderPort" scope="default" type="STRING"/>
<!-- Handle default port cases -->
<property expression="if (empty($ctx:SenderPort)) then (get-property('TRANSPORT_URL') starts-with 'https:' ? '443' : '80') else $ctx:SenderPort" name="SenderPort" scope="default" type="STRING"/>

Method 3: Inspect All Available Properties (For Special Protocols)

If you're using a non-HTTP protocol like JMS, the sender port property will be different. To find the right one, log all available properties and look for port-related fields:

<log level="full">
    <property name="AllAvailableProperties" expression="get-property('*')"/>
</log>

Check the logs after running this, and you'll spot the property that corresponds to the sender's port.

Keep in mind that property names might vary slightly across different WSO2 product versions (like ESB vs. APIM), so cross-referencing with your product's official docs can help confirm the exact property to use.

内容的提问来源于stack exchange,提问作者C. Bilgin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 08:27:32