Java Code Examples for org.apache.jena.atlas.web.HttpException#getStatusCode()

The following examples show how to use org.apache.jena.atlas.web.HttpException#getStatusCode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeltaLinkHTTP.java    From rdf-delta with Apache License 2.0 5 votes vote down vote up
private RDFPatch fetchCommon(Id dsRef, String param, String paramStr) {
    checkLink();

    String url = remoteReceive;
    url = createURL(url, DeltaConst.paramDatasource, dsRef.asParam());
    url = appendURL(url, paramStr);
    final String s = url;
    try {
        RDFPatch patch =  retry(()->{
            // [NET] Network point
            InputStream in = HttpOp.execHttpGet(s) ;
            if ( in == null )
                return null ;
            RDFPatchReaderText pr = new RDFPatchReaderText(in) ;
            RDFChangesCollector collector = new RDFChangesCollector();
            pr.apply(collector);
            return collector.getRDFPatch();
        }, ()->true, ()->"Retry fetch patch.", ()->"Failed to fetch patch.");
        return patch;
    }
    catch ( HttpException ex) {
        if ( ex.getStatusCode() == HttpSC.NOT_FOUND_404 ) {
            return null ; //throw new DeltaNotFoundException(ex.getMessage());
        }
        throw ex;
    }
}
 
Example 2
Source File: DeltaConnection.java    From rdf-delta with Apache License 2.0 5 votes vote down vote up
public void sync() {
    try {
        checkDeltaConnection();
        PatchLogInfo logInfo = getPatchLogInfo();
        sync(logInfo);
    } catch (HttpException ex) {
        if ( ex.getStatusCode() == -1 )
            throw new HttpException(HttpSC.SERVICE_UNAVAILABLE_503, HttpSC.getMessage(HttpSC.SERVICE_UNAVAILABLE_503), ex.getMessage());
        throw ex;
    }
}
 
Example 3
Source File: LibBuildDC.java    From rdf-delta with Apache License 2.0 5 votes vote down vote up
/** Build a Delta-backed datasets at a zone location. */
public static DatasetGraph setupDataset(String dsName, Location zoneLocation, LocalStorageType storage, DatasetGraph externalDataset, List<String> destURLs) {
    // Link to log server.
    DeltaLink deltaLink;
    if ( destURLs.size() == 1 )
        deltaLink = DeltaLinkHTTP.connect(destURLs.get(0));
    else {
        List<DeltaLink> links = new ArrayList<>(destURLs.size());
        for ( String destURL  : destURLs )
            links.add(DeltaLinkHTTP.connect(destURL));
        deltaLink = new DeltaLinkSwitchable(links);
    }

    Zone zone = Zone.connect(zoneLocation);
    DeltaClient deltaClient = DeltaClient.create(zone, deltaLink);
    SyncPolicy syncPolicy = SyncPolicy.TXN_RW;
    try { deltaLink.ping(); }
    catch (HttpException ex) {
        // rc < 0 : failed to connect - ignore?
        if ( ex.getStatusCode() > 0 )
            throw ex;
    }

    DatasetGraph dsg = ManagedDatasetBuilder.create()
        .deltaLink(deltaLink)
        .logName(dsName)
        .zone(zone)
        .syncPolicy(syncPolicy)
        .storageType(storage)
        .externalDataset(externalDataset)
        .build();
    return dsg;
 }