Loading...
Loading...
Use when Java XML-RPC API work requires contract decisions for fault signaling and interoperability, including defining XmlRpcException-based failures, replacing void returns with explicit operation results, reviewing handlers for return-code anti-patterns, and migrating DTOs from Serializable to JAXB.
npx skill4agent add gabia/agent-skills java-xmlrpc-guideline| Scenario | Pattern |
|---|---|
| API interface method | |
| Void-like operation | Return |
| Success result | Return value (DTO, primitive, etc.) |
| Failure result | Throw |
| DTO serialization | Use JAXB annotations ( |
throws XmlRpcExceptionpublic interface SomeApi {
SomeDto someAction(SomeParameterDto request) throws XmlRpcException;
}<?xml version="1.0" encoding="UTF-8"?>
<methodResponse xmlns:ex="http://ws.apache.org/xmlrpc/namespaces/extensions">
<fault>
<value>
<struct>
<member>
<name>faultCode</name>
<value><i4>1</i4></value>
</member>
<member>
<name>faultString</name>
<value>failed to execute api</value>
</member>
</struct>
</value>
</fault>
</methodResponse>enabledForExceptionvoidintpublic interface ServiceControlApi {
int start(String name) throws XmlRpcException;
}0XmlRpcExceptionvoidvoidvoidint| Outcome | How to Signal |
|---|---|
| Operation succeeded | Return value |
| Query found nothing | Return empty/false (this is success) |
| Operation failed | Throw |
public interface PublicIpApi {
boolean isExists(InetAddress address) throws XmlRpcException;
}truefalseXmlRpcExceptionpublic interface ServiceControlApi {
int start(String name) throws XmlRpcException;
}00XmlRpcException-1// GOOD: JAXB DTO
@XmlRootElement
public class ComplexJaxbDto implements Element {
@XmlAttribute
private String type;
@XmlAttribute
private String number;
private List<NestedDto> nestedDtos;
private ComplexJaxbDto() { }
public static final class NestedDto {
private String value;
private NestedDto() { }
}
}// BAD: Serializable DTO (Java-only)
public class SerializableDto implements Serializable {
private String value;
public SerializableDto(String value) {
this.value = value;
}
}<ex:serializable>rO0ABXNyACx0aWwueG1scnBj...</ex:serializable><ex:jaxb>
<complexJaxbDto number="number" type="type">
<nestedDtos>
<value>test</value>
</nestedDtos>
<nestedDtos>
<value>test2</value>
</nestedDtos>
</complexJaxbDto>
</ex:jaxb>| Mistake | Problem | Fix |
|---|---|---|
Missing | Client can't receive errors | Add to all API methods |
Using | XML-RPC library doesn't support it | Use |
Returning | Meaningless, creates confusion | Always return |
| Error codes in DTO fields | Request appears successful | Throw |
Using | Java-only, unreadable | Use JAXB annotations |
Using | Java-only | Avoid, use standard faults |
start()0start()XmlRpcExceptionthrows XmlRpcExceptionvoidint00