{
//
// get the current EPR/Address, and find the part where the
// context path starts...
//
EndpointReference epr = resource.getEndpointReference();
String address = epr.getAddress().toString();
int slash = address.lastIndexOf('/');
StringBuffer buffer = new StringBuffer();
buffer.append(address.substring(0, slash));
//
// substitute the resource type's context path for the one
// that was on there originally
//
String contextPath = resource.getContextPath();
if (contextPath.charAt(0) != '/')
buffer.append('/');
buffer.append(contextPath);
//
// re-set EPR address
//
URI addressWithProperEndpoint = URI.create(buffer.toString());
epr.setAddress(addressWithProperEndpoint);
}