Examples of EntityTemplate


Examples of org.apache.http.entity.EntityTemplate

                String serviceName = uri.substring(uri.lastIndexOf("/") + 1, uri.length() - 6);
                HashMap services = configurationContext.getAxisConfiguration().getServices();
                final AxisService service = (AxisService) services.get(serviceName);
                if (service != null) {
                    final String ip = HttpUtils.getIpAddress();
                    EntityTemplate entity = new EntityTemplate(new ContentProducer() {

                        public void writeTo(final OutputStream outstream) throws IOException {
                            service.printWSDL2(outstream, ip, servicePath);
                        }

                    });
                    entity.setContentType("text/xml");
                    entity.setChunked(chunked);
                    response.setEntity(entity);
                    return;
                }
            }
            if (uri.endsWith("?wsdl")) {
                String serviceName = uri.substring(uri.lastIndexOf("/") + 1, uri.length() - 5);
                HashMap services = configurationContext.getAxisConfiguration().getServices();
                final AxisService service = (AxisService) services.get(serviceName);
                if (service != null) {
                    final String ip = HttpUtils.getIpAddress();
                    EntityTemplate entity = new EntityTemplate(new ContentProducer() {

                        public void writeTo(final OutputStream outstream) throws IOException {
                            service.printWSDL(outstream, ip, servicePath);
                        }

                    });
                    entity.setContentType("text/xml");
                    entity.setChunked(chunked);
                    response.setEntity(entity);
                    return;
                }
            }
            if (uri.endsWith("?xsd")) {
                String serviceName = uri.substring(uri.lastIndexOf("/") + 1, uri.length() - 4);
                HashMap services = configurationContext.getAxisConfiguration().getServices();
                final AxisService service = (AxisService) services.get(serviceName);
                if (service != null) {
                    EntityTemplate entity = new EntityTemplate(new ContentProducer() {

                        public void writeTo(final OutputStream outstream) throws IOException {
                            service.printSchema(outstream);
                        }

                    });
                    entity.setContentType("text/xml");
                    entity.setChunked(chunked);
                    response.setEntity(entity);
                    return;
                }
            }
            //cater for named xsds - check for the xsd name
            if (uri.indexOf("?xsd=") > 0) {
                String serviceName = uri.substring(uri.lastIndexOf("/") + 1, uri.lastIndexOf("?xsd="));
                String schemaName = uri.substring(uri.lastIndexOf("=") + 1);

                HashMap services = configurationContext.getAxisConfiguration().getServices();
                AxisService service = (AxisService) services.get(serviceName);
                if (service != null) {
                    //run the population logic just to be sure
                    service.populateSchemaMappings();
                    //write out the correct schema
                    Map schemaTable = service.getSchemaMappingTable();
                    final XmlSchema schema = (XmlSchema) schemaTable.get(schemaName);
                    //schema found - write it to the stream
                    if (schema != null) {
                        EntityTemplate entity = new EntityTemplate(new ContentProducer() {

                            public void writeTo(final OutputStream outstream) throws IOException {
                                schema.write(outstream);
                            }

                        });
                        entity.setContentType("text/xml");
                        entity.setChunked(chunked);
                        response.setEntity(entity);
                        return;
                    } else {
                        // no schema available by that name  - send 404
                        response.setStatusLine(new StatusLine(ver, 404, "Schema Not Found!"));
                        return;
                    }
                }
            }

            OutputBuffer outbuffer = new OutputBuffer();
            msgContext.setProperty(MessageContext.TRANSPORT_OUT, outbuffer);
            msgContext.setProperty(Constants.OUT_TRANSPORT_INFO, outbuffer);

            // deal with GET request
            boolean processed = HTTPTransportUtils.processHTTPGetRequest(
                    msgContext,
                    outbuffer.getOutputStream(),
                    soapAction,
                    uri,
                    configurationContext,
                    HTTPTransportReceiver.getGetRequestParameters(uri));

            if (processed) {
                outbuffer.setChunked(chunked);
                response.setEntity(outbuffer);
            } else {
                response.setStatusLine(new StatusLine(ver, 200, "OK"));
                String s = HTTPTransportReceiver.getServicesHTML(configurationContext);
                StringEntity entity = new StringEntity(s);
                entity.setContentType("text/html");
                entity.setChunked(chunked);
                response.setEntity(entity);
            }

        } else if (method.equals(HTTPConstants.HEADER_POST)) {
            // deal with POST request
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.