KB Article #178281

Connect to URL filter fails with: java.lang.ClassCastException: java.lang.String cannot be cast to java.net.URI

Problem

A Connect to URL filter, whether pointed at ${http.request.uri} or not, fails with an exception like the following:


ERROR 12/1/16, 13:28:41.146 java exception:
java.lang.ClassCastException: java.lang.String cannot be cast to java.net.URI
at com.vordel.dwe.http.HTTPPlugin$6.generate(HTTPPlugin.java:220)
at com.vordel.circuit.Message.get(Message.java:105)
at com.vordel.circuit.Message.get(Message.java:91)
at com.vordel.circuit.net.ConnectToURLProcessor.invoke(ConnectToURLProcessor.java:57)
at com.vordel.circuit.InvocationEngine.invokeFilter(InvocationEngine.java:150)
at com.vordel.circuit.InvocationEngine.invokeCircuit(InvocationEngine.java:42)
at com.vordel.circuit.InvocationEngine.recordCircuitInvocation(InvocationEngine.java:276)
at com.vordel.circuit.InvocationEngine.processMessage(InvocationEngine.java:239)
at com.vordel.circuit.SyntheticCircuitChainProcessor.invoke(SyntheticCircuitChainProcessor.java:64)
at com.vordel.dwe.http.HTTPPlugin.processRequest(HTTPPlugin.java:364)
at com.vordel.dwe.http.HTTPPlugin.invokeDispose(HTTPPlugin.java:377)
at com.vordel.dwe.http.HTTPPlugin.invoke(HTTPPlugin.java:139)


Resolution

This may happen if http.request.uri has been written to via Set Attribute or similar filters. The http.request.uri is expected to be a java.net.URI object, not a java.lang.String. You can work around this by using another attribute name, or if the value comes from a script, by writing a java.net.URI object to http.request.uri. In general, you should use the Copy / Modify Attributes filter to make copies or backups of http.request.uri to avoid changing the Java type.


Note that it has been discovered that it is possible to get this error even if the Connect to URL filter is not using the value at all. This is because the value of http.request.url is initially generated from http.request.uri even when not actually used in the filter. If this attribute generation happens during the filter, and the URI value is a String, it will cause an exception there. Attribute generation may also happen during Trace filters, which can make errors that are trace-level dependent (i.e. that happen only at a level like ERROR but not at DEBUG) when the Trace filter generates the attributes prior to the value being overwritten by a String. This happens because the Trace filter itself will only run at certain trace levels, so at one trace level, the attribute is generated from a URI value correctly, while at the other trace level, the Trace filter never runs and the Connect to URL filter attempts to use a value with the wrong type.