Skip to content

Instantly share code, notes, and snippets.

@rschumm
Last active October 12, 2015 08:37
JAXB: Java aus xsd
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
</plugin>
import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.bind.JAXB;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.DecisionType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.RequestType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.ResponseType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.ResultType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.StatusType;
public class XacmlMarshallUtil {
public static Result extractResultFromXacmlResponseString(String xacmlResponseAsString) {
StringReader reader = new StringReader(xacmlResponseAsString);
ResponseType responseType = JAXB.unmarshal(reader, ResponseType.class);
ResultType resultType = responseType.getResult().get(0);
DecisionType decision = resultType.getDecision();
StatusType status = resultType.getStatus();
Result result = mapToOurResult(decision, status);
return result;
}
package com.axa.ch.authorization.client.pep.facade;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import org.junit.Test;
import org.xml.sax.SAXException;
import junit.framework.Assert;
public class XacmlMarshallUtilTest {
@Test
public void testExtractResultFromXacmlResponseString() {
Result result = XacmlMarshallUtil.extractResultFromXacmlResponseString(createResponse());
assertEquals(Result.Decision.Deny, result.getDecision());
}
private String createResponse() {
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?> "
+ "<Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\">"
+ "<Result><Decision>Deny</Decision></Result></Response>";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment