Skip to content

Commit

Permalink
Fix caps issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Zhang committed Sep 9, 2021
1 parent 05cfd21 commit 12eb752
Show file tree
Hide file tree
Showing 2,566 changed files with 671,636 additions and 0 deletions.
47 changes: 47 additions & 0 deletions bizcore/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

=======
# skynet-common-app-framework
Common App Framework, a replacement of modern app

## 支持返回一个blob类型, 一个返回图片的例子

```
public BlobObject helloImage2(int width, int height, String note) throws IOException {
BlobObject blob = new BlobObject();
int internalWidth = outOfThen(width,10,1400,600);
int internalHeight = outOfThen(height,10,1400,400);
BufferedImage off_Image =
new BufferedImage(internalWidth, internalHeight,
BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = off_Image.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
Font f = new Font("Monospaced", Font.BOLD, 14);
g2.setFont(f);
String text=String.format("%s(%dX%d)", note,internalWidth,internalHeight);
g2.drawString(text,1,15);
//WritableRaster raster = bufferedImage .getRaster();
//DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
Shape shape = new Rectangle2D.Double(1, 1,
internalWidth-2,
internalHeight-2);
g2.draw(shape);
shape = new Line2D.Double(0, 0, internalWidth, internalHeight);
g2.draw(shape);
shape = new Line2D.Double(internalWidth, 0, 0, internalHeight);
g2.draw(shape);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ImageIO.write(off_Image, "png", bos);
blob.setData(bos.toByteArray());
blob.setMimeType(BlobObject.TYPE_PNG);
//BlobObject.TYPE_XLSX
return blob;
}
```
27 changes: 27 additions & 0 deletions bizcore/String_Object$Map.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<%@page isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@page contentType="text/html; charset=UTF-8"%>
<style>
.message{
font-size:20px;
}
.name {
background-color: lightblue;
}
.value {
word-break: break-all;
}
</style>

<div class="message">
Map:<ul>
<table>

<c:forEach var="entry" items="${result}" varStatus="status">
<tr>
<td class="name"><c:out value="${entry.key}"/></td><td class="value"><c:out value="${entry.value}"/></td>
</tr>
</c:forEach>
</table>
</ul>
</div>
3 changes: 3 additions & 0 deletions bizcore/WEB-INF/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
classes/
*.sql

50 changes: 50 additions & 0 deletions bizcore/WEB-INF/caf_core_src/com/skynet/bootstrap/AppEntrance.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.skynet.bootstrap;

import com.terapico.uccaf.UCInvocationServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.elasticsearch.rest.RestClientAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ImportResource;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

import static org.springframework.core.Ordered.HIGHEST_PRECEDENCE;


