Skip to content

Commit 489370c

Browse files
committed
fix #168--allow javascript resource extensions and set content-type accordingly
1 parent 288f773 commit 489370c

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

src/main/java/com/marklogic/client/impl/ResourceExtensionsImpl.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import com.marklogic.client.DatabaseClientFactory.HandleFactoryRegistry;
2525
import com.marklogic.client.admin.ExtensionMetadata;
26+
import com.marklogic.client.admin.ExtensionMetadata.ScriptLanguage;
2627
import com.marklogic.client.admin.ResourceExtensionsManager;
2728
import com.marklogic.client.io.Format;
2829
import com.marklogic.client.io.marker.ContentHandle;
@@ -134,7 +135,7 @@ public <T extends TextReadHandle> T readServices(String resourceName, T sourceHa
134135

135136
sourceBase.receiveContent(
136137
services.getValue(requestLogger, "config/resources", resourceName, true,
137-
"application/xquery", sourceBase.receiveAs())
138+
sourceBase.getMimetype(), sourceBase.receiveAs())
138139
);
139140

140141
return sourceHandle;
@@ -192,9 +193,17 @@ public void writeServices(
192193
}
193194
}
194195
}
196+
String contentType = null;
197+
if ( metadata.getScriptLanguage() == null ) {
198+
throw new IllegalArgumentException("scriptLanguage cannot be null");
199+
} else if ( metadata.getScriptLanguage() == ScriptLanguage.JAVASCRIPT ) {
200+
contentType = "application/vnd.marklogic-javascript";
201+
} else if ( metadata.getScriptLanguage() == ScriptLanguage.XQUERY ) {
202+
contentType = "application/xquery";
203+
}
195204

196205
services.putValue(requestLogger, "config/resources", resourceName, extraParams,
197-
"application/xquery", sourceBase);
206+
contentType, sourceBase);
198207
}
199208

200209
@Override
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2012-2014 MarkLogic Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.marklogic.client.test.example.cookbook;
17+
18+
import static org.junit.Assert.assertTrue;
19+
20+
import java.io.IOException;
21+
22+
import org.junit.Test;
23+
24+
import com.marklogic.client.example.cookbook.JavascriptResourceExtension;
25+
26+
public class JavascriptExtensionTest {
27+
@Test
28+
public void testMain() {
29+
//System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.wire", "debug");
30+
boolean succeeded = false;
31+
try {
32+
JavascriptResourceExtension.main(new String[0]);
33+
succeeded = true;
34+
} catch (IOException e) {
35+
e.printStackTrace();
36+
}
37+
assertTrue("JavascriptResourceExtension example failed", succeeded);
38+
}
39+
}

0 commit comments

Comments
 (0)