Skip to content

Commit

Permalink
Merge pull request #25 from Unknow0/fix-webservice
Browse files Browse the repository at this point in the history
fix some jaxws & jaxb error
  • Loading branch information
Unknow0 authored Nov 28, 2023
2 parents 4d44d9b + b012402 commit 0e408f4
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ private void process(HttpServletRequest req, HttpServletResponse resp, boolean c
resp.setStatus(code);
resp.setContentLengthLong(size);
resp.setContentType(mimeType);

if (!content)
return;
ServletOutputStream os = resp.getOutputStream();
try (InputStream is = getServletContext().getResourceAsStream(path)) {
try (InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(path)) {
Chunk c = Chunk.get();
byte[] b = c.b;
int l;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,13 @@ else if (ENVELOPE12.equals(q)) {
e.sig(sig.append('/'));
WSMethod m = getCall(sig.toString());
if (m != null) {
try (OutputStream out = res.getOutputStream()) {
XMLStreamWriter w = XML_OUT.createXMLStreamWriter(out);
writeEnvelope(w, ns, m.call(e));
w.close();
try {
e = m.call(e);
try (OutputStream out = res.getOutputStream()) {
XMLStreamWriter w = XML_OUT.createXMLStreamWriter(out);
writeEnvelope(w, ns, e);
w.close();
}
} catch (Exception ex) {
logger.error("Failed to call operation " + sig, ex);
fault(res, ns, ex.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public abstract class AbstractGeneratorMojo extends AbstractMojo {

protected void init() throws MojoFailureException {
classLoader = getClassLoader();
loader = ModelLoader.from(JvmModelLoader.GLOBAL, new JvmModelLoader(classLoader), new AstModelLoader(classes, packages));
loader = ModelLoader.from(JvmModelLoader.GLOBAL, new AstModelLoader(classes, packages), new JvmModelLoader(classLoader));

List<String> compileSourceRoots = project.getCompileSourceRoots();

Expand Down Expand Up @@ -167,9 +167,11 @@ private ClassLoader getClassLoader() {
}

protected void process(TypeConsumer c) throws MojoExecutionException, MojoFailureException {
SrcWalker w = new SrcWalker(c);
SrcWalker w = new SrcWalker();
for (String s : project.getCompileSourceRoots())
w.walk(s);
for (String q : classes.keySet())
c.accept(loader.get(q));

if (artifacts == null || artifacts.isEmpty())
return;
Expand Down Expand Up @@ -231,14 +233,12 @@ private void addResource(String resources) {
}

private class SrcWalker extends SimpleFileVisitor<Path> {
private final TypeConsumer c;
private final String[] part;
private Path local;
private int count;
private Exception ex;

public SrcWalker(TypeConsumer c) {
this.c = c;
public SrcWalker() {
this.part = packageName == null ? new String[0] : packageName.split("\\.");
}

Expand Down Expand Up @@ -281,12 +281,6 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
for (TypeDeclaration<?> v : cu.findAll(TypeDeclaration.class)) {
String qualifiedName = v.resolve().getQualifiedName();
classes.put(qualifiedName, v);
TypeModel t = loader.get(qualifiedName);
try {
c.accept(t);
} catch (MojoExecutionException | MojoFailureException e) {
ex = e;
}
}
if (count == file.getNameCount() && file.startsWith(local)) {
String string = file.getFileName().toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;

Expand Down Expand Up @@ -165,8 +164,8 @@ private BlockStmt buildElement(TypeCache types, XmlElement e, XmlType xml, Block
for (XmlElement x : list)
s = new IfStmt(new InstanceOfExpr(name, types.getClass(x.xmlType().type())),
buildElement(types, x, x.xmlType(), new BlockStmt(), new CastExpr(types.get(x.xmlType().type()), name)), s);
p.addStatement(new IfStmt(new InstanceOfExpr(name, types.getClass(JAXBElement.class)), new ExpressionStmt(
new MethodCallExpr(new NameExpr("m"), "write", Utils.list(new CastExpr(types.get(JAXBElement.class), name), new NameExpr("w"), new NullLiteralExpr()))), s));
p.addStatement(new IfStmt(new InstanceOfExpr(name, types.getClass(JAXBElement.class)), new ExpressionStmt(new MethodCallExpr(new NameExpr("m"), "write",
Utils.list(new CastExpr(types.getClass(JAXBElement.class, TypeCache.ANY), name), new NameExpr("w"), new NullLiteralExpr()))), s));
return p;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public XmlGroup group() {
return group;
}

public boolean isEmpty() {
return elements.isEmpty();
}

@Override
public Iterator<XmlElement> iterator() {
return elements.iterator();
Expand Down Expand Up @@ -69,5 +73,4 @@ public String toString() {
return "ERROR";
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ private XmlType createObject(ClassModel c) {
elements = new XmlElements(XmlGroup.ALL, elems);
} else {
Collections.sort(elems, (a, b) -> {
String an = a.name();
String bn = b.name();
String an = a.prop().name();
String bn = b.prop().name();
int ai = propOrder.indexOf(an);
int bi = propOrder.indexOf(bn);
if (bi >= 0 && ai >= 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public XmlElements getElements() {
return elements;
}

public boolean hasElements() {
return elements != null && !elements.isEmpty();
}

public XmlElement getValue() {
return value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,28 +138,28 @@ private void appendSchema(XMLStreamWriter out, String ns) throws XMLStreamExcept
out.writeAttribute("elementFormDefault", "qualified");

for (Operation o : service.operations) {
if (o.wrapped) {
if (!ns.equals(o.name.getNamespaceURI()))
continue;
if (o.wrapped && ns.equals(o.name.getNamespaceURI())) {
out.writeStartElement(XS, ELEMENT);
out.writeAttribute("name", o.name.getLocalPart());
out.writeStartElement(XS, "complexType");
out.writeStartElement(XS, "all");
for (Parameter p : o.params) {
out.writeStartElement(XS, ELEMENT);
out.writeAttribute("name", p.name.getLocalPart());
out.writeAttribute("type", name(p.xml.name()));
out.writeAttribute("ref", name(p.name));
out.writeEndElement();
}
out.writeEndElement();
out.writeEndElement();
out.writeEndElement();

out.writeStartElement(XS, ELEMENT);
out.writeAttribute("name", o.name.getLocalPart() + RESPONSE);
out.writeStartElement(XS, "complexType");
if (o.result != null) {
out.writeStartElement(XS, "all");
out.writeStartElement(XS, ELEMENT);
out.writeAttribute("name", o.result.name.getLocalPart());
out.writeAttribute("type", name(o.result.xml.name()));
out.writeAttribute("ref", name(o.result.name));
out.writeEndElement();
out.writeEndElement();
}
// TODO result
Expand All @@ -177,7 +177,7 @@ private void appendSchema(XMLStreamWriter out, String ns) throws XMLStreamExcept
out.writeEndElement();
}
if (o.result != null && ns.equals(o.result.name.getNamespaceURI())) {
out.writeStartElement(XS, "elementR");
out.writeStartElement(XS, ELEMENT);
out.writeAttribute("name", o.result.name.getLocalPart());
out.writeAttribute("type", name(o.result.xml.name()));
out.writeEndElement();
Expand Down Expand Up @@ -215,16 +215,18 @@ private void appendType(XMLStreamWriter out, XmlType t) throws XMLStreamExceptio
out.writeStartElement(XS, "complexType");
out.writeAttribute("name", o.name().getLocalPart());

if (o.getElements() == null && o.getValue() != null) {
if (!o.hasElements() && o.getValue() != null) {
out.writeStartElement(XS, "simpleContent");
out.writeStartElement(XS, "extension");
out.writeAttribute("base", name(o.getValue().qname()));
out.writeAttribute("base", name(o.getValue().xmlType().name()));
}

out.writeStartElement(XS, o.getElements().group().toString());
for (XmlElement e : o.getElements())
appendElement(out, e);
out.writeEndElement();
if (o.hasElements()) {
out.writeStartElement(XS, o.getElements().group().toString());
for (XmlElement e : o.getElements())
appendElement(out, e);
out.writeEndElement();
}

for (XmlElement e : o.getAttributes()) { // TODO list ?
out.writeStartElement(XS, "attribute");
Expand Down Expand Up @@ -294,7 +296,7 @@ private void appendMessage(XMLStreamWriter out, Operation o) throws XMLStreamExc
out.writeAttribute("name", o.name.getLocalPart() + RESPONSE);
out.writeStartElement(WS, "part");
out.writeAttribute("name", "result");
out.writeAttribute(ELEMENT, name(o.wrapped ? o.name : o.result.name));
out.writeAttribute(ELEMENT, o.wrapped ? name(o.name.getNamespaceURI(), o.name.getLocalPart() + RESPONSE) : name(o.result.name));
out.writeEndElement();
out.writeEndElement();
}
Expand Down Expand Up @@ -325,7 +327,7 @@ private void appendPortType(XMLStreamWriter out) throws XMLStreamException {

private void appendBinding(XMLStreamWriter out) throws XMLStreamException {
out.writeStartElement(WS, "binding");
out.writeAttribute("name", service.name + "SoapBinding");
out.writeAttribute("name", service.name + "HttpBinding");
out.writeAttribute("type", name(service.ns, service.portType));

out.writeStartElement(WP, "binding");
Expand Down Expand Up @@ -366,7 +368,7 @@ private void appendService(XMLStreamWriter out) throws XMLStreamException {

out.writeStartElement(WS, "port");
out.writeAttribute("name", service.portName);
out.writeAttribute("binding", name(service.ns, service.name + "Binding"));
out.writeAttribute("binding", name(service.ns, service.name + "HttpBinding"));

out.writeStartElement(WP, "address");
out.writeAttribute("location", address + service.urls[0]);
Expand Down

0 comments on commit 0e408f4

Please sign in to comment.