@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, RestClientAutoConfiguration.class, KafkaAutoConfiguration.class})
@ImportResource(locations = {"classpath:/META-INF/spring.xml", "classpath:/META-INF/online-system.xml"})
@ServletComponentScan(basePackageClasses = {UCInvocationServlet.class})
public class AppEntrance {
public static void main(String[] args) {
SpringApplication.run(AppEntrance.class, args);
}

@Bean
public FilterRegistrationBean requestWrapperFilterRegistration() {
FilterRegistrationBean registration = new FilterRegistrationBean();
registration.setFilter(new ContentCachingRequestWrapperFilter());
registration.addUrlPatterns("/*");
registration.setName("requestWrapperRequest");
registration.setOrder(HIGHEST_PRECEDENCE);
return registration;
}

public class ContentCachingRequestWrapperFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
MultiReadHttpServletRequest requestWrapper = new MultiReadHttpServletRequest(request);
filterChain.doFilter(requestWrapper, response);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
package com.skynet.bootstrap;
import com.google.common.collect.Iterables;
import com.google.common.collect.ObjectArrays;

import org.apache.commons.io.IOUtils;
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.entity.ContentType;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ReadListener;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

/**
* Purpose of this class is to make getParameter() return post data AND also be able to get entire
* body-string. In native implementation any of those two works, but not both together.
*/
public class MultiReadHttpServletRequest extends HttpServletRequestWrapper {
public static final String UTF8 = "UTF-8";
public static final Charset UTF8_CHARSET = Charset.forName(UTF8);
private ByteArrayOutputStream cachedBytes;
private Map<String, String[]> parameterMap;

public MultiReadHttpServletRequest(HttpServletRequest request) {
super(request);
}

public static void toMap(Iterable<NameValuePair> inputParams, Map<String, String[]> toMap) {
for (NameValuePair e : inputParams) {
String key = e.getName();
String value = e.getValue();
if (toMap.containsKey(key)) {
String[] newValue = ObjectArrays.concat(toMap.get(key), value);
toMap.remove(key);
toMap.put(key, newValue);
} else {
toMap.put(key, new String[]{value});
}
}
}

@Override
public ServletInputStream getInputStream() throws IOException {
if (cachedBytes == null) cacheInputStream();
return new CachedServletInputStream();
}

@Override
public BufferedReader getReader() throws IOException {
return new BufferedReader(new InputStreamReader(getInputStream()));
}

private void cacheInputStream() throws IOException {
/* Cache the inputStream in order to read it multiple times. For
* convenience, I use apache.commons IOUtils
*/
cachedBytes = new ByteArrayOutputStream();
IOUtils.copy(super.getInputStream(), cachedBytes);
}

@Override
public String getParameter(String key) {
Map<String, String[]> parameterMap = getParameterMap();
String[] values = parameterMap.get(key);
return values != null && values.length > 0 ? values[0] : null;
}

@Override
public String[] getParameterValues(String key) {
Map<String, String[]> parameterMap = getParameterMap();
return parameterMap.get(key);
}

@Override
public Map<String, String[]> getParameterMap() {
if (parameterMap == null) {
// Map<String, String[]> result = new LinkedHashMap<String, String[]>();
// decode(getQueryString(), result);
// decode(getPostBodyAsString(), result);
// parameterMap = Collections.unmodifiableMap(result);
parameterMap = getRequest().getParameterMap();
}
return parameterMap;
}

private void decode(String queryString, Map<String, String[]> result) {
if (queryString != null) toMap(decodeParams(queryString), result);
}

private Iterable<NameValuePair> decodeParams(String body) {
Iterable<NameValuePair> params = URLEncodedUtils.parse(body, UTF8_CHARSET);
try {
String cts = getContentType();
if (cts != null) {
ContentType ct = ContentType.parse(cts);
if (ct.getMimeType().equals(ContentType.APPLICATION_FORM_URLENCODED.getMimeType())) {
List<NameValuePair> postParams = URLEncodedUtils.parse(IOUtils.toString(getReader()), UTF8_CHARSET);
params = Iterables.concat(params, postParams);
}else if (ct.getMimeType().equals(ContentType.MULTIPART_FORM_DATA.getMimeType())) {

}
}
} catch (IOException e) {
throw new IllegalStateException(e);
}
return params;
}

public String getPostBodyAsString() {
try {
if (cachedBytes == null) cacheInputStream();
return cachedBytes.toString(UTF8);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

/* An inputStream which reads the cached request body */
public class CachedServletInputStream extends ServletInputStream {
private ByteArrayInputStream input;

public CachedServletInputStream() {
/* create a new input stream from the cached request body */
input = new ByteArrayInputStream(cachedBytes.toByteArray());
}

@Override
public int read() throws IOException {
return input.read();
}

@Override
public boolean isFinished() {
return input.available() <= 0;
}

@Override
public boolean isReady() {
// TODO Auto-generated method stub
return true;
}

@Override
public void setReadListener(ReadListener arg0) {

}
public int available() throws IOException {
return input.available();
}

}


}
Loading

0 comments on commit 12eb752

Please sign in to comment.