/** * Authenticates a user with crowd. If authentication failed, raises a <code>RemoteException</code> * @param username * @param password * @throws RemoteException */ public void authenticate(String username, String password) throws RemoteException { username = JID.unescapeNode(username); LOG.debug("authenticate '" + String.valueOf(username) + "'"); final AuthenticatePost authenticatePost = new AuthenticatePost(); authenticatePost.value = password; final StringWriter writer = new StringWriter(); JAXB.marshal(authenticatePost, writer); final HttpUriRequest postRequest = RequestBuilder.post(crowdServer.resolve("authentication?username=" + urlEncode(username))) .setConfig(requestConfig) .setEntity(new StringEntity(writer.toString(), StandardCharsets.UTF_8)) .setHeader(HEADER_CONTENT_TYPE_APPLICATION_XML) .build(); try(final CloseableHttpResponse response = client.execute(postRequest, clientContext)) { if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { handleHTTPError(response); } } catch (IOException ioe) { handleError(ioe); } LOG.info("authenticated user:" + username); }
@Override public void write(OutputStream dest) throws IOException { JAXB.marshal(jaxbObject, dest); } });
public static void marshal(Object object, File file) { if (file == null) { throw new IllegalStateException("No file is given"); } marshal(object, new StreamResult(file)); }
public static void marshal(Object object, Writer writer) { if (writer == null) { throw new IllegalStateException("No writer is given"); } marshal(object, new StreamResult(writer)); }
public String toXmlString() { try (StringWriter writer = new StringWriter()) { JAXB.marshal(this, writer); return writer.toString(); } catch (IOException e) { return null; } }
public String serialize(Resource resource) { OutputStream outputStream = new ByteArrayOutputStream(); JAXB.marshal(resource, outputStream); return outputStream.toString(); }
public static void marshal(Object object, OutputStream os) { if (os == null) { throw new IllegalStateException("No output stream is given"); } marshal(object, new StreamResult(os)); }
public static void marshal(Object object, File file) { if (file == null) { throw new IllegalStateException("No file is given"); } marshal(object, new StreamResult(file)); }
public static void marshal(Object object, OutputStream os) { if (os == null) { throw new IllegalStateException("No output stream is given"); } marshal(object, new StreamResult(os)); }
/** * Serializes a JAXB object and prints to stdout * * @param obj * @return serialized text */ public static String JAXB_ToString(Object obj) { StringWriter sw = new StringWriter(); JAXB.marshal(obj, sw); return (sw.toString()); }
/** * Serializes a JAXB object and prints to stdout * * @param obj */ public static void JAXB_ToStdOut(Object obj) { StringWriter sw = new StringWriter(); JAXB.marshal(obj, sw); System.out.println(sw.toString()); }
private void setPostEntity(HttpPost req, Object obj) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); JAXB.marshal(obj, bos); req.setEntity(new ByteArrayEntity(bos.toByteArray())); }
private static synchronized void LogRequest(Object request) { if (isLogRequestPayloads()) try { File f = new File(System.currentTimeMillis()+".xml"); FileOutputStream fos = new FileOutputStream(f); JAXB.marshal(request, fos); fos.close(); f = null; } catch (Exception ex) { logger.warn("Unable to log request payload", ex); } }
@Override public void serialize(@NonNull Object o, @NonNull Resource resource) throws Exception { try (OutputStream outputStream = resource.outputStream()) { JAXB.marshal(o, outputStream); } }
public static void marshal(Object object, URI uri) { if (uri == null) { throw new IllegalStateException("No uri is given"); } try { marshal(object, uri.toURL()); } catch (IOException e) { throw new DataBindingException(e); } }
Process newProcessor(ProgramTypeProxy programTypeProxy, Object context) { StringWriter writer = new StringWriter(); JAXB.marshal(context, writer); return this.processes.parseInstance(this.management.newProcess(programTypeProxy.getId(), writer.toString())); }
@Test(expected = FileReactiveAuditException.class) public void marshal_URL() throws MalformedURLException { TestTools.strict.commit(); JAXB.marshal(null, IOTestTools.getTempFile().toURI().toURL()); }
@Test(expected = FileReactiveAuditException.class) public void marshal_File() { TestTools.strict.commit(); JAXB.marshal(null, IOTestTools.getTempFile()); }
@Test(expected = FileReactiveAuditException.class) public void marshal_Writer() { TestTools.strict.commit(); JAXB.marshal(null, IOTestTools.getTempFileWriter()); }