Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle new resource file key values. #2242

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1018,14 +1018,15 @@ public Object getEntry(String key) {
* @return its value
*/
public Entry getEntryDefinition(String key) {
String transformedKey = Utils.transformFileKey(key);
Object o = localRegistry.get(key);
if (o == null || o instanceof Entry) {
if (o == null) {
// this is not a local definition
synchronized (this) {
o = localRegistry.get(key);
if (o == null) {
Entry entry = new Entry(key);
Entry entry = new Entry(transformedKey);
entry.setType(Entry.REMOTE_ENTRY);
addEntry(key, entry);
return entry;
Expand Down
33 changes: 33 additions & 0 deletions modules/core/src/main/java/org/apache/synapse/config/Utils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.synapse.config;

public class Utils {

public static final String RESOURCES_IDENTIFIER = "resources:";
public static final String CONVERTED_RESOURCES_IDENTIFIER = "gov:mi-resources/";

public static String transformFileKey(String fileKey) {
chathuranga-jayanath-99 marked this conversation as resolved.
Show resolved Hide resolved

if (fileKey.startsWith(RESOURCES_IDENTIFIER)) {
return CONVERTED_RESOURCES_IDENTIFIER + fileKey.substring(RESOURCES_IDENTIFIER.length());
}
return fileKey;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

import junit.framework.TestCase;
import org.apache.synapse.endpoints.HTTPEndpoint;
import org.apache.synapse.registry.url.SimpleURLRegistry;
import org.apache.synapse.registry.url.SimpleURLRegistryTest;

public class SynapseConfigurationTest extends TestCase {

Expand Down Expand Up @@ -120,4 +122,12 @@ public void run() {
throw new RuntimeException(e);
}
}

public void testGetEntryDefinition() throws Exception {

String key = "resources:xslt/sample.xslt";
SynapseConfiguration config = new SynapseConfiguration();
Entry entry = config.getEntryDefinition(key);
assertEquals("Key of entry should be transformed.", "gov:mi-resources/xslt/sample.xslt", entry.getKey());
}
}
Loading