public Object readFrom(Class type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap httpHeaders, InputStream entityStream) throws IOException, WebApplicationException { return StringUtils.toString( entityStream ); }
public Object readFrom(Class type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap httpHeaders, InputStream entityStream) throws IOException, WebApplicationException { return StringUtils.toString( entityStream ); }
@Test public void testFileCreation() throws IOException { FileSystem fs = new MemoryFileSystem(); Folder mres = fs.getFolder( "src/main/java/org/domain" ); File f1 = mres.getFile( "MyClass.java" ); f1.create( new ByteArrayInputStream( "ABC".getBytes() ) ); mres.create(); f1 = mres.getFile( "MyClass.java" ); assertTrue( f1.exists()); f1.create( new ByteArrayInputStream( "ABC".getBytes() ) ); f1 = mres.getFile( "MyClass.java" ); assertTrue( f1.exists() ); assertEquals( "ABC", StringUtils.toString( f1.getContents() ) ); f1.create( new ByteArrayInputStream( "ABC".getBytes() ) ); f1.setContents( new ByteArrayInputStream( "DEF".getBytes() ) ); assertEquals( "DEF", StringUtils.toString( f1.getContents() ) ); }
public void process(Exchange exchange) throws Exception { Object object = exchange.getIn().getBody(); if ( object instanceof Response ) { Response res = (Response) object; if ( res.getStatus() == Status.OK.getStatusCode() ) { exchange.getOut().setBody( StringUtils.toString( (InputStream) ((Response) object).getEntity() ) ); } } } }
public static String toString(InputStream is) throws IOException { return toString( new BufferedReader(new InputStreamReader(is, "UTF-8") ) ); }
public void process(Exchange exchange) throws Exception { Object object = exchange.getIn().getBody(); if ( object instanceof Response ) { Response res = (Response) object; if ( res.getStatus() == Status.OK.getStatusCode() ) { exchange.getOut().setBody( StringUtils.toString( (InputStream) ((Response) object).getEntity() ) ); } } } }
@Test public void testFileRemoval() throws IOException { FileSystem fs = new MemoryFileSystem(); Folder mres = fs.getFolder( "src/main/java/org/domain" ); mres.create(); File f1 = mres.getFile( "MyClass.java" ); f1.create( new ByteArrayInputStream( "ABC".getBytes() ) ); assertTrue( f1.exists() ); assertEquals( "ABC", StringUtils.toString( f1.getContents() ) ); fs.remove( f1 ); f1 = mres.getFile( "MyClass.java" ); assertFalse( f1.exists() ); try { f1.getContents(); fail( "Should throw IOException" ); } catch( IOException e ) { } }
public static void buildResourcesList(Class cls, String kBaseQName, List<String> list) { String fileStr = null; InputStream is = null; try { is = cls.getResourceAsStream( "/" + kBaseQName + ".files.dat" ); fileStr = org.drools.core.util.StringUtils.toString( is ); } catch ( IOException e ) { throw new RuntimeException( "Unable to fine files for KnowledgeBase " + kBaseQName ); } finally { if ( is != null ) { try { is.close(); } catch (IOException e) { throw new RuntimeException( "Unable to fine files for KnowledgeBase " + kBaseQName ); } } } if (!StringUtils.isEmpty(fileStr)) { for( String entry : fileStr.split( "," ) ) { if (!StringUtils.isEmpty(entry)) { list.add( entry.trim() ); } } } }
public void process(Exchange exchange) throws Exception { byte[] body2 = (byte[]) exchange.getOut().getBody(); ByteArrayInputStream bais = new ByteArrayInputStream( body2 ); SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); SOAPBody soapBody = soapMessage.getSOAPPart().getEnvelope().getBody(); QName payloadName = new QName( "http://soap.jax.drools.org/", "executeResponse", "ns1" ); QName responseName = new QName( "http://soap.jax.drools.org/", "return", "ns1" ); SOAPBodyElement payload = soapBody.addBodyElement( payloadName ); SOAPElement response = payload.addChildElement( responseName ); response.addTextNode( StringUtils.toString( bais ) ); ByteArrayOutputStream baos = new ByteArrayOutputStream(); soapMessage.writeTo( baos ); exchange.getOut().setBody( new String( baos.toByteArray() ) ); }
public void process(Exchange exchange) throws Exception { byte[] body2 = (byte[]) exchange.getOut().getBody(); ByteArrayInputStream bais = new ByteArrayInputStream( body2 ); SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); SOAPBody soapBody = soapMessage.getSOAPPart().getEnvelope().getBody(); QName payloadName = new QName( "http://soap.jax.drools.org/", "executeResponse", "ns1" ); QName responseName = new QName( "http://soap.jax.drools.org/", "return", "ns1" ); SOAPBodyElement payload = soapBody.addBodyElement( payloadName ); SOAPElement response = payload.addChildElement( responseName ); response.addTextNode( StringUtils.toString( bais ) ); ByteArrayOutputStream baos = new ByteArrayOutputStream(); soapMessage.writeTo( baos ); exchange.getOut().setBody( new String( baos.toByteArray() ) ); }
public void process(Exchange exchange) throws Exception { InputStream is = (InputStream) exchange.getIn().getBody(); //Bad Hack - Need to remote it and fix it in Camel (if it's a camel problem) //I need to copy the results here because I loose them at the end of the method String results = StringUtils.toString( is ); if ( is != null ) { SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody(); QName payloadName = new QName( "http://soap.jax.drools.org/", "executeResponse", "ns1" ); QName responseName = new QName( "http://soap.jax.drools.org/", "return", "ns1" ); SOAPBodyElement payload = body.addBodyElement( payloadName ); SOAPElement response = payload.addChildElement( responseName ); //Bad Hack - Need to remote it and fix it in Camel (if it's a camel problem) // response.addTextNode( StringUtils.toString( is ) ); response.addTextNode( results ); exchange.getOut().setBody( soapMessage ); } }
public void process(Exchange exchange) throws Exception { InputStream is = (InputStream) exchange.getIn().getBody(); //Bad Hack - Need to remote it and fix it in Camel (if it's a camel problem) //I need to copy the results here because I loose them at the end of the method String results = StringUtils.toString( is ); if ( is != null ) { SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody(); QName payloadName = new QName( "http://soap.jax.drools.org/", "executeResponse", "ns1" ); QName responseName = new QName( "http://soap.jax.drools.org/", "return", "ns1" ); SOAPBodyElement payload = body.addBodyElement( payloadName ); SOAPElement response = payload.addChildElement( responseName ); //Bad Hack - Need to remote it and fix it in Camel (if it's a camel problem) // response.addTextNode( StringUtils.toString( is ) ); response.addTextNode( results ); exchange.getOut().setBody( soapMessage ); } }