Skip to content

Commit 9a3fbf7

Browse files
committed
Support underscores in names (jboss-fuse#66)
Signed-off-by: Aurélien Pupier <[email protected]>
1 parent 5f3fe92 commit 9a3fbf7

File tree

6 files changed

+795
-5
lines changed

6 files changed

+795
-5
lines changed

impl/src/main/java/org/jboss/fuse/wsdl2rest/impl/codegen/CamelContextGenerator.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ public void process(List<EndpointInfo> clazzDefs, JavaModel javaModel) throws IO
9898

9999
private void addTypeMapping(EndpointInfo epinfo, JavaModel javaModel) {
100100
IllegalArgumentAssertion.assertTrue(javaModel.getInterfaces().size() == 1, "Multiple interfaces not supported");
101-
JavaInterface javaIntrf = javaModel.getInterfaces().get(epinfo.getClassName());
101+
// the keys used have removed the underscores
102+
JavaInterface javaIntrf = javaModel.getInterfaces().get(epinfo.getClassName().replaceAll("_", ""));
102103
for (MethodInfo method : epinfo.getMethods()) {
103104
if ("document".equals(method.getStyle())) {
104105
JavaMethod javaMethod = getJavaMethod(javaIntrf, method.getMethodName());
@@ -125,8 +126,7 @@ private String normalize(String typeName) {
125126
private JavaMethod getJavaMethod(JavaInterface intrf, String methodName) {
126127
JavaMethod result = null;
127128
for (JavaMethod method : intrf.getMethods()) {
128-
// sometimes the method name and the operation name differ by case, so default to case insensitive
129-
if (method.getName().equalsIgnoreCase(methodName))
129+
if (method.getOperationName().equalsIgnoreCase(methodName))
130130
result = method;
131131
}
132132
IllegalStateAssertion.assertNotNull(result, "Cannot obtain java method for: " + methodName);

impl/src/main/java/org/jboss/fuse/wsdl2rest/impl/service/MethodInfoImpl.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,11 @@ public String getPath() {
121121
}
122122

123123
private boolean hasPathParam(ParamInfo pinfo) {
124-
String httpMethod = getHttpMethod();
125-
boolean pathParam = httpMethod.equals("GET") || httpMethod.equals("DELETE");
124+
boolean pathParam =
125+
//null httpMethod is supposed to default to GET based on ResourceMapperImpl.mapResources(String)
126+
httpMethod == null
127+
|| "GET".equals(httpMethod)
128+
|| "DELETE".equals(httpMethod);
126129
return pathParam && pinfo.getParamType() != null;
127130
}
128131

pom.xml

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<version.javaparser>2.5.1</version.javaparser>
2020
<version.javax.ws.rs.api>2.1</version.javax.ws.rs.api>
2121
<version.junit>4.12</version.junit>
22+
<version.assertj>3.11.1</version.assertj>
2223
<version.wsdl4j>1.6.3</version.wsdl4j>
2324

2425
<!-- Plugin versions -->
@@ -69,6 +70,11 @@
6970
<artifactId>junit</artifactId>
7071
<version>${version.junit}</version>
7172
</dependency>
73+
<dependency>
74+
<groupId>org.assertj</groupId>
75+
<artifactId>assertj-core</artifactId>
76+
<version>${version.assertj}</version>
77+
</dependency>
7278
<dependency>
7379
<groupId>org.apache.camel</groupId>
7480
<artifactId>camel-parent</artifactId>

tests/spring/pom.xml

+4
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@
6363
<artifactId>slf4j-log4j12</artifactId>
6464
<scope>test</scope>
6565
</dependency>
66+
<dependency>
67+
<groupId>org.assertj</groupId>
68+
<artifactId>assertj-core</artifactId>
69+
</dependency>
6670
</dependencies>
6771

6872
<build>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.jboss.fuse.wsdl2rest.test;
18+
19+
import static org.assertj.core.api.Assertions.assertThat;
20+
21+
import java.io.File;
22+
import java.nio.file.Path;
23+
import java.nio.file.Paths;
24+
import java.util.List;
25+
26+
import org.jboss.fuse.wsdl2rest.EndpointInfo;
27+
import org.jboss.fuse.wsdl2rest.MethodInfo;
28+
import org.jboss.fuse.wsdl2rest.impl.Wsdl2Rest;
29+
import org.junit.Test;
30+
31+
public class WithUnderscoreTest {
32+
33+
@Test
34+
public void testJavaClient() throws Exception {
35+
File wsdlFile = new File("src/test/resources/A_NAME_WITH_UNDERSCORE_SRV.1.wsdl");
36+
assertThat(wsdlFile).exists();
37+
38+
Path outpath = Paths.get("target/wsdl2rest/A_NAME_WITH_UNDERSCORE_SRV.1");
39+
Wsdl2Rest wsdl2Rest = new Wsdl2Rest(wsdlFile.toURI().toURL(), outpath);
40+
41+
List<EndpointInfo> clazzDefs = wsdl2Rest.process();
42+
assertThat(clazzDefs).hasSize(1);
43+
EndpointInfo clazzDef = clazzDefs.get(0);
44+
assertThat(clazzDef.getPackageName()).isEqualTo("1.com/Enterprise/HCM/services/A_NAME_WITH_UNDERSCORE_SRV.oracle.xmlns");
45+
assertThat(clazzDef.getClassName()).isEqualTo("A_NAME_WITH_UNDERSCORE_SRV_PortType");
46+
MethodInfo method = clazzDef.getMethod("A_SECOND_NAME_WITH_UNDERSCORE_EMAIL_OPR_SRV");
47+
assertThat(method.getPath()).isEqualTo("/{arg0}");
48+
49+
File cctxFile = outpath.resolve(Paths.get("camel", "wsdl2rest-camel-context.xml")).toFile();
50+
assertThat(cctxFile).exists();
51+
}
52+
}

0 commit comments

Comments
 (0)