XML to JAVA with @XmlType instead of @XmlRootElement

Posted on by Kim

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;

...

private AssessResponse loadOpaResponseFromXmlFile(String file) throws Exception {
    JAXBContext jaxbContext = JAXBContext.newInstance(AssessResponse.class);
    InputStream is = getClass().getResourceAsStream(file);
    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    return unmarshaller.unmarshal(new StreamSource(is), AssessResponse.class).getValue();
}

----------------------

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "AssessResponse", propOrder = {
    "versionInfo",
    "events",
    "globalInstance"})
public class AssessResponse
    implements Serializable
{

...

----------------------
<assess-response xmlns="http://oracle.com/determinations/server/12.2.1/rulebase/assess/types">
    <global-instance>
        <entity id="month" inferred="false">
            <instance id="xxx">

...

Tunnel localhost to the internet

Posted on by Kim


Use ngrok

How to use ngrok:

Download and install ngrok. If you have npm installed, you can use: npm install -g ngrok Otherwise you can download it from the ngrok website

From the command line, run ngrok http $PORT replacing $PORT with the port you want.

Parse JSON with Java

Posted on by Kim

Using cxf to parse JSON

ChangeService changeService = JAXRSClientFactory.create(propertiesInterface.getServerUrl(),
        ChangeService.class, Collections.singletonList(new JacksonJaxbJsonProvider()),
        propertiesInterface.getUserName(), propertiesInterface.getPassword(), null);
Where ChangeService is
@Path("/change_request")
@Produces(MediaType.APPLICATION_JSON)
public interface ChangeService {

    @GET    public Changes getChangesByAssignedTo(
            @QueryParam("sysparm_query") String userSysId);
And maven dependency

    org.apache.cxf
    cxf-rt-rs-client
    ${cxf.version}
    provided


    org.codehaus.jackson
    jackson-jaxrs
    ${jackson.version}
    provided


    org.codehaus.jackson
    jackson-xc
    ${jackson.version}
    test