解码WebTarget URI

时间:2014-12-30 07:58:58

标签: java jsp uri encode

我在属性文件中有一个属性

appointments.deleteAppointmentwithReasonApi=api/appointment/{id}?reason={reason}
URL=http://xyz/etc/

在另一个档案中

public static final String  DELETE_APPOINTMENT_REASON = PropertiesUtil.getPropertyValueFromKey(REST_WEBSERVICE_URLS_PROP_FILE,
            "appointments.deleteAppointmentwithReasonApi"); // To get API name
public static final String URL = ServicesUtil.getURL(); // to get endpoint URL

在我的java API调用中,我给出了类似的东西

WebTarget target = client.target(CommonConstants.URL)
                    .path(CommonConstants.DELETE_APPOINTMENT_REASON)
                    .resolveTemplate("id", appointmentID).resolveTemplate("reason", reason);
            System.out.println(target);

我的回复是这样打印的......

JerseyWebTarget { http://xyz/etc/api/appointment/abc-123-ced-456%3Freason=Test }

没有达到正确的Web服务......我希望它像这样

JerseyWebTarget { http://xyz/etc/api/appointment/abc-123-ced-456?reason=Test }

我知道我需要对URL进行编码。我无法以某种方式做到这一点。有什么建议吗?

1 个答案:

答案 0 :(得分:-1)

你试过吗

encode(String s, String enc)